2013-07-11 54 views
3

我試圖提交一個cURL請求到Balanced Payment's測試市場來模擬收取信用卡,但我一直以「需要身份驗證」作爲category_code獲得「未授權」狀態。我已經能夠使用他們的文檔成功提交其他請求,所以我不太確定我做錯了什麼。PHP cURL請求未能平衡付款

我在關注these steps向測試市場中的信用卡收費。

我只是在第1步創建一個帳戶來關聯卡標記與其被稱爲URI。

//all of these parameters are supplied in the documentation 

$url = 'https://api.balancedpayments.com/v1/marketplaces/TEST-MP3k9AuX9cW549vxxxxxxxxxxxxxxxx/accounts'; 
$post_arr[] = 'username=6d2896e8e9a911e2b3cd02xxxxxxxxxxxxxx:'; 
$post_arr[] = 'card_uri=/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/cards/CC3DSm7qtThxh6DRe6lnYNVC'; 
$post = implode('&',$post_arr); 

//make the request 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); // 3 seconds to connect 
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); // 10 seconds to complete 
$output = curl_exec($ch); 
curl_close($ch); 

print_r($output); 

這是輸出

{ "status": "Unauthorized", "category_code": "authentication-required", "category_type": "permission", "_uris": {}, "description": "Not permitted to perform show on cards. Your request id is OHMefab3f08ea6711e2950a026ba7xxxxxxxxxxxxx.", "request_id": "OHMefab3f08ea6711e2950a026baxxxxxxxxxxxx", "status_code": 401 } 

然而,我當我提出以下參數來tokenize a card的要求,它的工作原理。

$url = 'https://api.balancedpayments.com/v1/marketplaces/TEST-MP3k9AuX9cW549vxxxxxxxxxxxxx/cards'; 
$post_arr[] = '6d2896e8e9a911e2b3cd026bxxxxxxxxxxxxxx:'; 
$post_arr[] = 'expiration_month=12'; 
$post_arr[] = 'security_code=123'; 
$post_arr[] = 'card_number=5105105105105100'; 
$post_arr[] = 'expiration_year=2020'; 
$post_arr[] = 'category_type=request'; 
$post = implode('&',$post_arr); 

這裏是輸出

{ "security_code_check": "true", "_type": "card", "hash": "b7250dd4b4827a88d5e4132b67f02916bce6f8e83d4ca0d779d1351b360ff6af", "brand": "MasterCard", "expiration_month": 12, "_uris": {}, "meta": {}, "last_four": "5100", "id": "CCSBORr685LWzmR62FSKZaw", "customer": null, "account": null, "postal_code_check": "true", "name": "None", "expiration_year": 2020, "created_at": "2013-07-11T21:01:53.245948Z", "uri": "/v1/marketplaces/TEST-MP3k9AuX9cW549vd1Ao5M0OW/cards/CCSBORr685LWzmR62FSKZaw", "card_type": "mastercard", "is_valid": true, "is_verified": true } 

編輯 - 我仍然會錯誤地做一些事情,但我認爲有可能是一個錯誤的文件

我刪除了「card_uri在'參數從我的請求,它成功。在檢查返回的JSON時,我發現它是'cards_uri'而不是'card_uri'。也許我仍然沒有做正確的事情,但是當我將最初的請求改爲'cards_uri'時,它成功了。

這裏現在是輸出

{ "_type": "account", "_uris": { "holds_uri": { "_type": "page", "key": "holds" }, "bank_accounts_uri": { "_type": "page", "key": "bank_accounts" }, "refunds_uri": { "_type": "page", "key": "refunds" }, "customer_uri": { "_type": "customer", "key": "customer" }, "debits_uri": { "_type": "page", "key": "debits" }, "transactions_uri": { "_type": "page", "key": "transactions" }, "credits_uri": { "_type": "page", "key": "credits" }, "cards_uri": { "_type": "page", "key": "cards" } }, "bank_accounts_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/bank_accounts", "meta": {}, "transactions_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/transactions", "email_address": null, "id": "AC2A9aCbuzUWalMNX7JXbhrk", "credits_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/credits", "cards_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/cards", "holds_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/holds", "name": null, "roles": [], "created_at": "2013-07-11T21:24:55.567233Z", "uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk", "refunds_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/refunds", "customer_uri": "/v1/customers/AC2A9aCbuzUWalMNX7JXbhrk", "debits_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/debits" } 

回答

0

您還沒有驗證。嘗試添加

curl_setopt('6d2896e8e9a911e2b3cd026ba7f8ec28:', CURLOPT_USERPWD) 
+0

我通過簡單地將'card_uri'更改爲'cards_uri'來實現它。底部的編輯顯示了一些細節。我也嘗試了你的方法,但是它引用了一個錯誤,指出在該行中引用了「遇到的格式不正確的數值」。 – user1406951