I am using Strip PHP API and trying to create a charge:
$chargeData = [
"amount" => $amountTaxed,
"currency" => $this->settings->currency_code,
"source" => 'tok_visa', // Card token
//'customer' => $this->user->stripe_id,
"description" => __('general.add_funds') . ' (Auto-recharge) @' . $this->user->username,
'metadata' => [
'user' => $this->user->stripe_id,
'amount' => $amountTaxed,
'taxes' => $this->settings->tax_on_wallet ? $this->user->taxesPayable() : null,
'type' => 'deposit'
]
];
$charge = StripeCharge::create($chargeData);
Below is payment method card detail added in customer account
I know how to get card token via card number
$token = StripeToken::create([
'card' => [
'number' => '4242424242424242',
'exp_month' => 7,
'exp_year' => 2024,
'cvc' => '314',
],
]);
If I get token manually using the card number StripeToken::create
, stripe’s charge method StripeCharge::create
works fine. So my only problem is to get the source/token.
My intention is to get the token from existing payment method’s card.
If there is any other way to charge from customer’s existing payment methods’s card, please let me know.
Thank you!
2
Answers
I found the solution with the help of @LauraT.
You’re using an older integration path. Stripe’s Charges API still work but are not recommended. I recommend starting with their guide for building an integration that charges a customer and saves their payment details for later charges.