This repository has been archived by the owner on May 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,100 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Copyright 2014 PayPal */ | ||
"use strict"; | ||
|
||
var paypal_api = require('../../../'); | ||
require('../../configure'); | ||
|
||
var billingAgreementId = "I-08413VDRU6DE"; | ||
|
||
var cancel_note = { | ||
"note": "Canceling the agreement" | ||
}; | ||
|
||
paypal_api.billing_agreement.cancel(billingAgreementId, cancel_note, function (error, response) { | ||
if (error) { | ||
console.log(error); | ||
throw error; | ||
} else { | ||
console.log("Cancel Billing Agreement Response"); | ||
console.log(response); | ||
|
||
paypal_api.billing_plan.get(billingAgreementId, function (error, billingPlan) { | ||
if (error) { | ||
console.log(error.response); | ||
throw error; | ||
} else { | ||
console.log(billingPlan.state); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* Copyright 2014 PayPal | ||
Create a billing plan, activate it and use it to create a billing Agreement. | ||
*/ | ||
"use strict"; | ||
|
||
var paypal_api = require('../../../'); | ||
require('../../configure'); | ||
var url = require('url'); | ||
|
||
var billingPlanAttributes = { | ||
"description": "Create Plan for Regular", | ||
"merchant_preferences": { | ||
"auto_bill_amount": "yes", | ||
"cancel_url": "http://www.cancel.com", | ||
"initial_fail_amount_action": "continue", | ||
"max_fail_attempts": "1", | ||
"return_url": "http://www.success.com", | ||
"setup_fee": { | ||
"currency": "USD", | ||
"value": "25" | ||
} | ||
}, | ||
"name": "Testing1-Regular1", | ||
"payment_definitions": [ | ||
{ | ||
"amount": { | ||
"currency": "USD", | ||
"value": "100" | ||
}, | ||
"charge_models": [ | ||
{ | ||
"amount": { | ||
"currency": "USD", | ||
"value": "10.60" | ||
}, | ||
"type": "SHIPPING" | ||
}, | ||
{ | ||
"amount": { | ||
"currency": "USD", | ||
"value": "20" | ||
}, | ||
"type": "TAX" | ||
} | ||
], | ||
"cycles": "0", | ||
"frequency": "MONTH", | ||
"frequency_interval": "1", | ||
"name": "Regular 1", | ||
"type": "REGULAR" | ||
}, | ||
{ | ||
"amount": { | ||
"currency": "USD", | ||
"value": "20" | ||
}, | ||
"charge_models": [ | ||
{ | ||
"amount": { | ||
"currency": "USD", | ||
"value": "10.60" | ||
}, | ||
"type": "SHIPPING" | ||
}, | ||
{ | ||
"amount": { | ||
"currency": "USD", | ||
"value": "20" | ||
}, | ||
"type": "TAX" | ||
} | ||
], | ||
"cycles": "4", | ||
"frequency": "MONTH", | ||
"frequency_interval": "1", | ||
"name": "Trial 1", | ||
"type": "TRIAL" | ||
} | ||
], | ||
"type": "INFINITE" | ||
}; | ||
|
||
var billingPlanUpdateAttributes = [ | ||
{ | ||
"op": "replace", | ||
"path": "/", | ||
"value": { | ||
"state": "ACTIVE" | ||
} | ||
} | ||
]; | ||
|
||
var billingAgreementAttributes = { | ||
"name": "Fast Speed Agreement", | ||
"description": "Agreement for Fast Speed Plan", | ||
"start_date": "2015-02-19T00:37:04Z", | ||
"plan": { | ||
"id": "P-0NJ10521L3680291SOAQIVTQ" | ||
}, | ||
"payer": { | ||
"payment_method": "paypal" | ||
}, | ||
"shipping_address": { | ||
"line1": "StayBr111idge Suites", | ||
"line2": "Cro12ok Street", | ||
"city": "San Jose", | ||
"state": "CA", | ||
"postal_code": "95112", | ||
"country_code": "US" | ||
} | ||
}; | ||
|
||
// Create the billing plan | ||
paypal_api.billing_plan.create(billingPlanAttributes, function (error, billingPlan) { | ||
if (error) { | ||
console.log(error); | ||
throw error; | ||
} else { | ||
console.log("Create Billing Plan Response"); | ||
console.log(billingPlan); | ||
|
||
// Activate the plan by changing status to Active | ||
paypal_api.billing_plan.update(billingPlan.id, billingPlanUpdateAttributes, function (error, response) { | ||
if (error) { | ||
console.log(error); | ||
throw error; | ||
} else { | ||
console.log("Billing Plan state changed to " + billingPlan.state); | ||
billingAgreementAttributes.plan.id = billingPlan.id; | ||
|
||
// Use activated billing plan to create agreement | ||
paypal_api.billing_agreement.create(billingAgreementAttributes, function (error, billingAgreement) { | ||
if (error) { | ||
console.log(error); | ||
throw error; | ||
} else { | ||
console.log("Create Billing Agreement Response"); | ||
//console.log(billingAgreement); | ||
for (var index = 0; index < billingAgreement.links.length; index++) { | ||
if (billingAgreement.links[index].rel === 'approval_url') { | ||
var approval_url = billingAgreement.links[index].href; | ||
console.log("For approving subscription via Paypal, first redirect user to"); | ||
console.log(approval_url); | ||
|
||
console.log("Payment token is"); | ||
console.log(url.parse(approval_url, true).query.token); | ||
// See billing_agreements/execute.js to see example for executing agreement | ||
// after you have payment token | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Copyright 2014 PayPal | ||
Execute a billing agreement after it has been created. See | ||
billing_agreements/create.js to see a sample for creating an | ||
agreement. | ||
*/ | ||
"use strict"; | ||
|
||
var paypal_api = require('../../../'); | ||
require('../../configure'); | ||
|
||
var paymentToken = ''; | ||
|
||
//Retrieve payment token appended as a parameter to the redirect_url specified in | ||
//billing plan was created. It could also be saved in the user session | ||
paymentToken = 'EC-2V0782854X675410W'; | ||
|
||
paypal_api.billing_agreement.execute(paymentToken, {}, function (error, billingAgreement) { | ||
if (error) { | ||
console.log(error); | ||
throw error; | ||
} else { | ||
console.log("Billing Agreement Execute Response"); | ||
console.log(JSON.stringify(billingAgreement)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Copyright 2014 PayPal */ | ||
"use strict"; | ||
|
||
var paypal_api = require('../../../'); | ||
require('../../configure'); | ||
|
||
var billingAgreementId = "I-08413VDRU6DE"; | ||
|
||
paypal_api.billing_agreement.get(billingAgreementId, function (error, billingAgreement) { | ||
if (error) { | ||
console.log(error); | ||
throw error; | ||
} else { | ||
console.log("Get Billing Agreement"); | ||
console.log(JSON.stringify(billingAgreement)); | ||
} | ||
}); |
Oops, something went wrong.