2

I am working for the first time with Stripe. I am using stand alone accounts. I have a platform account also. In my web site a number of people with different Stripe accounts will be opening up campaigns for which money can be donated by various donors. Each campaign owner has a separate stripe account and the platform will be charging through the campaign owner's stripe account.

So what it amounts to is the platform account will be charging for a number of campaigns through each campaign owner's Stripe account. My problem is related to web hooks. One point to remember is each campaign has an id associated with it in the database and I am storing the API key of each campaign owner's stripe account and associating it with this id. To get Stripe data from the web hook in the web hook end point I have to set the API key of the connected account with a statement like:

\Stripe\Stripe::setApiKey("api key of stand alone account");
$input = @file_get_contents("php://input");

The trouble with this is there is one web hook end point for a number of Stripe accounts. I cannot hard-code the API key in the above statement. I have to fetch the appropriate API key from my database using the id.

But when Stripe invokes the web hook end point I simply do not have the campaign id with me in order to fetch the appropriate API key and set the API key. Is there any solution around this?

4

1 回答 1

1

您不需要存储每个帐户的 API 密钥。您需要存储的唯一信息是帐户 ID ( "acct_...")。对于独立帐户,您的集成将在参数中收到 OAuth 流程最后一步stripe_user_id中的帐户 ID 。

然后,您可以使用您自己的(平台的)API 密钥和标头代表此帐户发出 API 请求Stripe-Account

特别是关于 webhook,通过“连接”端点发送到您的服务器的事件将包含一个user_id带有帐户 ID 的字段。所以你可以做这样的事情:

\Stripe\Stripe::setApiKey("PLATFORM_API_KEY");

$input = @file_get_contents("php://input");
$event_json = json_decode($input);
$user_id = $event_json->user_id;

// if you need to send an API request on behalf of this account,
// for example if you want to verify the event by fetching it from
// Stripe, you can use the Stripe-Account header:
$event = \Stripe\Event::retrieve(
    $event_json->id,
    array("stripe_account" => $user_id)
);
于 2016-07-07T10:27:11.520 回答