[英]PHP - Issue with Stripe API Create Card
由於某種原因,我在實施 Stripe API 方面做得並不好。 我一直在努力創建客戶並收取罰款,但是當我嘗試向現有客戶添加新卡時,我無法使其正常工作。
這是 API 的基本實現(足夠簡單),但它不斷提供錯誤:
$customer = Stripe_Customer::retrieve($stripe_customer_id);
$customer->sources->create(array("card" => $token));
https://stripe.com/docs/api#create_card
錯誤日志:
PHP Fatal error: Uncaught exception 'Stripe_InvalidRequestError' with message 'Missing required param: source' in / ... /scripts/stripe/stripe_library/lib/Stripe/ApiRequestor.php:142
Stack trace:
0 / ... /scripts/stripe/stripe_library/lib/Stripe/ApiRequestor.php(254): Stripe_ApiRequestor->handleApiError('{\n "error": {\n...', 400, Array)
1 / ... /scripts/stripe/stripe_library/lib/Stripe/ApiRequestor.php(104): Stripe_ApiRequestor->_interpretResponse('{\n "error": {\n...', 400)
2 / ... /scripts/stripe/stripe_library/lib/Stripe/List.php(19): Stripe_ApiRequestor->request('post', '/v1/customers/c...', Array)
3 / ... /join/update-card-stripe.php(34): Stripe_List->create(Array)
4 {main} thrown in / ... /scripts/stripe/stripe_library/lib/Stripe/ApiRequestor.php on line 142
任何幫助,將不勝感激。 謝謝!
我認為條紋示例文檔已過時或不正確。 查看“定義”下的文檔,它應該是:
$customer->sources->create(array("source" => $token));
在“示例請求”下,它確實與您所做的完全一樣,但是查看左側記錄的參數,它實際上應該是“源”而不是“卡片”
我使用以下代碼向現有客戶添加了一張新卡:
$customer_stripe_data = \Stripe\Customer::retrieve('customer stripe id');
$createdCard = $customer_stripe_data->sources->create(array("source" => $this->input->post('stripe_token')));
$customer_stripe_data->save();
通過在我的 html 文件中包含條紋 js 文件,我得到了$this->input->post('stripe_token')
。
我已由客戶創建並嘗試使用源令牌注冊該卡
// create a new customer if our current user doesn't have one
$stripe_customer = \Stripe\Customer::create(array(
'source' => $token,
'description' => $displayname,
'metadata' => array('BHAA_ID'=>$bhaa_id),
'email' => $email
)
);
$stripe_customer_id=$stripe_customer->id;
update_user_meta( $bhaa_id, 'stripe_customer_id', $stripe_customer_id );
error_log('$stripe_customer_id '.$stripe_customer_id);
// http://stackoverflow.com/questions/29393338/php-issue-with-stripe-api-create-card
$customer = \Stripe\Customer::retrieve($stripe_customer_id);
$card = $customer->sources->create(array("source" => $token));
error_log('card '.$card->id);
但我得到了同樣的錯誤
[16-Dec-2015 18:54:12 UTC] PHP Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Missing required param: source.' in /var/www/wp-content/plugins/events-manager-pro-stripe-token-gateway-master/vendor/stripe/stripe-php/lib/ApiRequestor.php:103 from API request 'req_7Xq54M2AlKDijE'
Stack trace:
#0 /var/www/wp-content/plugins/events-manager-pro-stripe-token-gateway-master/vendor/stripe/stripe-php/lib/ApiRequestor.php(217): Stripe\ApiRequestor->handleApiError('{? "error": {?...', 400, Array, Array)
#1 /var/www/wp-content/plugins/events-manager-pro-stripe-token-gateway-master/vendor/stripe/stripe-php/lib/ApiRequestor.php(60): Stripe\ApiRequestor->_interpretResponse('{? "error": {?...', 400, Array)
#2 /var/www/wp-content/plugins/events-manager-pro-stripe-token-gateway-master/vendor/stripe/stripe-php/lib/ApiResource.php(108): Stripe\ApiRequestor->request('post', '/v1/customers/c...', Array, Array)
#3 /var/www/wp-content/plugins/events-manager-pro-stripe-token-gateway-master/vendor/stripe/stripe-php/lib/ApiResource.php(99): Stripe\Ap in /var/www/wp-content/plugins/events-manager-pro-stripe-token-gateway-master/vendor/stripe/stripe-php/lib/ApiRequestor.php on line 103
我懷疑問題可能出在 Stripe PHP API 中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.