[英]Error sharing customer stripe and create charges with php
對不起我的英語。
我嘗試使用獨立帳戶通過條帶化連接帳戶來創建費用。 我正在使用以下條紋中的這篇文章連接我的帳戶: 示例OAuth應用程序 。 我有3個帳戶:A)主帳戶。 此帳戶是我們應用程序的客戶。 帳戶B和帳戶C是與帳戶A連接的其他帳戶(我在帳戶A的設置中看到這兩個帳戶已連接。這告訴我兩個帳戶已連接,對嗎?)。 所有用戶的應用程序都位於帳戶A中,我們希望與帳戶B和C共享,這是我們的目標。
連接帳戶后,我們將acces_token和refresh令牌保存在數據庫中。 共享客戶的文檔說,我們需要使用customer_id和account_id創建一個令牌,以便使用customer的信用卡信息創建令牌,但是當我們執行代碼時,它將返回錯誤:
提供的密鑰“ sk_test _ ******************** uJ3l”無權訪問帳戶“ acct _--------------” (或該帳戶不存在)。 應用程序訪問權限可能已被撤消。
我們已經測試了傳遞給api的變量的幾種組合,並且結果始終返回錯誤。
在這種情況下怎么了。 你能幫我們嗎???
這是我們使用的代碼:所有注釋都是我們嘗試的另一個測試:
public function createtransaction($customer_id, $paymentDesc, $destinationAccount) {
$errors = array();
try {
$secret_key = $this->get_secret_key();
\Stripe\Stripe::setApiKey($secret_key);
// THIS ONLY FOR TESTING PURPOSE. WE WANT SEE IF CAN ACCESS TO CONNECTED ACCOUNT
// Fetching an account just needs the ID as a parameter
// WHIT ACCESS_TOKEN WORKS THE RETRIEVE METHOD
// $account = \Stripe\Account::retrieve('access_token_from_db');
// WHIT ACCOUNT_ID DOES NOT. RETURNS AN ERROR
// $account = \Stripe\Account::retrieve('acct_***********');
// echo "<pre>------";
// print_r($account);
// echo "-----</pre>";
// HERE ONLY WE CAN TEST IF WE CAN CREATE A CUSTOMER. THIS IS ONLY TO CHECK IF THE ACCOUNT IS CONNECTED. THE CUSTOMER ALREADY EXISTS IN MAIN ACCOUNT
// Recommended: sending API key with every request
// \Stripe\Customer::create(
// array("description" => "example@stripe.com"),
// array("api_key" => 'sk_test_***************') // account's access token from the Connect flow
// SAME. WITH stripe_account DOES NOT WORK. WHIT api_key PARAM WORKS WELL
// );
// THE DOCS SAYS WE NEED CREATE A TOEKN WITH customer AND stripe_account, BUT IT RETURNS AN ERROR OF PERMISSION
// Create a Token from the existing customer on the platform's account
// $token = \Stripe\Token::create(
// array("customer" => $customer_id),
// array("stripe_account" => 'acct_********************') // id of the connected account
// );
// echo "<pre>------";
// print_r($token);
// echo "-----</pre>";
// ONE COMBINATION. DOES NOT WORK
// var_dump($customer_id, $paymentDesc, $destinationAccount);
// $charge = \Stripe\Charge::create(array(
// "amount" => $paymentDesc['total'] * 100,
// "currency" => "usd",
// "source" => $token,
// "description" => $paymentDesc['description'],
// 'destination' => $destinationAccount
// ));
//
//
// IT WORKS IN THE MAIN ACCOUNT BUT IT IS NOT OUR GOAL, BUT WE CAN TRANSFER THE MONEY TO ANOTHER CONNECTED ACCOUNT
// $charge = \Stripe\Charge::create(array(
// 'amount' => $paymentDesc['total'] * 100,
// 'currency' => 'usd',
// 'customer' => $customer_id,
// "description" => $paymentDesc['description']
// ));
// ANOTHER COMBINATION. DOES NOT WORK
/*$charge = \Stripe\Charge::create(array(
'amount' => $paymentDesc['total'] * 100,
'currency' => 'usd',
"description" => $paymentDesc['description'],
'customer' => $customer_id
), array('stripe_account' => 'acct_************'));*/
// ANOTHER COMBINATION. DOES NOT WORK
/*$charge = \Stripe\Charge::create(array(
'amount' => $paymentDesc['total'] * 100,
'currency' => 'usd',
"description" => $paymentDesc['description'],
'customer' => $customer_id
), array('api_key' => 'ACCESS_TOKEN_IN_DB'));
echo "<pre>------";
print_r($charge);
echo "-----</pre>";
return array('charge' => $charge);*/
} catch(Stripe_CardError $e) {
$errors = array('error' => false, 'message' => 'Card was declined.', 'e' => $e);
} catch (Stripe_InvalidRequestError $e) {
$errors = array('error' => false, 'message' => 'Invalid parameters were supplied to Stripe\'s API', 'e' => $e);
} catch (Stripe_AuthenticationError $e) {
$errors = array('error' => false, 'message' => 'Authentication with Stripe\'s API failed!', 'e' => $e);
} catch (Stripe_ApiConnectionError $e) {
$errors = array('error' => false, 'message' => 'Network communication with Stripe failed', 'e' => $e);
} catch (Stripe_Error $e) {
$errors = array('error' => false, 'message' => 'Stripe error. Something wrong just happened!', 'e' => $e);
} catch (Exception $e) {
$errors = array('error' => false, 'message' => 'An error has ocurred getting info customer.', 'e' => $e);
}
return $errors;
}
您不需要保存access_token
和refresh_token
,只需包含包含已連接帳戶ID的stripe_user_id
即可使用Connect。
您可以對所有請求使用平台的秘密API密鑰,只需將已連接的帳戶ID傳遞給Stripe-account標頭即可,如共享客戶文檔中所示。 通常,可以將此標頭添加到幾乎每個API請求中,以將其定向到已連接的帳戶:
https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header
就您而言,您可以:
// Create a Token from the existing customer on the platform's account
$sharedToken = \Stripe\Token::create(
array("customer" => CUSTOMER_ID, "card" => CARD_ID),
array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID) // id of the connected account
);
$sharedCustomer = \Stripe\Customer::create(array(
"description" => "Customer for noah.robinson@example.com",
"source" => $sharedToken),
array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID)
);
然后,您可以通過以下方式從該共享客戶創建費用:
\Stripe\Charge::create(array(
"amount" => 2000,
"currency" => "usd",
"customer" => $sharedCustomer),
array("stripe_account" => CONNECTED_STRIPE_ACCOUNT_ID)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.