LoginSignup
1
2

More than 3 years have passed since last update.

stripeエンドポイント作成 php

Last updated at Posted at 2020-08-27

stripe custom webhook
ダッシュボードがトリガー

webhook.php
<?php
ストライプキー挿入
//
// Webhook の署名を確認する
// https://stripe.com/docs/webhooks/signatures#verify-official-libraries
//
$endpoint_secret = 'えんどポイントダッシュボードのエンドポイントにて';


$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) {
    // Invalid payload
    http_response_code(400); // PHP 5.4 or greater
    exit();
} catch(\Stripe\Error\SignatureVerification $e) {
    // Invalid signature
    http_response_code(400); // PHP 5.4 or greater
    exit();
}

//
// $eventに対しての処理を行う
//
$event_json = json_decode($payload);
// $event_json = json_decode($payload);
// ダッシュボードのテストでは0だからうまく行かない ここら辺の
// $event_id = $event_json->id;
// try {
//     $event = \Stripe\Event::retrieve($event_id);
// } catch(\Stripe\Error\InvalidRequest $e) {
//     // Invalid payload
//     http_response_code(400);
//     exit();
// } catch(\Stripe\Error $e) {
//     // Invalid payload
//     http_response_code(400);
//     exit();
// }

if ($event->type == 'customer.created') {
}
if ($event->type == 'account.updated') {
  $account = $event->data->object;
  handleAccountUpdate($account);
  // var_dump($event_json);
}

//ここにうまくいったときと処理
if ($event->type == 'checkout.session.completed') {
dbやらメールなど
      var_dump($event_json); 




}

if ($event->type == 'customer.subscription.deleted') {
}

if ($event->type == 'customer.subscription.updated') {
}

if ($event->type == 'invoice.payment_succeeded') {
}

http_response_code(200);

function handleAccountUpdate($account) {
  // Fulfill the purchase.
  echo $account;
};
?>

Q.ユーザーが、アカウント作成の際にstripe様に運転免許等のIDを提出すると思うのですが、stripe様がそのIDを許可または許可しなかった行為を行われた際に、account.updatedのイベントが発生しwebhookで受け付けることは可能でしょうか?

A.はい、account.updated 、person.updated (Person API 使用の場合)で可能です。
身分証明書のカラースキャンまたは写真が Stripe のチェックを通ると、書類の要件が requirements[currently_due] から削除されます。その人物または企業のすべての確認要件を満たすと verification[status] フィールドは更新されて verified になります。また確認プロセスの完了時に account.updated Webhook 通知が届きます。

また、確認が失敗するとステータスは unverified となり details フィールドに理由を伝えるメッセージが表示されます。このメッセージは「提供された画像が読み取れません」のようにユーザに表示して問題ないものです。さらにこの応答には scan_not_readable のような details_code 値が含まれます。
失敗すると requirements[currently_due] が新しい身分証明書のアップロードが必要であることを示します。確認の期日が迫っている場合は、requirements[current_deadline] に日付が入力されている場合があります。また account.updated Webhook 通知が送信されます。

Q.また、https://stripe.com/docs/connect/identity-verification-api こちらを参照すた際に主にエラーが発生するのはユーザーのアカウント作成が主となっているようなのですが、銀行口座アカウント(external account)でもアカウント作成のようなエラーが発生し、エラーを解除しなければ送金ができないということは起こりうるのでしょうか?

A,連結されたアカウントでの入金アクティビティはすべて、Webhook を使用して追跡できます。入金固有の以下のイベントが発生します。
payout.created
payout.updated
payout.paid
payout.failed

入金を完了できない場合は、payout.failed イベントが発生します。このイベントの failure_code プロパティは理由を示します。また、入金に関与する銀行口座が無効になります。銀行口座が無効になるとaccount.external_account.updated 通知が起動します。プラットフォームが連結されたアカウントの銀行口座情報を更新するまで、自動入金も手動入金も完了できませんことご留意ください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2