カテゴリー:
QA
閲覧数:278 配信日:2019-08-22 16:01
Q62
Webhook::constructEventで、SignatureVerificationエラーになるのですが…
2019/8/22
前提
Stripe Conect の Standardアカウント directチャージ
Q
Charge Session の Webhookエンドポイントで、SignatureVerificationエラーを解決できません。
'No signatures found matching the expected signature for payload'
下記で何か気が付いたことがもしあれば教えてください。
コード抜粋
▼index.php
▼webhook.php
※$payload変数内容と、捕捉されたエラー内容につきましてはファイル添付しています
Webhook設定
https://dashboard.stripe.com/test/webhooks/we_1FA4EeEfFqi3KPm3KnVgQ73H
親アカウント手数料。取得できています
https://dashboard.stripe.com/test/events/evt_1FAA1OEfFqi3KPm3cljUKB3t
子アカウントの処理自体は問題なく出来ていると思われます
https://dashboard.stripe.com/test/logs/req_INyZaaJergSzAl
https://dashboard.stripe.com/test/logs/req_ljN6xIo6f6nWbv
https://dashboard.stripe.com/test/logs/req_7TAWxtFJOr5ngi
Stripe Conect の Standardアカウント directチャージ
Q
Charge Session の Webhookエンドポイントで、SignatureVerificationエラーを解決できません。
'No signatures found matching the expected signature for payload'
下記で何か気が付いたことがもしあれば教えてください。
コード抜粋
▼index.php
\Stripe\Stripe::setApiKey('xxxx');
\Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'name' => "Checkout Session Direct Charges デモ3",
'amount' => 200,
'currency' => 'jpy',
'quantity' => 10,
]],
'payment_intent_data' => [
'application_fee_amount' => 200,
],
'success_url' => 'xxxx',
'cancel_url' => 'xxxx',
], [
'stripe_account' => 'acct_xxxx',
]);
▼webhook.php
\Stripe\Stripe::setApiKey('xxxx');
$endpoint_secret = 'whsec_xxxx';
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
//ここでエラーが捕捉されます
※$payload変数内容と、捕捉されたエラー内容につきましてはファイル添付しています
Webhook設定
https://dashboard.stripe.com/test/webhooks/we_1FA4EeEfFqi3KPm3KnVgQ73H
親アカウント手数料。取得できています
https://dashboard.stripe.com/test/events/evt_1FAA1OEfFqi3KPm3cljUKB3t
子アカウントの処理自体は問題なく出来ていると思われます
https://dashboard.stripe.com/test/logs/req_INyZaaJergSzAl
https://dashboard.stripe.com/test/logs/req_ljN6xIo6f6nWbv
https://dashboard.stripe.com/test/logs/req_7TAWxtFJOr5ngi
▼debug.php
'----------payload----------'
'{
"id": "evt_1FAA1OLlsmkNgPt89Y9Qvi5b",
"object": "event",
"account": "acct_xxxx",
"api_version": "2019-08-14",
"created": 1566456226,
"data": {
"object": {
"id": "cs_test_G21JU02SWKqBwdMZxZOy6bcnIzU9eIb85HJgptXo1m107zQiqP8h86V4",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "http://xxxx/stripe/charge-cancel",
"client_reference_id": "2",
"customer": "cus_FfV1HWhLR6GhM8",
"customer_email": null,
"display_items": [
{
"amount": 200,
"currency": "jpy",
"custom": {
"description": null,
"images": null,
"name": "Checkout Session Direct Charges デモ3"
},
"quantity": 10,
"type": "custom"
}
],
"livemode": false,
"locale": null,
"payment_intent": "pi_1FAA17LlsmkNgPt8igElJDpi",
"payment_method_types": [
"card"
],
"submit_type": null,
"subscription": null,
"success_url": "http://xxxx/stripe/charge-success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}'
'----------SignatureVerification----------'
Stripe\Error\SignatureVerification::__set_state(array(
'message' => 'No signatures found matching the expected signature for payload',
'string' => '',
'code' => 0,
'file' => '/var/www/xxxx/lib/composer/vendor/stripe/stripe-php/lib/WebhookSignature.php',
'line' => 55,
'trace' =>
array (
0 =>
array (
'file' => '/var/www/xxxx/lib/composer/vendor/stripe/stripe-php/lib/Webhook.php',
'line' => 27,
'function' => 'verifyHeader',
'class' => 'Stripe\\WebhookSignature',
'type' => '::',
'args' =>
array (
0 => '{
"id": "evt_1FAA1OLlsmkNgPt89Y9Qvi5b",
"object": "event",
"account": "acct_xxxx",
"api_version": "2019-08-14",
"created": 1566456226,
"data": {
"object": {
"id": "cs_test_G21JU02SWKqBwdMZxZOy6bcnIzU9eIb85HJgptXo1m107zQiqP8h86V4",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "http://xxxx/stripe/charge-cancel",
"client_reference_id": "2",
"customer": "cus_FfV1HWhLR6GhM8",
"customer_email": null,
"display_items": [
{
"amount": 200,
"currency": "jpy",
"custom": {
"description": null,
"images": null,
"name": "Checkout Session Direct Charges デモ3"
},
"quantity": 10,
"type": "custom"
}
],
"livemode": false,
"locale": null,
"payment_intent": "pi_1FAA17LlsmkNgPt8igElJDpi",
"payment_method_types": [
"card"
],
"submit_type": null,
"subscription": null,
"success_url": "http://xxxx/stripe/charge-success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}',
1 => 't=1566456226,v1=664ea5151ae5598a24f10dbb76fd7450f2cabd7a0a24c9fa0787f53ca3182147',
2 => 'whsec_xxxx',
3 => 300,
),
),
1 =>
array (
'file' => '/var/www/html/1-p46/0webapp/controllers/StripeController.php',
'line' => 56,
'function' => 'constructEvent',
'class' => 'Stripe\\Webhook',
'type' => '::',
'args' =>
array (
0 => '{
"id": "evt_1FAA1OLlsmkNgPt89Y9Qvi5b",
"object": "event",
"account": "acct_子アカウント",
"api_version": "2019-08-14",
"created": 1566456226,
"data": {
"object": {
"id": "cs_test_G21JU02SWKqBwdMZxZOy6bcnIzU9eIb85HJgptXo1m107zQiqP8h86V4",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "http://xxxx/stripe/charge-cancel",
"client_reference_id": "2",
"customer": "cus_FfV1HWhLR6GhM8",
"customer_email": null,
"display_items": [
{
"amount": 200,
"currency": "jpy",
"custom": {
"description": null,
"images": null,
"name": "Checkout Session Direct Charges デモ3"
},
"quantity": 10,
"type": "custom"
}
],
"livemode": false,
"locale": null,
"payment_intent": "pi_1FAA17LlsmkNgPt8igElJDpi",
"payment_method_types": [
"card"
],
"submit_type": null,
"subscription": null,
"success_url": "http://xxxx/stripe/charge-success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}',
1 => 't=1566456226,v1=664ea5151ae5598a24f10dbb76fd7450f2cabd7a0a24c9fa0787f53ca3182147',
2 => 'whsec_xxxx',
),
),
2 =>
array (
'file' => '/var/www/html/1-p46/0webapp/core/Controller.php',
'line' => 63,
'function' => 'webhookAction',
'class' => 'StripeController',
'type' => '->',
'args' =>
array (
0 =>
array (
'controller' => 'stripe',
'action' => 'webhook',
0 => '/stripe/webhook',
),
),
),
3 =>
array (
'file' => '/var/www/html/1-p46/0webapp/core/Application.php',
'line' => 254,
'function' => 'run',
'class' => 'Controller',
'type' => '->',
'args' =>
array (
0 => 'webhook',
1 =>
array (
'controller' => 'stripe',
'action' => 'webhook',
0 => '/stripe/webhook',
),
),
),
4 =>
array (
'file' => '/var/www/html/1-p46/0webapp/core/Application.php',
'line' => 215,
'function' => 'runAction',
'class' => 'Application',
'type' => '->',
'args' =>
array (
0 => 'stripe',
1 => 'webhook',
2 =>
array (
'controller' => 'stripe',
'action' => 'webhook',
0 => '/stripe/webhook',
),
),
),
5 =>
array (
'file' => '/var/www/html/xxxx/xxxx/public_html/index.php',
'line' => 12,
'function' => 'run',
'class' => 'Application',
'type' => '->',
'args' =>
array (
),
),
),
'previous' => NULL,
'httpStatus' => NULL,
'httpBody' => '{
"id": "evt_1FAA1OLlsmkNgPt89Y9Qvi5b",
"object": "event",
"account": "acct_子アカウント",
"api_version": "2019-08-14",
"created": 1566456226,
"data": {
"object": {
"id": "cs_test_G21JU02SWKqBwdMZxZOy6bcnIzU9eIb85HJgptXo1m107zQiqP8h86V4",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "http://xxxx/stripe/charge-cancel",
"client_reference_id": "2",
"customer": "cus_FfV1HWhLR6GhM8",
"customer_email": null,
"display_items": [
{
"amount": 200,
"currency": "jpy",
"custom": {
"description": null,
"images": null,
"name": "Checkout Session Direct Charges デモ3"
},
"quantity": 10,
"type": "custom"
}
],
"livemode": false,
"locale": null,
"payment_intent": "pi_1FAA17LlsmkNgPt8igElJDpi",
"payment_method_types": [
"card"
],
"submit_type": null,
"subscription": null,
"success_url": "http://xxxx/stripe/charge-success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}',
'jsonBody' => NULL,
'httpHeaders' => NULL,
'requestId' => NULL,
'stripeCode' => NULL,
'sigHeader' => 't=1566456226,v1=664ea5151ae5598a24f10dbb76fd7450f2cabd7a0a24c9fa0787f53ca3182147',
'xdebug_message' => '<tr><th align=\'left\' bgcolor=\'#f57900\' colspan="5"><span style=\'background-color: #cc0000; color: #fce94f; font-size: x-large;\'>( ! )</span> Stripe\\Error\\SignatureVerification: No signatures found matching the expected signature for payload in /var/www/html/lib/composer/vendor/stripe/stripe-php/lib/WebhookSignature.php on line <i>55</i></th></tr>
<tr><th align=\'left\' bgcolor=\'#e9b96e\' colspan=\'5\'>Call Stack</th></tr>
<tr><th align=\'center\' bgcolor=\'#eeeeec\'>#</th><th align=\'left\' bgcolor=\'#eeeeec\'>Time</th><th align=\'left\' bgcolor=\'#eeeeec\'>Memory</th><th align=\'left\' bgcolor=\'#eeeeec\'>Function</th><th align=\'left\' bgcolor=\'#eeeeec\'>Location</th></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>1</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.0001</td><td bgcolor=\'#eeeeec\' align=\'right\'>396496</td><td bgcolor=\'#eeeeec\'>{main}( )</td><td title=\'/var/www/html/xxxx/xxxx/public_html/index.php\' bgcolor=\'#eeeeec\'>.../index.php<b>:</b>0</td></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>2</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.0121</td><td bgcolor=\'#eeeeec\' align=\'right\'>432376</td><td bgcolor=\'#eeeeec\'>MiniBlogApplication->run( )</td><td title=\'/var/www/html/xxxx/xxxx/public_html/index.php\' bgcolor=\'#eeeeec\'>.../index.php<b>:</b>12</td></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>3</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.0123</td><td bgcolor=\'#eeeeec\' align=\'right\'>432792</td><td bgcolor=\'#eeeeec\'>MiniBlogApplication->runAction( )</td><td title=\'/var/www/html/1-p46/0webapp/core/Application.php\' bgcolor=\'#eeeeec\'>.../Application.php<b>:</b>215</td></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>4</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.2865</td><td bgcolor=\'#eeeeec\' align=\'right\'>439072</td><td bgcolor=\'#eeeeec\'>StripeController->run( )</td><td title=\'/var/www/html/1-p46/0webapp/core/Application.php\' bgcolor=\'#eeeeec\'>.../Application.php<b>:</b>254</td></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>5</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.2865</td><td bgcolor=\'#eeeeec\' align=\'right\'>439112</td><td bgcolor=\'#eeeeec\'>StripeController->webhookAction( )</td><td title=\'/var/www/html/1-p46/0webapp/core/Controller.php\' bgcolor=\'#eeeeec\'>.../Controller.php<b>:</b>63</td></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>6</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.2934</td><td bgcolor=\'#eeeeec\' align=\'right\'>443896</td><td bgcolor=\'#eeeeec\'>Stripe\\Webhook::constructEvent( )</td><td title=\'/var/www/html/1-p46/0webapp/controllers/StripeController.php\' bgcolor=\'#eeeeec\'>.../StripeController.php<b>:</b>56</td></tr>
<tr><td bgcolor=\'#eeeeec\' align=\'center\'>7</td><td bgcolor=\'#eeeeec\' align=\'center\'>0.2935</td><td bgcolor=\'#eeeeec\' align=\'right\'>444536</td><td bgcolor=\'#eeeeec\'>Stripe\\WebhookSignature::verifyHeader( )</td><td title=\'/var/www/html/lib/composer/vendor/stripe/stripe-php/lib/Webhook.php\' bgcolor=\'#eeeeec\'>.../Webhook.php<b>:</b>27</td></tr>
',
))