[英]Retrieving buyers billing end period
I browse around PayPal's API and I was not able to find the information I am looking for. 我浏览了PayPal的API,但是找不到所需的信息。 I would like to save the billing period end value for the new subscription to the database.
我想为数据库的新订阅保存计费期末值。 I have two plans to choose from, monthly and annually.
我有两个计划可供选择,每月和每年。 Each subscription plan is set to auto renewal.
每个订阅计划都设置为自动续订。
If someone could help assist me in saving the end date of the billing period to the Subscriptions table that would be helpful! 如果有人可以帮助我将结算期的结束日期保存到“订阅”表中,那将很有帮助!
I need help finding the PayPal attribute I can call on to save to the database since I can't locate it in the API. 我需要帮助找到可以调用以保存到数据库的PayPal属性,因为我无法在API中找到它。
Once you retrieve the Billing Agreement Details you will get the variable "final_payment_date" which you can store in your DB as it indicates the end date for the billing agreement . 检索开票协议明细后,您将获得变量“ final_payment_date” ,可以将其存储在数据库中,因为它指示了开票协议的结束日期。
I have included the sample request and response : 我已经包括了示例请求和响应:
Request 请求
GET https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-YBM89E79APJ1
Response : 回应:
{
"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"
}
}
Legal note: This answer is based on my understanding, you should verify anything you have a question on with PayPal. 法律说明:该答案是基于我的理解,您应该对贝宝(PayPal)的任何问题进行核实。 Your reading and use of any information contained herein constitutes your agreement that any liability on my part for your use of this information is limited to $1 including all types of claims, special, etc.
您阅读和使用此处包含的所有信息即表示您同意,我对您使用此信息所承担的任何责任限于$ 1,包括所有类型的索赔,特殊要求等。
If you do, or will continue to, receive end date information is unclear. 如果您知道或将继续收到结束日期信息,目前尚不清楚。 The existence of a
final_payment_date
property is not defined in the PayPal API specification . 一个的存在
final_payment_date
属性没有在所述定义的PayPal API规范 。 However, in one, and only one of multiple examples, an additional agreement_details
object is shown. 但是,在多个示例中的一个(只有一个)中,显示了一个额外的
agreement_details
对象。 This object is not mentioned anywhere else in the API specification other than within the "Response Sample" provided as an example of the response to a request to " Retrieve an agreement ". 除了在“ Response Sample”(响应示例)中作为对“ 检索协议 ”的请求的响应示例而提供的API规范之外的其他任何地方,均未提及该对象。 Nor are any of the properties anywhere else in the API specification, other than in that one example.
除了一个示例之外,API规范中其他任何地方的属性也没有。
The example shows this object as: 该示例将该对象显示为:
"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"
}
As can be noted this structure contains very useful information, some of which is unavailable elsewhere. 可以注意到,该结构包含非常有用的信息,其中某些信息在其他地方不可用。 It is possible, even probable that this structure was merely left out of the specification by accident.
甚至有可能偶然将这种结构排除在规范之外。 However, there is no way to know that for sure.
但是,没有办法确定这一点。 You will need to make a choice as to how you want to handle the situation.
您将需要选择如何处理这种情况。
If I were writing code to interact with the API: If the code was just for my own use, I would go ahead an use/rely on the structure and make some effort to contact PayPal for clarification. 如果我正在编写与API交互的代码:如果该代码仅供我自己使用,我将继续使用/依赖该结构,并做出一些努力与PayPal联系以进行澄清。 If I were writing code to be used for any other situation other than myself, I would make a very concerted effort to get clarification from PayPal.
如果我正在编写将代码用于除我之外的其他任何情况,则我将竭尽全力以使PayPal做出澄清。 If I received no clarification from PayPal, I would probably have the code calculate the end date and compare it against the date which might be in this field.
如果我没有从贝宝(PayPal)获得任何澄清,则代码可能会计算出结束日期,并将其与该字段中的日期进行比较。 At a minimum, I would log a warning/bring it to the user's attention if there was a discrepancy.
至少,如果有差异,我会记录一条警告/提醒用户注意。
It should be noted that this information is not contained in the examples of the responses you get when going through the process of " Create an agreement ", " Execute an agreement ", " Update an agreement ", " Suspend an agreement ", " Reactivate an agreement ", " Cancel an agreement ", " Set outstanding agreement amounts ", or " Bill outstanding agreement amounts ". 应当注意的是,在通过“ 创建协议 ”,“ 执行协议 ”,“ 更新协议 ”,“ 暂停协议 ”,“ 重新激活 ”过程获得的响应示例中不包含此信息。 协议 ”,“ 取消协议 ”,“ 设置未完成的协议金额 ”或“ 结算未完成的协议金额 ”。
The full example of the response to a " Retrieve an agreement " request is: 响应“ 检索协议 ”请求的完整示例是:
{
"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"
}
}
The PayPal API specifies that "After creating a profile, PayPal automatically queues payments based on the billing start date, billing frequency, and billing amount. Payments reoccur until the profile expires, there are too many failed payments to continue, or you cancel the profile." PayPal API指定“在创建配置文件后,PayPal会根据结算开始日期,结算频率和结算金额自动将付款排队。付款会重复发生,直到配置文件过期,失败的付款太多以致无法继续,或者您取消配置文件”。 Thus, the end date is based on the start date and billing frequency, and number of payments.
因此,结束日期取决于开始日期和开票频率以及付款次数。
In contrast to the above data structure, when you " Create an agreement ", the request returns no calculated information as to the end date. 与上述数据结构相反,当您“ 创建协议 ”时,请求不返回有关结束日期的任何计算信息。 The data you receive as a response looks like:
您收到的作为响应的数据如下所示:
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 ~
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: payment_definition对象:
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.
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.
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: charge_models对象:
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.
[Some portions of the data structure definition are not included here as they do not affect the end date.] [此处不包括数据结构定义的某些部分,因为它们不影响结束日期。
Example response: 响应示例:
{
"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"
}
For this profile the information relevant to determining the end date is: 对于此配置文件,与确定结束日期有关的信息是:
{
"plan": {
"payment_definitions": [
{
"frequency": "Month",
"cycles": "12",
"frequency_interval": "2"
}
],
},
"start_date": "2015-02-19T00:37:04Z"
}
That is the information you receive. 那就是您收到的信息。 You do not get an explicitly stated end date.
您没有明确说明的结束日期。 You have to calculate the end of the payments yourself.
您必须自己计算付款的结束时间。 In the above example, payments would be made 12 times, every other month, starting on 2015-02-19.
在上面的示例中,从2015-02-19开始,每隔一个月要付款12次。 The customer will be billed on the following days:
将在接下来的几天向客户收费:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.