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

「決済」及び「開発」関連用語集

カテゴリー: QA  閲覧数:317 配信日:2019-04-27 07:46


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


週間人気ページランキング / 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 更新
指定期間人気ページランキング / 2020-5-28 → 2024-4-25
順位 ページタイトル抜粋 アクセス数
1 Stripeアカウントへログインする際、モバイル端末で受信したコード入力を求められる理由は? | その他エントリー(Stripe) 2010
2 EMVCo | クレジットカード仕様(仕様) 1268
3 Stripe Q13。決済成功時に、「請求に紐づけられたメールアドレス」に対して、メール送信したいのですが、 | QA(Stripe) 943
4 Stripe Q16。PaymentIntentの支払いで郵便番号入力を求められる。Radar rules の ZIP code を無効にしているのに | QA(Stripe) 901
5 クレジットカード決済 | 課金 880
6 Twitch | ゲーム実況配信サービス(課金販売できるプラットフォーム) 876
7 決済用語 855
8 Stripe Q50。 Connect 「Standardアカウント」で、自身に連結された子アカウントを、ダッシュボードから削除するには? | QA(Stripe) 824
9 Omise | 「支払」機能を有する決済系サービス(決済サービス) 767
10 Stripe Q1。Stripeにおける個人事業主の定義 | QA(Stripe) 761
11 pixivFANBOX | クリエイター支援プラットフォーム(課金販売できるプラットフォーム) 741
12 Stripe Q31。ダッシュボードでの「支払い作成」の見方について | QA(Stripe) 738
13 EMVレベル1 / EMVレベル2 / EMVCo とは? 727
14 YouTube | 動画サービス(課金販売できるプラットフォーム) 670
15 プリペイドカード | カード 645
16 EPUB | ファイルフォーマット(電子書籍) 587
17 サブスクリプション | 課金 563
18 Stripeで"No such token: src"と表示されたら、最初にAPIキーを確認する | Stripe エラー(Stripe) 544
19 Stripe Q74.「お客様のビジネスの詳細」とは何ですか? | Stripe 542
20 ファンティア | クリエイター支援プラットフォーム(課金販売できるプラットフォーム) 482
2024/4/26 1:02 更新