#Syed Shahzaib

1 messages · Page 1 of 1 (latest)

weary notchBOT
cobalt needle
#

Hi! Let me help you with this.

#

You need to use the payment_method property to be able to charge the customer.

weary notchBOT
runic talon
#

first I am fetching payment methods like this

#

$paymentMethodIds = $stripe->paymentMethods->all([
'customer' => $customerId,
'type' => 'card',
]);

#

than making charge like this

#

$paymentIntent = PaymentIntent::create([
'amount' => $amount,
'currency' => $currency,
// 'automatic_payment_methods' => [ 'enabled' => true ],
'customer' => $customerId, //$customer->id, // must be associated here for future use
'payment_method' => $paymentMethodIds->data[1]->id,
'off_session' => true,
'confirm' => true
]);

#

How should I modify this? Point to be noted is that Card payments are working swiftly this is happening when customer has paid using google pay for the first time

bold flame
#

That code should work, but for the request that you sent, it doesn't look like that is the code that was run. Here is the creation request for that payment intent, it only passed the parameters

  currency: "aed",
  off_session: "true",
  confirm: "true",
  amount: "100000",
  customer: "cus_NwR1m18Fbn2nms",
}```
https://dashboard.stripe.com/test/logs/req_MSF0ZyHiXZDyJu
runic talon
#

for first time payment I am using payment element once first payment is made I am using customer id to make future payments so the code above is to simulate/test future payments considering payment method used for the first time was google pay

#

If we simplify this what I am missing here? As the code is working fine when the first payment was made using credit/debit card but only doing problem when using google pay as payment method

bold flame
#

Hard to say, for one reason or another your code did not send a payment method ID (pm_123) when creating that payment intent

#

Maybe it is possible that your payment method list call did not return any IDs?

#

You will want to debug and check why a payment method is not being saved when you use google pay

runic talon
#

ok I fixed the issue thanks for pointing out my mistake

#

'payment_method' => $paymentMethodIds->data[1]->id, problem was here with this index there is no index 1

#

but it didn't gave me default php error of undefined index this is strange but changing this 1 to 0 has solved my issue