【问题标题】:PayPal API - Initiate Monthly Bill?PayPal API - 发起月度账单?
【发布时间】:2018-01-16 13:46:02
【问题描述】:

如果我在我的网站上设置了“自动计费”按钮,可以使用哪个 API 来设置可变计费金额并启动计费?希望我做的 API 在这里描述:https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/manage-billing-plans/

我在任何地方都找不到这个,但我不确定它是否在 PayPal API 文档和前端之间的不同术语中丢失了 - 我这么说是因为它似乎没有自动计费这样的东西API 文档!

【问题讨论】:

    标签: paypal


    【解决方案1】:

    如果您想使用 REST API,请查看 Billing Plans

    如果您想使用经典 API,请查看 Recurring Paymments

    【讨论】:

      【解决方案2】:

      为了进一步接受答案,我无法实现我想要的 - 似乎无法通过 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>";
      

      希望这些 sn-ps 可以节省我花费的时间!

      【讨论】:

        猜你喜欢
        • 2021-06-01
        • 1970-01-01
        • 2014-12-26
        • 2013-01-13
        • 2023-03-20
        • 2012-10-28
        • 2013-05-14
        • 2021-07-13
        • 2015-10-22
        相关资源
        最近更新 更多