如果我有"自动结算"在我的网站上设置按钮,哪个API可用于设置变量计费金额并启动账单?我希望我在这里描述的API:https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/manage-billing-plans/
我无法在任何地方找到这个,但我不确定它是否会在PayPal API文档和前端之间的不同术语中丢失 - 我之所以这样说是因为它&#39 ;似乎在API文档中没有自动计费这样的东西!
答案 0 :(得分:0)
如果您想使用REST API,请查看Billing Plans。
如果您想使用Classic API,请查看Recurring Paymments。
答案 1 :(得分:0)
为了进一步接受已接受的答案,我无法达到我想要的效果 - 似乎无法通过API触发“自动计费”。您需要创建开票计划,然后根据计划创建协议,然后执行协议。
从安德鲁的回答中,我首先得到了一个访问令牌。在我的cURLless环境中,我这样做了:
//sandbox
$clientid = "AbFnq7P52jf6AUWpu.....";
$secret = "ECfJRJBDnA26VVNAq.....";
$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$auth = base64_encode($clientid . ":" . $secret);
$data = array(
'grant_type' => 'client_credentials'
);
$options = array(
'http' => array(
'header' => "Authorization: Basic {$auth}\r\nAccept: application/json\r\nAccept-Language: en_US\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$arr = json_decode($result, true);
echo "<pre>"; print_r($arr); echo "</pre>";
$accesstoken = $arr['access_token'];
然后是“整合步骤”https://developer.paypal.com/docs/integration/direct/billing-plans-and-agreements/#integration-steps
我做了这样的cURLless API调用(创建计划示例):
$url = 'https://api.sandbox.paypal.com/v1/payments/billing-plans/';
$options = array(
'http' => array(
'header' => "Authorization: Bearer {$accesstoken}\r\nContent-Type: application/json\r\n",
'method' => 'POST',
'content' => '{
"name": "Test Plan",
"description": "My first test plan",
"type": "INFINITE",
"payment_definitions": [
{
"name": "Regular payment definition",
"type": "REGULAR",
"type":"REGULAR",
"frequency":"Month",
"amount":{
"currency":"AUD",
"value":"100.00"
},
"cycles":"0",
"charge_models":[
{
"type":"TAX",
"amount":{
"currency":"AUD",
"value":"0.00"
}
},
{
"type":"SHIPPING",
"amount":{
"currency":"AUD",
"value":"0.00"
}
}
],
"frequency_interval":"1"
}
],
"merchant_preferences": {
"setup_fee": {
"value": "0",
"currency": "AUD"
},
"return_url": "http://www.paypal.com",
"cancel_url": "http://www.paypal.com/cancel",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE",
"max_fail_attempts": "0"
}
}'
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$arr = json_decode($result, true);
echo "<pre>"; print_r($arr); echo "</pre>";
希望这些片段可以节省我花费的时间!