Reputation: 1309
I am trying to implement the Stripe PHP API, but I am stuck since last week. At first I thought I did not mention the payment method correctly in the way of a correct notation. However this seems not to be the case.
I have created a wrapper class that loads all stripe API files and following handles all calls required for me.
Hence that's why the code layout.
When I execute my script I receive the following error :
Fatal error: Uncaught (Status 400) (Request req_AQbkjKFB4mo31Z) You cannot confirm this PaymentIntent because it's missing a payment method. You can either update the PaymentIntent with a payment method and then confirm it again, or confirm it again directly with a payment method. thrown in /var/www/vhosts/example.com/httpdocs/stripe/stripe/lib/Exception/ApiErrorException.php on line 38
I have contacted the Stripe helpdesk already however they keep referring me to their manual but that doesn't get me any further either.
The iDeal payment method has been enabled in their dashboard. So that's not the reason for failure. Where it COULD be is the manner I setup my payment. But for as far as I am concerned I do not have set the payment method correctly. But for as far as I can see that has been done accordingly their manual.
Also, I cannot find any confirmatory documentation about using the retrieve call. Should I do this? Or is this simply double and unneeded.
public function create_payment($amount, $order_id, $method = 'ideal', $return_url = NULL, $currency = 'eur'){
///######## CHECK IF CURRENCY IS ALLOWED
if(!$this->currency_supported($currency)) exit('<strong>error</strong>, stripe currency not supported : '.$currency);
///######## SETUP PAYMENT
$result = $this->obj->paymentIntents->create(
array(
'amount' => $amount,
'currency' => $currency,
'payment_method_types' => array($method)
)
);
///######## IF ERROR
if(!is_object($result) || !isset($result->id)) exit('<strong>error</strong>, something went wrong during stripe payment intend creation');
///######## SETUP PAYMENT ID
$payment_id = $result->id;
///######## RETRIEVE PAYMENT INTEND DETAILS
$result = $this->obj->paymentIntents->retrieve($payment_id, []);
///######## SET AN ORDER ID
$result = $this->obj->paymentIntents->update($payment_id, array(
'metadata' => array(
'order_id' => $order_id,
),
'payment_method_types' => array($method),
));
///######## SETUP PARAMETRES
$params = array('payment_method_types' => array($method));
///######## IF THE RETURN URL HAS BEEN SET
if($return_url) $params['return_url'] = $return_url;
///######## CONFIRM A PAYMENT INTEND
$result = $this->obj->paymentIntents->confirm($payment_id, $params);
exit(print_r($result));
}
I hope that one could point me at my error. Since I am absolutely stuck here.
Upvotes: 1
Views: 10829
Reputation: 7419
You are setting the payment_method_types
, which determines which types of payment methods are accepted for this payment intent. In order to confirm & collect payment, you need to provide a specific payment_method
. You can provide this directly yourself, but I would recommend using Stripe.js and Elements to collect the iDEAL payment details. After you've created your Payment Intent on the server, you would send the client_secret
back to your client and use that with the collected details:
HTML:
<div id="ideal-bank-element">
<!-- A Stripe Element will be inserted here. -->
</div>
JS:
var idealBank = elements.create('idealBank', options);
idealBank.mount('#ideal-bank-element');
...
stripe.confirmIdealPayment(
'{{PAYMENT_INTENT_CLIENT_SECRET}}',
{
payment_method: {
ideal: idealBank,
billing_details: {
name: accountholderName.value,
},
},
return_url: 'https://your-website.com/checkout/complete',
}
);
Using confirmIdealPayment
like this will automatically set the payment_method
on the Payment Intent and confirm it.
Upvotes: 0