I am integrating Stripe SEPA payment method in PHP WordPress. I cannot use plugin so that is why I have to integrate it.
I have created a product in stripe dashboard and get user IBAN to subscribe the product for recurring payment.
Here is my code:
$iban = $_POST['useriban'];
$username = $_POST['username'];
$email = $_POST['useremail'];
$paymentMethod = \Stripe\PaymentMethod::create([
'type' => 'sepa_debit',
'sepa_debit' => [
'iban' => $iban, // Replace with the actual IBAN
],
'billing_details' => [
'name' => $username,
'email' => $email,
],
]);
$customer = \Stripe\Customer::create([
'name' => $username,
'email' => $email,
'payment_method' => $paymentMethod->id,
]);
$customer_id = $customer->id;
$customer->invoice_settings->default_payment_method = $paymentMethod->id;
$customer->save();
$subscription = \Stripe\Subscription::create([
'customer' => $customer->id,
'items' => [
[
'price' => 'plan_ODaZeXLlnFADJZ', // Replace with the price ID of the product
],
],
'default_source' => $paymentMethod->id, // Replace with the actual SEPA payment method ID
'mandate' => [
'customer_acceptance' => [
'type' => 'online',
'online' => [
'ip_address' => $_SERVER['REMOTE_ADDR'], // Replace with the customer's IP address
],
],
],
]);
this code gives me an error:
Fatal error: Uncaught Error sending request to Stripe: (Status 400) (Request req_4Q3bwHjriVSt6Y) Received unknown parameter: mandate Stripe\Exception\InvalidRequestException: Received unknown parameter: mandate in
Kindly help me how to set recurring payment and how to set mandate with subscription.
You likely shouldn't be creating Payment Method objects directly. Recommend starting here for integrating SEPA Direct Debit subscriptions (includes details on how to collect mandate acknowledgement, etc).