Принять платеж в Laravel 6 с Stripe - PullRequest
0 голосов
/ 21 января 2020

Я пытаюсь интегрировать платежную систему в свой проект Laravel 6.

Но я понятия не имею, как получить ClientSecret со стороны моего сервера

У меня есть это в моем CheckOutController

    public function charge(Request $request)
{
    Stripe::setApiKey('sk_test_GEQCwhRyT9PcK1vju3YcsIEN00gXSsjo1P');

    $intent = PaymentIntent::create([
        'amount' => round(Cart::total()),
        'currency' => 'eur',
    ]);

    echo json_encode($intent);
}

И я должен получить информацию и работать с этим (из документации Stripe)

submitButton.addEventListener('click', function(ev) {
  stripe.confirmCardPayment(clientSecret, {
    payment_method: {
      card: card,
      billing_details: {
       name: 'Jenny Rosen'
      }
    }
  }).then(function(result) {
   if (result.error) {
     // Show error to your customer (e.g., insufficient funds)
      console.log(result.error.message);
    } else {
      // The payment has been processed!
      if (result.paymentIntent.status === 'succeeded') {
        // Show a success message to your customer
        // There's a risk of the customer closing the window before callback
        // execution. Set up a webhook or plugin to listen for the
        // payment_intent.succeeded event that handles any business critical
        // post-payment actions.
      }
   }
  });
});

Спасибо, что прочитали меня:)

1 Ответ

0 голосов
/ 21 января 2020

Секрет клиента, который вы ищете, возвращается Stripe как client_secret.

Таким образом, вы можете получить это значение с помощью:

Arr::get($intent, 'client_secret');

Вы можете посмотреть на пример ответа из документации здесь: https://stripe.com/docs/api/payment_intents/create

...