检索买家结算期限

时间:2014-09-03 15:44:30

标签: ruby-on-rails paypal paypal-subscriptions

我浏览了PayPal的API,但我无法找到我要查找的信息。我想将新订阅的结算周期结束值保存到数据库中。我有两个计划可供选择,每月和每年。每个订阅计划都设置为自动续订。

如果有人可以帮助我将结算周期的结束日期保存到订阅表中,那将会有所帮助!

我需要帮助找到我可以调用的PayPal属性以保存到数据库,因为我无法在API中找到它。

2 个答案:

答案 0 :(得分:2)

检索结算协议详细信息后,您将获得变量" final_payment_date" ,您可以将其存储在数据库中,因为它表示结算协议的结束日期。

我已经包含了示例请求和响应:

请求

GET https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1

回复:

{
  "id": "I-YBM89E79APJ1",
  "state": "Active",
  "description": "Agreement for Fast Speed Plan",
  "plan": {
    "payment_definitions": [
      {
        "type": "TRIAL",
        "frequency": "Month",
        "amount": {
          "currency": "USD",
          "value": "100.00"
        },
        "cycles": "12",
        "charge_models": [
          {
            "type": "TAX",
            "amount": {
              "currency": "USD",
              "value": "12.00"
            }
          },
          {
            "type": "SHIPPING",
            "amount": {
              "currency": "USD",
              "value": "10.00"
            }
          }
        ],
        "frequency_interval": "2"
      },
      {
        "type": "REGULAR",
        "frequency": "Month",
        "amount": {
          "currency": "USD",
          "value": "100.00"
        },
        "cycles": "12",
        "charge_models": [
          {
            "type": "TAX",
            "amount": {
              "currency": "USD",
              "value": "12.00"
            }
          },
          {
            "type": "SHIPPING",
            "amount": {
              "currency": "USD",
              "value": "10.00"
            }
          }
        ],
        "frequency_interval": "2"
      }
    ],
    "merchant_preferences": {
      "setup_fee": {
        "currency": "USD",
        "value": "1.00"
      },
      "max_fail_attempts": "0",
      "auto_bill_amount": "YES"
    }
  },
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1/suspend",
      "rel": "suspend",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1/re-activate",
      "rel": "re_activate",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1/cancel",
      "rel": "cancel",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1/bill-balance",
      "rel": "self",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1/set-balance",
      "rel": "self",
      "method": "POST"
    }
  ],
  "start_date": "2015-02-19T08:00:00Z",
  "agreement_details": {
    "outstanding_balance": {
      "currency": "USD",
      "value": "0.00"
    },
    "cycles_remaining": "12",
    "cycles_completed": "0",
    "next_billing_date": "2015-02-19T08:00:00Z",
    "last_payment_date": "2014-07-21T09:18:28Z",
    "last_payment_amount": {
      "currency": "USD",
      "value": "1.00"
    },
    "final_payment_date": "2018-12-19T10:00:00Z",
    "failed_payment_count": "0"
  }
}

答案 1 :(得分:1)

法律声明:此答案基于我的理解,您应该使用PayPal验证任何问题。您阅读和使用此处包含的任何信息即表示您同意我对您使用此信息的任何责任仅限于1美元,包括所有类型的声明,特殊等。 < / p>

如果您确实或将继续收到结束日期信息,则不清楚。 PayPal API specification中存在final_payment_date属性 。但是,在一个且仅有多个示例中的一个示例中,显示了另外的agreement_details对象。除了#34;响应示例&#34;之外,API规范中的任何其他地方都没有提到此对象。作为对&#34; Retrieve an agreement&#34;的请求响应的示例提供。除了那个例子之外,API规范中的任何其他地方也没有任何属性。

该示例将此对象显示为:

  "agreement_details": {
      "outstanding_balance": {
          "currency": "USD",
          "value": "0.00"
      },
      "cycles_remaining": "12",
      "cycles_completed": "0",
      "final_payment_date": "2016-12-19T10:00:00Z",
      "failed_payment_count": "0"
  }

可以注意到,这种结构包含非常有用的信息,其中一些信息在其他地方不可用。甚至可能的是,这种结构仅仅是偶然地被排除在说明书之外。但是,没有办法确定这一点。您需要选择如何处理这种情况。

如果我正在编写与API交互的代码:如果代码仅供我自己使用,我会继续使用/依赖结构并努力联系PayPal进行澄清。如果我正在编写代码以用于除我以外的任何其他情况,我会做出非常协调的努力以从PayPal获得澄清。如果我没有收到PayPal的澄清,我可能会让代码计算结束日期,并将其与该字段中可能出现的日期进行比较。至少,如果出现差异,我会记录警告/引起用户的注意。

请注意,此信息未包含在执行&#34; Create an agreement&#34;,&#34; Execute an agreement过程中的回复示例中&#34;,&#34; Update an agreement&#34;,&#34; Suspend an agreement&#34;,&#34; Reactivate an agreement&#34;,&#34 ; Cancel an agreement&#34;,&#34; Set outstanding agreement amounts&#34;,或&#34; Bill outstanding agreement amounts&#34;。

对&#34; Retrieve an agreement&#34;的响应的完整示例请求是:

{
  "id": "I-0LN988D3JACS",
  "state": "Pending",
  "description": "New Description",
  "plan": {
    "payment_definitions": [
      {
        "type": "REGULAR",
        "frequency": "Month",
        "amount": {
          "currency": "USD",
          "value": "100.00"
        },
        "charge_models": [
          {
            "type": "TAX",
            "amount": {
              "currency": "USD",
              "value": "12.00"
            }
          },
          {
            "type": "SHIPPING",
            "amount": {
              "currency": "USD",
              "value": "10.00"
            }
          }
        ],
        "cycles": "12",
        "frequency_interval": "2"
      }
    ],
    "merchant_preferences": {
      "setup_fee": {
        "currency": "USD",
        "value": "0.00"
      },
      "max_fail_attempts": "0",
      "auto_bill_amount": "YES"
    }
  },
  "links": [
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/suspend",
      "rel": "suspend",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/re-activate",
      "rel": "re_activate",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/cancel",
      "rel": "cancel",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/bill-balance",
      "rel": "self",
      "method": "POST"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-0LN988D3JACS/set-balance",
      "rel": "self",
      "method": "POST"
    }
  ],
  "start_date": "2015-02-19T08:00:00Z",
  "agreement_details": {
    "outstanding_balance": {
      "currency": "USD",
      "value": "0.00"
    },
    "cycles_remaining": "12",
    "cycles_completed": "0",
    "final_payment_date": "2016-12-19T10:00:00Z",
    "failed_payment_count": "0"
  }
}

PayPal API指定&#34;创建个人资料后,PayPal会根据结算开始日期,结算频率和结算金额自动对付款进行排队。付款重新出现,直到个人资料到期,有太多的失败付款才能继续,或者您取消个人资料。&#34;因此,结束日期取决于开始日期和结算频率以及付款次数。

与上述数据结构相反,当您&#34; Create an agreement&#34;时,请求不会返回有关结束日期的计算信息。您作为回复收到的数据如下:

Response (agreement object):

Returns the agreement object based on the billing plan. The response includes a billing agreement id and return links to obtain the buyer information and to execute the subscription.      

Property                        Type                             Description
id                              string                           Identifier of the agreement.
name                            string                           Name of the agreement.
description                     string                           Description of the agreement.
start_date                      string                           Start date of the agreement. Date format yyyy-MM-dd z, as defined in ISO8601.
payer                           payer                            Details of the buyer who is enrolling in this agreement. This information is gathered from execution of the approval URL.
shipping_address                address                          Shipping address object of the agreement, which should be provided if it is different from the default address.
override_merchant_preferences   merchant_preferences             Default merchant preferences from the billing plan are used, unless override preferences are provided here.
override_charge_models          array of override_charge_model   Array of override_charge_model for this agreement if needed to change the default models from the billing plan.
plan                            plan                             Plan details for this agreement.
create_time                     string                           Date and time that this resource was created. Date format yyyy-MM-dd z, as defined in ISO8601.
update_time                     string                           Date and time that this resource was updated. Date format yyyy-MM-dd z, as defined in ISO8601.
links                           array of links                   ~

plan object:

Billing plan resource that will be used to create a billing agreement.      

Property                Type                           Description
id                      string                         Identifier of the billing plan. Assigned in response.
name                    string                         Name of the billing plan. Required.
description             string                         Description of the billing plan. Required.
type                    string                         Type of the billing plan. Possible types include: FIXED and INFINITE. Required.
state                   string                         Status of the billing plan. Possible states include: CREATED, ACTIVE, and INACTIVE. Assigned in response.
payee                   payee                          Details of the merchant who is creating this billing plan. Assigned in response.
create_time             string                         Time when the billing plan was created, represented as YYYY-MM-DDTimeTimezone format. Assigned in response.
update_time             string                         Time when this billing plan was updated, represented as YYYY-MM-DDTimeTimezone format. Assigned in response.
payment_definitions     array of payment_definition    Array of payment definitions for this billing plan.
terms                   array of terms                 Array of terms for this billing plan. Assigned in response.
merchant_preferences    merchant_preferences           Specific preferences such as: set up fee, max fail attempts, autobill amount, and others that are configured for this billing plan.
links                   array of links                 ~

payment_definition object:

Resource representing payment definition scheduling information.

Property            Type                      Description
id                  string                    Identifier of the payment_definition. Assigned in response.
name                string                    Name of the payment definition. Required.
type                string                    Type of the payment definition. Possible types include: TRIAL and REGULAR. Required.
frequency_interval  string                    How frequently the customer should be charged. Required.
frequency           string                    Frequency of the payment definition offered. Required.
cycles              string                    Number of cycles in this payment definition. Required.
amount              currency                  Amount that will be charged at the end of each cycle for this payment definition. Required.
charge_models       array of charge_models    Array of charge_models for this payment definition.

terms object:

Resource representing terms used by the plan.       

Property             Type       Description
id                   string     Identifier of the terms. Assigned in response.
type                 string     Term type Required.
max_billing_amount   currency   Max Amount associated with this term. Required.
occurrences          string     How many times money can be pulled during this term. Required.
amount_range         currency   Amount_range associated with this term. Required.
buyer_editable       string     Buyer’s ability to edit the amount in this term. Required.

currency object:

Base object for all financial value related fields (balance, payment due, etc.)     

Property    Type       Description
currency    string     3 letter currency code as defined by ISO 4217. Required.
value       string     amount up to N digit after the decimals separator as defined in ISO 4217 for the appropriate currency code. Required.

charge_models object:

A resource representing a charge model for a payment definition.        

Property    Type       Description
id          string     Identifier of the charge model. Assigned in response.
type        string     Type of charge model, possible values can be shipping/tax. Required.
amount      currency   Specific amount for this charge model. Required.

[数据结构定义的某些部分未包含在此处,因为它们不会影响结束日期。]

示例回复:

{
  "name": "T-Shirt of the Month Club Agreement",
  "description": "Agreement for T-Shirt of the Month Club Plan",
  "plan": {
    "id": "P-94458432VR012762KRWBZEUA",
    "state": "ACTIVE",
    "name": "T-Shirt of the Month Club Plan",
    "description": "Template creation.",
    "type": "FIXED",
    "payment_definitions": [
      {
        "id": "PD-50606817NF8063316RWBZEUA",
        "name": "Regular Payments",
        "type": "REGULAR",
        "frequency": "Month",
        "amount": {
          "currency": "USD",
          "value": "100"
        },
        "charge_models": [
          {
            "id": "CHM-92S85978TN737850VRWBZEUA",
            "type": "TAX",
            "amount": {
              "currency": "USD",
              "value": "12"
            }
          },
          {
            "id": "CHM-55M5618301871492MRWBZEUA",
            "type": "SHIPPING",
            "amount": {
              "currency": "USD",
              "value": "10"
            }
          }
        ],
        "cycles": "12",
        "frequency_interval": "2"
      }
    ],
    "merchant_preferences": {
      "setup_fee": {
        "currency": "USD",
        "value": "1"
      },
      "max_fail_attempts": "0",
      "return_url": "http://www.return.com",
      "cancel_url": "http://www.cancel.com",
      "auto_bill_amount": "YES",
      "initial_fail_amount_action": "CONTINUE"
    }
  },
  "links": [
    {
      "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-0JP008296V451950C",
      "rel": "approval_url",
      "method": "REDIRECT"
    },
    {
      "href": "https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-0JP008296V451950C/agreement-execute",
      "rel": "execute",
      "method": "POST"
    }
  ],
  "start_date": "2015-02-19T00:37:04Z"
}

自己计算结束日期:

对于此配置文件,与确定结束日期相关的信息是:

{
  "plan": {
    "payment_definitions": [
      {
        "frequency": "Month",
        "cycles": "12",
        "frequency_interval": "2"
      }
    ],
  },
  "start_date": "2015-02-19T00:37:04Z"
}

这是您收到的信息。您没有明确说明结束日期。您必须自己计算付款的结束。在上面的例子中,从2015-02-19开始,每隔一个月付款12次。客户将在接下来的几天收费:

Charge    Date
Number  
  1       2015-02-19
  2       2015-04-19
  3       2015-06-19
  4       2015-08-19
  5       2015-10-19
  6       2015-12-19
  7       2016-02-19
  8       2016-04-19
  9       2016-06-19
  10      2016-08-19
  11      2016-10-19
  12      2016-12-19