目次一覧
状態:-
閲覧数:977
投稿日:2019-02-22
更新日:2019-03-21
最初に結論 / 質問履歴9
最初に結論 / 質問履歴9
最初に結論
Checkout beta version
・webhookで'client_reference_id'を受け取るためには、予め 'clientReferenceId'を指定しておく必要がある
クライアント側
<!-- Load Stripe.js on your website. -->
<script src="https://js.stripe.com/v3"></script>
<!-- Create a button that your customers click to complete their purchase. -->
<button id="checkout-button" role="link">Pay</button>
<div id="error-message"></div>
<script>
var stripe = Stripe('pk_test_〇〇', {
betas: ['checkout_beta_4']
});
var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click', function () {
// When the customer clicks on the button, redirect
// them to Checkout.
stripe.redirectToCheckout({
items: [{sku: 'sku_EYUuveVPe61SrH', quantity: 1}],
// Note that it is not guaranteed your customers will be redirected to this
// URL *100%* of the time, it's possible that they could e.g. close the
// tab between form submission and the redirect.
successUrl: 'https://省略',
cancelUrl: 'https://省略',
clientReferenceId: 'order_123',
})
.then(function (result) {
if (result.error) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer.
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
});
});
</script>
PHPで受け取った結果
stdClass::__set_state(array(
'id' => 'evt_1E7vFPJiXAQvfxv3mC6pUpZE',
'object' => 'event',
'api_version' => '2019-02-19',
'created' => 1551146443,
'data' =>
stdClass::__set_state(array(
'object' =>
stdClass::__set_state(array(
'object' => 'checkout_beta',
'client_reference_id' => 'order_123',
'display_items' =>
array (
0 =>
stdClass::__set_state(array(
'currency' => 'jpy',
'amount' => 10000,
'type' => 'sku',
'quantity' => 1,
'sku' => 'sku_EYUuveVPe61SrH',
)),
),
'line_items' => NULL,
'livemode' => false,
'payment_intent' => 'pi_1E7vF1JiXAQvfxv3XC5ezNTm',
)),
)),
'livemode' => false,
'pending_webhooks' => 1,
'request' =>
stdClass::__set_state(array(
'id' => NULL,
'idempotency_key' => NULL,
)),
'type' => 'checkout_beta.session_succeeded',
))
質問履歴9
Checkout beta version で、webhookを受け取ると、client_reference_idがNULL
・2019/2/22
Checkout beta version で、webhookを受け取ると、client_reference_idがNULLになるのですが、redirectToCheckoutを指定した場合は、ここで「一意の文字列」を受け取れるわけではないのでしょうか?
・redirectToCheckoutの書き方がおかしいですか?
クライアント
<script>
var stripe = Stripe('pk_test_〇〇', {
betas: ['checkout_beta_4']
});
var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click', function () {
stripe.redirectToCheckout({
items: [{sku: 'sku_EYUuveVPe61SrH', quantity: 1}],
successUrl: '省略',
cancelUrl: '省略',
})
.then(function (result) {
if (result.error) {
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
});
});
</script>
PHPで受け取った結果
stdClass::__set_state(array(
'id' => 'evt_1E6I74JiXAQvfxv3iGbGoRcu',
'object' => 'event',
'api_version' => '2019-02-19',
'created' => 1550757682,
'data' =>
stdClass::__set_state(array(
'object' =>
stdClass::__set_state(array(
'object' => 'checkout_beta',
'client_reference_id' => NULL,
'display_items' =>
array (
0 =>
stdClass::__set_state(array(
'currency' => 'jpy',
'amount' => 10000,
'type' => 'sku',
'quantity' => 1,
'sku' => 'sku_EYUuveVPe61SrH',
)),
),
'line_items' => NULL,
'livemode' => false,
'payment_intent' => 'pi_1E6I6eJiXAQvfxv3IMxgerR9',
)),
)),
'livemode' => false,
'pending_webhooks' => 1,
'request' =>
stdClass::__set_state(array(
'id' => NULL,
'idempotency_key' => NULL,
)),
'type' => 'checkout_beta.session_succeeded',
))
・redirectToCheckoutの書き方がおかしいですか?
クライアント
<script>
var stripe = Stripe('pk_test_〇〇', {
betas: ['checkout_beta_4']
});
var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click', function () {
stripe.redirectToCheckout({
items: [{sku: 'sku_EYUuveVPe61SrH', quantity: 1}],
successUrl: '省略',
cancelUrl: '省略',
})
.then(function (result) {
if (result.error) {
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
});
});
</script>
PHPで受け取った結果
stdClass::__set_state(array(
'id' => 'evt_1E6I74JiXAQvfxv3iGbGoRcu',
'object' => 'event',
'api_version' => '2019-02-19',
'created' => 1550757682,
'data' =>
stdClass::__set_state(array(
'object' =>
stdClass::__set_state(array(
'object' => 'checkout_beta',
'client_reference_id' => NULL,
'display_items' =>
array (
0 =>
stdClass::__set_state(array(
'currency' => 'jpy',
'amount' => 10000,
'type' => 'sku',
'quantity' => 1,
'sku' => 'sku_EYUuveVPe61SrH',
)),
),
'line_items' => NULL,
'livemode' => false,
'payment_intent' => 'pi_1E6I6eJiXAQvfxv3IMxgerR9',
)),
)),
'livemode' => false,
'pending_webhooks' => 1,
'request' =>
stdClass::__set_state(array(
'id' => NULL,
'idempotency_key' => NULL,
)),
'type' => 'checkout_beta.session_succeeded',
))
Stripe Q8。Stripe Checkout public beta version について
Stripe Q10。Checkout の Simple で、「data-zip-code="true"」追加した場合について