Retrieving buyers billing end period - ruby-on-rails

I browse around PayPal's API and I was not able to find the information I am looking for. 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.

Legal note: This answer is based on my understanding, you should verify anything you have a question on with 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.
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. However, in one, and only one of multiple examples, an additional agreement_details object is shown. 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". Nor are any of the properties anywhere else in the API specification, other than in that one example.
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. 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. 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. 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." 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 ~
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.
[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"
}
Calculating the end date yourself:
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. 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

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 .
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"
}
}

Related

singleValueExtendedProperties not returned for event attendee, only organiser

We have developed an outlook add in that adds a custom property to an event. This is working fine and if I query the MS Graph API as the organiser I can see the custom property returned.
#Query
https://graph.microsoft.com/v1.0/me/events?$expand=singleValueExtendedProperties($filter=id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-f7f0d3d0-21c3-4c6e-91f5-edaee4e32466')
#Response
{
...
"value": [
{
...
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "1601-01-01T00:00:00Z"
},
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV#domain.onmicrosoft.com"
}
}
],
"singleValueExtendedProperties#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('abc1234-b90f-469f-9a92-6eb23af30276')/events('AAMkADlhNzdjZWY2LWVjNjQtNGExNi1iNDZjLTA4M2Q1ZWM3MTMzMgBGAAAAAAAoycA_ZVHiTq8VDwWB362DBwAI-BzSjmJPQJ2LM7A8Gj1OAAAAAAENAAAI-BzSjmJPQJ2LM7A8Gj1OAAC_N5E_AAA%3D')/singleValueExtendedProperties",
"singleValueExtendedProperties": [
{
"id": "String {00020329-0000-0000-c000-000000000046} Name cecp-f7f0d3d0-21c3-4c6e-91f5-edaee4e32466",
"value": "{\"id\":\"ABC\"}"
}
]
}
]
However, if I try and run the same query for an attendee (Adele Vance) then I don't get the singleValueExtendedProperties returned.
Are the extended properties only available to the user who added them? I can see the metadata includes my user Id, however this seems very limiting.
Any help much appreciated.
Iain
Yes, the attendee appointment is created by the organizer sending a meeting invitation. The invitation does not include any custom properties.

How to pay to a customer using quickbooks API?

The QuickBooks API provides an API (https://developer.intuit.com/docs/api/payments/charges) to accept payments from a customer using a credit card. But how can we pay back a customer? Is there any payment API where I can send money to my customer? Is it possible?
--New Edit--
Example scenario: I have 2 layers of customers, level one customers have to receive payments from level2 customers. The process goes like this, level2 customers will pay me and I will transfer to the level1 customer. Of course, I will take a small commission amount. The refund will not help here ??? I am looking for something like payout (is payout available ???)
QuickBooks Payments does not support pay-outs. If you're looking for payouts, look elsewhere.
You can issue a REFUND with the Refund a charge endpoint:
https://developer.intuit.com/docs/api/payments/charges
e.g.:
POST /quickbooks/v4/payments/charges/<id>/refunds
Content type: application/json
{
"id": "",
"created": "",
"amount": 5.00,
"context": {
"tax": 0,
"deviceInfo": {
"id": "",
"type": "",
"longitude": "",
"latitude": "",
"phoneNumber": "",
"macAddress": "",
"ipAddress": ""
},
"recurring": false
},
"description": "first refund"
}
Which returns something like:
{
"created": "2014-09-23T01:49:12Z",
"amount": "5.00",
"description": "first refund",
"id": "EMU891209421",
"context": {
"tax": "0.00",
"recurring": false,
"deviceInfo": {
"id": "",
"type": "",
"longitude": "",
"latitude": "",
"phoneNumber": "",
"macAddress": "",
"ipAddress": ""
}
}
}
You can't just send random dollar amounts to customers. (They wouldn't be "customers" if you were just sending them money -- the definition of a "customer" is someone you are taking money FROM, not giving money TO.)

FHIR medication

I have a data model for medications like this:
Drug name
Prescription Date
Preparation
Dose
Quantity
for example:
Bendroflumethiazide (Bendrofluazide), 05/12/2015, TABS 2.5MG,1 Tab,56
I had a look at the medication resource but I am unable to map it. Can anyone help me with this mapping?
Thanks.
Firstly I wanted to ask more details but I couldn't comment on your question because of stackverflow reputation system.
In FHIR, the Medication domain includes a number of related resources, they are;
MedicationOrder
MedicationDispense
MedicationAdministration
MedicationStatement
#brillox also refenced this but I will point this again Resource Medication - Content This source is like Master File Notification (MFN for HL7 v2)
Please check examples to see drug names. I also gave one example below.
For Medication Administration please check examples and descriptions, you will find all details you need. Resource MedicationAdministration - Detailed Descriptions
An example for compounded medication;
{
"resourceType": "Medication",
"id": "medexample008",
"text": {
"fhir_comments": [
" this example includes a compounded medication "
],
"status": "generated",
"div": "<div>Hydrocortisone 1%, Salicyclic Acid 5% in Glaxal Base</div>"
},
"code": {
"text": "Hydrocortisone 1%, Salicyclic Acid 5% in Glaxal Base"
},
"isBrand": false,
"product": {
"form": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "255621006",
"display": "Cream"
}
]
},
"ingredient": [
{
"item": {
"display": "Hydrocortisone Powder"
},
"amount": {
"numerator": {
"value": 1,
"system": "http://unitsofmeasure.org",
"code": "g"
},
"denominator": {
"value": 100,
"system": "http://unitsofmeasure.org",
"code": "g"
}
}
},
{
"item": {
"display": "Salicyclic Acid"
},
"amount": {
"numerator": {
"value": 5,
"system": "http://unitsofmeasure.org",
"code": "g"
},
"denominator": {
"value": 100,
"system": "http://unitsofmeasure.org",
"code": "g"
}
}
},
{
"item": {
"display": "Glaxal Base"
},
"amount": {
"numerator": {
"value": 94,
"system": "http://unitsofmeasure.org",
"code": "g"
},
"denominator": {
"value": 100,
"system": "http://unitsofmeasure.org",
"code": "g"
}
}
}
]
}
}
What is your data representing? I assume medication prescriptions by a physician.
You should look at the Medicationorder ressource:
https://www.hl7.org/fhir/medicationorder.html
There are many examples of doing it on the FHIR Homepage, like this one:
https://www.hl7.org/fhir/medicationorder-example-f001-combivent.xml.html
In the medication order resource you are then link to your actual Medication resource: https://www.hl7.org/fhir/medication.html
If you have medications from different prescribers or different start/end dates, just use one medication order per prescription.

Can a json response can be partially paginate?

I'm wondering if a json can be partially paginate.
For example
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever."
}
}],
"included": [
{
"type": "people",
"id": 42,
"attributes": {
"name": "John"
}
},
{
...annnd 80000 others
}
}
]
}
Where included have soo many elements (80.000 for examples) than maybe we need pagination?
But if it's paginate and we go on the next page only included elements will change, the json will still return the data.articles.
Is it a correct behavior ?
First proposal :
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever."
},
"relationships": {
"users": {
"link": "https://website.com/api/v1/articles/1/users.json"
}
}
}]
}
To be compliant with the JSON API spec, your compound document must obey the full linkage requirement. Any included resources MUST be identified via relationship data.
In your example, you could fulfill this by adding a data member under the users relationship. You could then link to every included person.
If the relationship data is a partial set, you can use pagination links within the relationship object.

Extended Choice Parameter plugin Multi-Level Select

OK, so I downloaded this plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin
And select Multi-Level Single Select as the type of parameters.
The problem is that when I have multiple parameters selected and I want to use these parameters in shell in a build, I can only select the LAST parameter
So if I do $PARAM_NAME it only outputs the last parameters, but I want all the parameters that I selected, not just the last one.
Here is a picture for demonstration
You aren't building the parameter based on the selections, you are navigating to the value that you want. I.E. Country --->State ---->City
You aren't building a CountryStateCity variable, you are stating that the City variable is the value you select.
I could get the nearest to this by using Extended Choice Parameter > JSON Parameter Type > JSON Parameter Config Groovy Script.
import org.boon.Boon;
def jsonEditorOptions = Boon.fromJson(/{
disable_edit_json: true,
disable_properties: true,
no_additional_properties: true,
disable_collapse: true,
disable_array_add: false,
disable_array_delete: false,
disable_array_reorder: false,
theme: "bootstrap3",
iconlib: "fontawesome5",
schema: {
"type": "object",
"title": "",
"required": [
"Locations"
],
"properties": {
"Locations": {
"type": "array",
"format": "table",
"title": "",
"uniqueItems": true,
"items": {
"type": "object",
"title": "Location",
"properties": {
"Country": {
"type": "string",
"propertyOrder" : 1,
"enum": [
"USA",
"Germany",
"India"
]
},
"City": {
"type": "string",
"propertyOrder" : 2,
"enum": [
"New York",
"Frankfurt",
"Mumbai"
]
},
"Neighborhood": {
"type": "string",
"propertyOrder" : 3
}
}
},
"default": [{
"Country": "USA",
"City": "New York",
"Neighborhood": "Times Square"
}]
}
}
}
/);
You can visit the plugin page and json-editor.github.io to create and validate your
JSON schemas as seen above.
This is how it appears in Jenkins:
Note that however, it still does not provide a context sensitive
second column based on what is selected in the first column. The
second column rather behaves exactly like the first column where you
select from a pre-defined list without any filters.
On printing the variable Location, it returns this JSON:
{"Locations":[{"City":"New York","Country":"USA","Neighborhood":"Times Square"},{"City":"Frankfurt","Country":"Germany","Neighborhood":"Bornheim"},{"City":"Mumbai","Country":"India","Neighborhood":"Vile Parle"}]}
I met the same problem, so I added a 'row number' column to the parameters file:
Country City Row
United States San Francisco 1
United States Chicago 2
Mexico Mexico City 3
Mexico Cancun 4
This way, the plugin returns the row number and I can address that row from the parameters file.

Resources