skip to Main Content

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

enter image description here

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


  1. Chosen as BEST ANSWER

    I found the solution with the help of @LauraT.

    $paymentIntent = PaymentIntent::create([
        'amount' => $amountTaxed, // Amount in cents (e.g., $10.00)
        'currency' => $this->settings->currency_code,
        'customer' => $this->user->stripe_id, // Replace with the customer ID in Stripe
        'payment_method' => $default_payment_method_id, // Replace with the payment method ID (Visa card) in Stripe
        'confirm' => true, // Set to true to confirm the payment immediately
    ]);
    
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search