PHP cURL请求无法平衡付款

时间:2013-07-11 21:06:44

标签: php curl balanced-payments

我正在尝试向Balanced Payment's测试市场提交cURL请求以模拟对信用卡收费,但我继续获得“未经授权”状态,其中“需要身份验证”作为category_code。我已经能够使用他们的文档成功提交其他请求,所以我不太确定我做错了什么。

我正在关注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" } 

1 个答案:

答案 0 :(得分:0)

您没有进行身份验证。尝试添加

curl_setopt('6d2896e8e9a911e2b3cd026ba7f8ec28:', CURLOPT_USERPWD)