Я использую Stripe PHP SDK для обработки платежей в Европе, я только недавно получил сессионные сборы, работающие с использованием API PaymentIntent в регулировании с правилами SCA, теперь я хочу, чтобы пользователи могли подписываться на различные планы для ежемесячных платежей, читаяДокументы и поиск в Интернете примеров, использующих API PaymentIntent для повторяющихся примеров, мало чем помогли, поэтому мой вопрос: как мне его обработать?
Мой рабочий процесс выглядит следующим образом: 1) Соберите метод оплаты с помощьюэлементы и создать полосу клиента 2) Пользователь выбирает план 3) Подписаться пользователя на регулярные платежи
Это мой метод контроллера, как я могу завершить подписку, используя PaymentIntent:
public function addSubscription(Request $request)
{
$validatedData = $request->validate(StripeValidator::$addSubscription);
$customer = Auth::check() && Auth::user()->stripeId ? Customer::retrieve(Auth::user()->stripeId) : false;
if(!$customer)
{
return response()->json([
'message' => 'Registrate para disfrutar de nuestras mejores promociones.',
], 500);
}
$paymentMethod = PaymentMethod::retrieve($request->input('paymentMethodId'));
$plan = Plan::create([
"product" =>
[
"name" => "Product name"
],
"interval" => "month",
"interval_count" => "1",
"currency" => "eur",
"amount" => "3000",
]);
$subscription = Subscription::create([
"customer" => $customer->id,
"items" =>
[
["plan" => $plan->id ],
],
]);
return response()->json([
'subscription' => $subscription,
'message' => 'Te suscribiste a el plan con éxito.',
], 200);
}
И на всякий случайВот как я работаю с однократными сессионными платежами:
public function createCustomerAndPaymentMethod(Request $request)
{
$validatedData = $request->validate(StripeValidator::$createCustomerAndPaymentMethod);
$user = Auth::user();
if(!$user){
return response()->json([
'message' => 'Debes estar registrado para realizar una compra.',
], 400);
}
$customer = Customer::create([
'email' => $user['email'],
"description" => 'Customer for'.config('app.name')
]);
$user->stripeId = $customer->id;
$user->save();
$paymentMethod = PaymentMethod::retrieve($request->input('paymentMethodId'));
$paymentMethod->attach(['customer' => $customer->id]);
$paymentMethods = PaymentMethod::all([
'customer' => $customer->id,
'type' => 'card',
]);
return response()->json([
'message' => 'Añadiste una tarjeta como forma de pago.',
'customer' => $customer,
'paymentMethods' => $paymentMethods
]);
}
public function confirmPayment(Request $request)
{
$customer = Auth::check() && Auth::user()->stripeId ? Customer::retrieve(Auth::user()->stripeId) : false;
if(!$customer)
{
return response()->json([
'message' => 'Registrate para disfrutar de nustras mejores promociones.',
'customer' => null,
], 500);
}
//dd( $request->input('paymentMethodId'));
$paymentIntent = PaymentIntent::create([
'payment_method' => $request->input('paymentMethodId'),
'customer' => $customer->id,
'amount' => 2000,
'currency' => 'eur',
'confirmation_method' => 'manual',
'payment_method_types' => ['card'],
'confirm' => true,
'setup_future_usage' => 'on_session',
]);
$this->generatePaymentResponse($paymentIntent);
}
Любое предложение приветствуется, документации по этому поводу не так много ...