Stripe Q37。PaymentIntentで支払いを行った後、成功画面を表示させるためにはどうすれば良いですか?

StripeQA

目次一覧

 状態:回答待  閲覧数:1,437  投稿日:2019-04-24  更新日:2019-04-28  
Q37 / A37抜粋

Q37-2 / 質問後に気が付いたこと

Q37 / A37抜粋

 閲覧数:308 投稿日:2019-04-24 更新日:2019-04-27 

Q37


PaymentIntentで支払いを行った後、成功画面を表示させるためにはどうすれば良いですか?
・2019/4/24
やりたいこと
・移行ではなく、新規でPaymentIntent作成。支払い実行
・自動で確認

試したこと
・https://dashboard.stripe.com/test/events/evt_1ESXe1JiXAQvfxv3YdG1pNTV

出来たこと
・webhookで"payment_intent.succeeded"イベントを受け取り
・支払い実行

問題点
・PaymentIntentで支払いを行った後、成功画面が表示されない
・webhookで"payment_intent.succeeded"イベントを受け取っても、そこへは画面遷移しない

質問1
・PaymentIntentで支払いを行った後、成功画面を表示させるにはどうすれば良いですか?
・Checkout newでは、下記のように'success_url'を指定できたけれども、Checkout を使用しない場合は'success_url'をどう指定すれば良い?
$checkoutSession = \Stripe\Checkout\Session::create([
 'customer_email' => 'customer@example.com',
 'success_url' => 'https://xxxx/thanks.php',


質問2
・成功確認は下記何れで行うのですか? 何れでも良い? あるいは、何れかが良い? そもそも下記判定は何が異なるのですか?
・webhookの"payment_intent.succeeded"イベントで判定
・stripe.jsの「await stripe.handleCardPayment」メソッドのレスポンスであるerrorで判定

試したコード(PHP)
▼index.php
<?php
\Stripe\Stripe::setApiKey("sk_test_xxxx");
$paymentintent = \Stripe\PaymentIntent::create([
 "amount" => 1099,
 "currency" => "jpy",
]);
?>
<input id="cardholder-name" type="text">
<div id="card-element"></div>
<button id="card-button" data-secret="<?php echo $paymentintent->client_secret; ?>">
 Submit Payment
</button>

<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('pk_test_xxxx');

const elements = stripe.elements();
const cardElement = elements.create('card');
cardElement.mount('#card-element');

const cardholderName = document.getElementById('cardholder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;

cardButton.addEventListener('click', async (ev) => {
 const {paymentIntent, error} = await stripe.handleCardPayment(
   clientSecret, cardElement, {
     payment_method_data: {
       billing_details: {name: cardholderName.value}
     }
   }
 );

 if (error) {
   // Display error.message in your UI.
   console.log(error)
 } else {
   // The payment has succeeded. Display a success message.
   console.log("成功")
 }
});
</script>


A37


PaymentIntentで作成された支払いの成功確認をするには?
・”payment_intent.succeeded"イベントのWebhookを利用することを推奨
・Client sideのレスポンスで判定することは非推奨。顧客が支払った後すぐに支払いページを閉じるまたは移動する可能性があるため
Verifying Payment Status

CheckoutではなくPaymentIntentsを利用する場合
・決済完了後のリダイレクトフローはあなたが開発する必要がある

PaymentIntentsにはリダイレクト機能が提供されていない
・PaymentIntentオブジェクトは、Checkout のsessionオブジェクトと異なり、リダイレクトに関するパラメータがない
The PaymentIntent object

Q37-2 / 質問後に気が付いたこと

 閲覧数:317 投稿日:2019-04-27 更新日:2019-04-28 

Q37-2


How do I redirect to the success screen after receiving the “payment_intent.succeeded” event via webhook?
・2019/4/27
・How can I display the success screen after making a payment with PaymentIntent?
・Checkout new allows you to specify 'success_url' as shown below, but how to specify 'success_url' if you do not use Checkout?
$checkoutSession = \Stripe\Checkout\Session::create([
'customer_email' => 'customer@example.com',
'success_url' => 'https://xxxx/thanks.php',


Code tried (PHP)
・ I can receive "payment_intent.succeeded" event by webhook
・ I do not redirect to the success screen

▼index.php
<?php
\Stripe\Stripe::setApiKey("sk_test_xxxx");
$paymentintent = \Stripe\PaymentIntent::create([
 "amount" => 1099,
 "currency" => "jpy",
]);
?>
<input id="cardholder-name" type="text">
<div id="card-element"></div>
<button id="card-button" data-secret="<?php echo $paymentintent->client_secret; ?>">
 Submit Payment
</button>

<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('pk_test_xxxx');

const elements = stripe.elements();
const cardElement = elements.create('card');
cardElement.mount('#card-element');

const cardholderName = document.getElementById('cardholder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;

cardButton.addEventListener('click', async (ev) => {
 const {paymentIntent, error} = await stripe.handleCardPayment(
   clientSecret, cardElement, {
     payment_method_data: {
       billing_details: {name: cardholderName.value}
     }
   }
 );

 if (error) {
   // Display error.message in your UI.
   console.log(error)
 } else {
   // The payment has succeeded. Display a success message.
   console.log("ok")
 }
});
</script>


How do I redirect to the success screen after receiving the "payment_intent.succeeded" event via webhook?

質問後に気が付いたこと


JavaScriptでリダイレクトさせるもエラー
・JavaScriptでwebhook.phpへリダイレクトさせるも「HTTP ERROR 400」発生
・そもそもwebhook.phpで「$_SERVER['HTTP_STRIPE_SIGNATURE']」を受け取るよう設定しているため、それ以外の方法によるアクセスは不可

\Stripe\Checkout\Session::create()メソッドの'success_url'パラメータ処理を行っているコード内容を参考にすればよいのでは?
・探してみるも良く分からない
・'success_url'に関する記述は下記のみ
▼stripe/vendor/stripe/stripe-php/lib/Checkout/Session.php
<?php

namespace Stripe\Checkout;

/**
* Class Session
*
* @property string $id
* @property string $object
* @property string $cancel_url
* @property string $client_reference_id
* @property string $customer
* @property string $customer_email
* @property mixed $display_items
* @property bool $livemode
* @property string $payment_intent
* @property string[] $payment_method_types
* @property string $subscription
* @property string $success_url
*
* @package Stripe
*/
class Session extends \Stripe\ApiResource
{

   const OBJECT_NAME = "checkout.session";

   use \Stripe\ApiOperations\Create;
   use \Stripe\ApiOperations\Retrieve;
}

▼stripe/stripe-php/lib/ApiOperations/Create.php
<?php

namespace Stripe\ApiOperations;

/**
* Trait for creatable resources. Adds a `create()` static method to the class.
*
* This trait should only be applied to classes that derive from StripeObject.
*/
trait Create
{
   /**
    * @param array|null $params
    * @param array|string|null $options
    *
    * @return \Stripe\ApiResource The created resource.
    */
   public static function create($params = null, $options = null)
   {
       self::_validateParams($params);
       $url = static::classUrl();

       list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
       $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
       $obj->setLastResponse($response);
       return $obj;
   }
}


Stripe Q39。I want to check the processing for the 'success_url' parameter of the 'Checkout \ Session :: create () method' in the Git-Hub code



Stripe Q36。What is the difference between “stripe.handleCardPayment (clientSecret)” and “stripe.retrievePaymentIntent (clientSecret)”?

Stripe Q38。Difference between “paymentIntent.status === 'succeeded'” and “payment_intent.succeeded event of Webhook”

コメント投稿(ログインが必要)



類似度ページランキング
順位 ページタイトル抜粋
1 Stripe Q37。PaymentIntentで支払いを行った後、成功画面を表示させるためにはどうすれば良いですか? 80
2 Stripe Q66.Webhookエンドポイントが、"connect"内容も含むかどうかを確認するためにはどうすれば良いですか? 42
3 Stripe Q23。イベントで「新しい支払元が追加されました」と表示されているのに、「支払元がありません」 41
4 Stripe Q11。テストAPIで、実際のカード番号を入力したらどうなりますか? 40
5 Stripe Q35。「Payment Intents API」で、3Dセキュアなどの認証手順を(顧客が)使用しないことは出来ますか? 40
6 Stripe Q27。ダッシュボードやAPIドキュメントの表示内容変更などを知らせるページはありますか? 40
7 Stripeで"No such token: src"と表示されたら、最初にAPIキーを確認する 39
8 Stripe Q50。 Connect 「Standardアカウント」で、自身に連結された子アカウントを、ダッシュボードから削除するには? 36
9 Stripe Q16。PaymentIntentの支払いで郵便番号入力を求められる。Radar rules の ZIP code を無効にしているのに 36
10 Stripe Q53.Checkout\Sessionの1回限りの支払いで、決済完了したユーザにだけページ表示させたい 36
11 Stripe Q15。PaymentIntent でエラー。カード番号に不備があります。 35
12 Stripe Q68.WebhookはPUT送信しているのですか? 35
13 Stripe Q31。ダッシュボードでの「支払い作成」の見方について 34
14 Stripe Q12。IBAN要素を使用すると、日本でも顧客の銀行口座の詳細を取得できますか? 34
15 Stripe Q13。決済成功時に、「請求に紐づけられたメールアドレス」に対して、メール送信したいのですが、 34
16 Stripe Q6。Stripeサーバより返された「一意のトークン」をどこで受け取るの? 33
17 Stripe Q44。Standard アカウント連結後の返り値で、保存すべき値について 33
18 Stripe Q58.Checkout\Session::create後、'checkout.session.completed'受信した段階で、PaymentIntentオブジェクトは作成されていますか? 32
19 Stripe Q76.ウェブサイトドメインのメールを受信できないのですが、他にドメイン所有権を確認する方法はありますか? 32
20 Stripe Q43。payouts スケジュールについて 32
2024/4/26 20:04 更新
週間人気ページランキング / 4-19 → 4-25
順位 ページタイトル抜粋 アクセス数
1 YouTube | 動画サービス(課金販売できるプラットフォーム) 7
2 EMVCo | クレジットカード仕様(仕様) 6
3 EMVレベル1 / EMVレベル2 / EMVCo とは? 5
4 クレジットカード決済 | 課金 4
5 pixivFANBOX | クリエイター支援プラットフォーム(課金販売できるプラットフォーム) 3
5 Squareは、デジタルコンテンツ(デジタル情報)の配信利用が認められないサービス | 「支払」機能を有する決済系サービス(決済サービス) 3
6 Stripeアカウントへログインする際、モバイル端末で受信したコード入力を求められる理由は? | その他エントリー(Stripe) 2
6 Off-session Payments with Payment Intents / Payment Intents を使用したオフセッション支払 2
6 Stripe Q32。Webhook のエンドポイントから適切な値を返さなかったときの停止措置について | QA(Stripe) 2
6 「支払」と「送金」の違い | 違い 2
6 Stripe Q16。PaymentIntentの支払いで郵便番号入力を求められる。Radar rules の ZIP code を無効にしているのに | QA(Stripe) 2
6 プリペイドカード | カード 2
7 振込 | 送金 1
7 IBAN | 海外送金(送金) 1
7 Stripe Q11。テストAPIで、実際のカード番号を入力したらどうなりますか? | QA(Stripe) 1
7 Stripe Q53.Checkout\Sessionの1回限りの支払いで、決済完了したユーザにだけページ表示させたい | QA(Stripe) 1
7 ツイキャスとは?/ 特徴 / キートスとは? 1
7 note | 課金販売できるプラットフォーム 1
7 Stripe webhook 配信の問題 / 実際に受け取った警告メールの受信例 1
7 Stripe webhook 配信の問題 | その他エントリー(Stripe) 1
2024/4/26 1:02 更新