How to implement stripe SCA in PHP? - php

As per the stripe documentation here we read all the information and know the ideas about the SCA. But I am not getting any related API documentation. So, I am confusing how to implement in our existing PHP code and what are the parameters we will add. Please find below my example of code:
\Stripe\Stripe::setApiKey(API_KEY_HERE);
$customer = \Stripe\Token::create(
array("card" => array(
"name" => $arg['name'],
"number" => $arg['number'],
"exp_month" => $arg['exp_month'],
"exp_year" => $arg['exp_year'],
"cvc" => $arg['cvc']
))
);
/* some other code here */
$charge = \Stripe\Charge::create(
array(
"amount" => $arg['amount'],
"currency" => "usd",
"description" => "Subscription Charge",
"customer" => $customer->id
)
);
/* some other db related code here */
I have shared the code. Could you please let us know what we need to change for SCA?

I just answered this question where OP did a great job on the question.
Perhaps her code can help you see how you need to implement this using JS in the
front-end and PHP in the backend.
Stripe - Payment Intents (3d secure issue)

Related

WePay API response error "payment method does not exist or does not belong to app"

i was having a problem with Wepay API. My codes are correct but it keeps on returning an error saying "payment method does not exist or does not belong to app". I already configured the permission to allow tokenized credit cards. But still. Any feedback is greatly appreciated. Thanks!
Here is my code
require_once('public/payment/wepay/wepay.php');
$user = API::get_client(['fldClientEmail' => $email])->first();
// change to useProduction for live environments
\Wepay::useStaging(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET);
$wepay = new \WePay($user->fldClientWepayTokenAccess);
// $wepay = new \WePay(WEPAY_ACCESS_TOKEN);
// dd($email);die;
// dd($user->fldClientWepayAccountID);die;
// charge the credit card
$response = $wepay->request('checkout/create', [
'account_id' => $user->fldClientWepayAccountID,
'amount' => number_format(Input::get('amount_tipped'),2),
'currency' => 'USD',
'short_description' => 'A short description',
'type' => 'goods',
'payment_method' => array(
'type' => 'credit_card',
'credit_card' => array(
'id' => Input::get('cc_id')
)
)
]);
// display the response
return $response;
Make sure that when you follow the tutorial from their docs, you replace all of the credentials from the examples. I was using their Javascript library for the tokenization of the credit card with the client_id they provided.
response = WePay.credit_card.create({
"client_id": YOUR.CLIENT.ID.HERE,
"user_name": valueById('name'),
"email": valueById('email'),
"cc_number": valueById('cc-number'),
"cvv": valueById('cc-cvv'),
"expiration_month": valueById('cc-month'),
"expiration_year": valueById('cc-year'),
"address": {
"postal_code": valueById('postal_code')
}
If you don't provide your own, is like you were creating those credit cards for another application that's not yours.
If this didn't do the trick, check this article, hopefully it does:
https://support.wepay.com/hc/en-us/articles/203609273-WePay-API-Error-Codes

PHP: Stripe connect API would not accept card details?

I know that asking this here could be throwing a stone in the dark because I found 2 other similar questions but none had any answers to it.
Any way, I hope someone has already found the solution for this and can shed a light on it.
Let me explain the scenario first as it might help with finding a solution:
I am creating stripe custom connect accounts like this:
$acct = \Stripe\Account::create(array(
"country" => "US",
"type" => "custom",
"email" => "email#mail.com"
));
Then I add Bank Accounts to them like so:
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "bank_account",
"country" => "US",
"currency" => "usd",
"account_holder_name" => 'Jane Austen',
"account_holder_type" => 'individual',
"routing_number" => "111000025",
"account_number" => "000123456789"
)
));
This all works fine so far....
Now, what I need to do is to be able to transfer Money/Payments from the connected custom accounts into their Bank accounts.
For that purpose, I will need to add a Credit Card to that connetced account so that card details can be used for making payments into the Bank Accounts.
So I went ahead and tried this:
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "card",
"exp_month" => 8,
"exp_year" => 2018,
"number" => "4012888888881881",
"currency" => "usd",
"cvc" => "123"
)
));
And that did NOT work and gave me this error:
Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.
So I changed my strategy and tried this:
$result = \Stripe\Token::create(
array(
"card" => array(
"name" => "Some Name",
"exp_month" => 8,
"exp_year" => 2018,
"number" => "4012888888881881",
"currency" => "usd",
"cvc" => "123"
)
));
$token = $result['id'];
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "card",
"source" => "".$token.""
)
));
However, this gave me the same error message!!!
This is very frustrating because if you look at their own API documentation, you will clearly see that they say:
source required
Either a token, like the ones returned by Stripe.js, or a dictionary containing a user's credit card details (with the options shown below). Stripe will automatically validate the card.
This can be seen here:
https://stripe.com/docs/api#create_card
Could someone please advice on this issue?
I cannot use stripe.js in my project so I will need to use the API.
Any help would be greatly appreciated.
Thanks in advance.
First Edit:
Here is a strange one.. I generated a Stripe card token from here:
https://codepen.io/fmartingr/pen/pGfhy
Note that the above codepen uses the stripe.js to generate the tokens....
and tried to use the token from there in my PHP code like so:
$account->external_accounts->create(
array(
'external_account' => array(
"object" => "card",
"source" => "tok_1AqPXeDQzcw33c71uncYBFdm"
)
));
but this gives me the exact same error:
Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.
Please use this it will add your external account
$result = \Stripe\Token::create(
array(
"card" => array(
"name" => "Some Name",
"exp_month" => 8,
"exp_year" => 2018,
"number" => "4012888888881881",
"currency" => "usd",
"cvc" => "123"
)
));
$token = $result['id'];
$account->external_accounts->create(
array(
'external_account' => "".$token.""
));

Use plan and quantity to add customer using stripe

I created a customer and charge that customer by using amount instead of plan. I checked their documentation but have no idea how to do that. Can anyone help me with my below code,
// create customer
$customer = Stripe_Customer::create(array(
"card" => $_POST['stripeToken'],
"description" => "This is testing mode",
"email" => "test#mail.com",
));
// Charge the Customer
Stripe_Charge::create(array(
"amount" => 3000,
"currency" => "usd",
"customer" => $customer->id)
);
Your code looks fine, and follows that outlined here:
https://stripe.com/docs/tutorials/charges
Is there a specific question or problem you're having?
Best,
Larry
PS I work on Support at Stripe.

Braintree API in PHP success and currency issue

My braintree integration is going well - there's just two minor issues.
Firstly what is the option name to pass through and specify a currency code e.g.:
$options = [
"amount" => "10.00"
"creditCard" => [
"number" => "",
"cvv" => "",
"expirationMonth" => "",
"expirationYear" => ""
],
"currencyCode" => "AUD" // This is what im after?
];
Secondly, when I run the code below I get this: "Undefined property: Braintree_Result_Successful::$_attributes" when running the check on success?
$result = Braintree_Transaction::sale($this->collect_data());
if($result->success) { // do something }
I work at Braintree. If you have more questions, please feel free to get in touch with our support team.
To use a different currency, you specify a different merchant account:
$result = Braintree_Transaction::sale(array(
'amount' => '100.00',
'merchantAccountId' => 'gbp_merchant_account',
'creditCard' => array(
'number' => '5105105105105100',
'expirationDate' => '05/12'
)
));
Contact Braintree to get the additional merchant accounts set up.
For your second question, I've not seen that error before. Your best bet is to contact Braintree support so they can help you with the problem.

Mercado Pago only CreditCard

I'm learning Mercado-Pago SDK...
I'd like to only be able to use credit card's, and for that I'm trying to use, "excluded_payment_types", so my array looks like this:
$preference_data = array(
"items" => array(
array(
"title" => "Puppy Dalmata",
"description" => "Nice description of the item",
"quantity" => 1,
"currency_id" => "MXN",
"picture_url" => "http://domain.com/dal2.jpg",
"unit_price" => 1500,
"payment_methods" => array (
"excluded_payment_types" => array (
"id" => "ticket",
"id" => "bank_transfer",
"id" => "atm",
"id" => "debit_card",
"id" => "account_money"
),
"installments" => 12
),
)
)
);
$preference = $mp->create_preference($preference_data);
With that I'm able to get the URL so that I can process the payment for that item, so, this is working "fine" the client is able to see how much is going to pay and a lot of option to make a payment:
Bank Deposit, Account Money, Debit card, Payment via "7Eleven, OXXO, STRIPES" and Credit card... the idea is to only show Credit Card and nothing else, the user can only select the type of card, Visa Credit or Master Credit ... and nothing else...
but as in the this url shows :https://api.mercadolibre.com/payment_types it doesn't work base on my ARRAY... so I wonder what am I doing wrong? ...
I thank you for any help you can provided
Thank you for taking the time to read my question.
toke me some time to get back to this... anyway, the problem with that array is that I have the key "payment_methods" inside key "items" which is wrong... it should be outside key items ... and that solved to problem of getting "payment_methods" to only accept credit card... btw, after I solved this issue I went back to read and learn more about "mercadopago" API for processing online payments and is quite easy to use I'm not saying is better than... PayPal, but, yes more easy to use...

Categories