Jul 19, 2021
0
Level 5
The PaymentMethod provided (sepa_debit) is not allowed for this SetupIntent. Please attach a PaymentMethod of one of the following types: card. Alternatively update the allowed payment_method_types for this SetupIntent to include "sepa_debit".
Hello, i am currently trying to built a subscription platform with Laravel Cashier V. 13.4. Credit Card Payments are working fine but when I try to add SEPA Direct Debit Payments it will throw the following error:
The PaymentMethod provided (sepa_debit) is not allowed for this SetupIntent. Please attach a PaymentMethod of one of the following types: card. Alternatively update the allowed payment_method_types for this SetupIntent to include "sepa_debit".
OrdersController.php
public function create()
{
$paymentIntent = auth()->user()->createSetupIntent();
return view('orders.create', compact( 'paymentIntent'));
}
public function checkout()
{
try {
$paymentMethod = $request->payment_method;
$user->createOrGetStripeCustomer();
$user->updateDefaultPaymentMethod($paymentMethod);
$user->charge($order->price * 100, $paymentMethod, [
'description' => $order->invoice_number
]);
$order->update(['paid_at' => now()]);
} catch (\Exception $e) {
return back()->with('error', $e->getMessage());
}
//Redirect to order success/payment page
return redirect(route('orders.show', $order))->with('success', 'Your order was successfully executed');
}
Create Order Page - create.blade.php
HTML Markup
<form action="{{ route('orders.store') }}" method="POST" id="payment-form">
@csrf
<input type="hidden" id="payment-method" name="payment_method">
//Stripe SEPA Direct Debit Form
<label for="iban-element">IBAN</label>
<div id="iban-element"><!-- A Stripe Element will be inserted here. --></div>
</form>
Javascript
<script src="https://js.stripe.com/v3/"></script><script>
var stripe = Stripe('{{ config('services.stripe.publishable_key') }}')
var elements = stripe.elements();
var form = document.getElementById("payment-form");
var options = {
supportedCountries: ['SEPA'],
placeholderCountry: 'DE',
};
// Create an instance of the IBAN Element
var iban = elements.create('iban', options);
// Add an instance of the IBAN Element into the `iban-element` <div>
iban.mount('#iban-element');
form.onsubmit = function(e) {
e.preventDefault();
stripe
.confirmSepaDebitSetup('{{ $paymentIntent->client_secret }}', {
payment_method: {
sepa_debit: iban,
billing_details: {
name: '{{ auth()->user()->full_name }}',
email: '{{ auth()->user()->email }}',
},
},
}) .then(function(result) {
if(result.error) {
//show error message
} else {
document.getElementById('payment-method').value = result.setupIntent.payment_method;
document.getElementById("payment-form").submit();
} });
};
</script>
Does anybody have an Idea how to add sepa direct debit to laravel cashier payment methods?
Please or to participate in this conversation.