diff --git a/README.md b/README.md index 9a1e3f69..babfb084 100644 --- a/README.md +++ b/README.md @@ -86,12 +86,14 @@ To write an app using the SDK // Logout url paypal_sdk.openid_connect.logout_url("Replace with tokeninfo.id_token"); ``` + * For creating [Subscription Payments](https://developer.paypal.com/docs/integration/direct/create-billing-plan/), check out the [samples](/samples/subscription) for creating planned sets of future recurring payments at periodic intervals. + * To create [Future Payments](https://developer.paypal.com/docs/integration/mobile/make-future-payment/), check out this [sample](/samples/payment/create_future_payment.js) for executing future payments for a customer who has granted consent on a mobile device. * For [Invoicing](https://developer.paypal.com/webapps/developer/docs/api/#invoicing), check out the [samples](/samples/invoice/) to see how you can use the node sdk to create, send and manage invoices. ## Running Samples -Instructions for running samples are located in the [sample directory] (https://github.com/Runnable/rest-api-sdk-nodejs/tree/master/samples). Try these samples in a live sandbox environment: +Instructions for running samples are located in the [sample directory](https://github.com/Runnable/rest-api-sdk-nodejs/tree/master/samples). Try these samples in a live sandbox environment: diff --git a/lib/paypal-rest-sdk.js b/lib/paypal-rest-sdk.js index 651da956..88e400c7 100644 --- a/lib/paypal-rest-sdk.js +++ b/lib/paypal-rest-sdk.js @@ -8,7 +8,7 @@ var uuid = require('node-uuid'); module.exports = function () { - var sdk_version = '0.9.3'; + var sdk_version = '0.10.0'; var user_agent = 'PayPalSDK/rest-sdk-nodejs ' + sdk_version + ' (node ' + process.version + '-' + process.arch + '-' + process.platform + ')'; var default_options = { 'mode': 'sandbox', @@ -73,7 +73,9 @@ module.exports = function () { } function configure(options) { - default_options = merge(default_options, options); + if (options !== undefined && typeof options === 'object') { + default_options = merge(default_options, options); + } } function generate_token(config, cb) { @@ -235,13 +237,18 @@ module.exports = function () { res.on('end', function () { var err = null; - response.httpStatusCode = res.statusCode; - try { - + //Set response to be parsed JSON object if data received is json + //expect that content-type header has application/json when it + //returns data if (res.headers['content-type'] === "application/json") { response = JSON.parse(response); } + //Set response to an empty object if no data was received + if (response === '') { + response = {}; + } + response.httpStatusCode = res.statusCode; //TURN NODE_ENV to development to get access to paypal-debug-id //for questions to merchant technical services. Similar convention @@ -249,7 +256,6 @@ module.exports = function () { if (res.headers['paypal-debug-id'] !== undefined && process.env.NODE_ENV === 'development') { console.log(res.headers['paypal-debug-id']); } - } catch (e) { err = new Error('Invalid JSON Response Received'); err.error = { @@ -385,6 +391,7 @@ module.exports = function () { configure: function (options) { configure(options); }, + configuration: default_options, generate_token: function (config, cb) { generate_token(config, cb); }, @@ -396,6 +403,10 @@ module.exports = function () { executeHttp('GET', '/v1/payments/payment/' + payment_id, {}, config, cb); }, list: function (data, config, cb) { + if (typeof data === 'function') { + config = data; + data = {}; + } executeHttp('GET', '/v1/payments/payment', data, config, cb); }, execute: function (payment_id, data, config, cb) { @@ -437,6 +448,60 @@ module.exports = function () { executeHttp('GET', '/v1/payments/capture/' + capture_id, {}, config, cb); } }, + billing_plan: { + create: function (data, config, cb) { + executeHttp('POST', '/v1/payments/billing-plans/', data, config, cb); + }, + get: function (plan_id, config, cb) { + executeHttp('GET', '/v1/payments/billing-plans/' + plan_id, {}, config, cb); + }, + list: function (data, config, cb) { + if (typeof data === 'function') { + config = data; + data = {}; + } + executeHttp('GET', '/v1/payments/billing-plans', data, config, cb); + }, + update: function (plan_id, data, config, cb) { + executeHttp('PATCH', '/v1/payments/billing-plans/' + plan_id, data, config, cb); + } + }, + billing_agreement: { + create: function (data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements', data, config, cb); + }, + get: function (agreement_id, config, cb) { + executeHttp('GET', '/v1/payments/billing-agreements/' + agreement_id, {}, config, cb); + }, + update: function (agreement_id, data, config, cb) { + executeHttp('PATCH', '/v1/payments/billing-agreements/' + agreement_id, data, config, cb); + }, + execute: function (payment_token, data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements/' + payment_token + '/agreement-execute', data, config, cb); + }, + suspend: function (agreement_id, data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements/' + agreement_id + '/suspend', data, config, cb); + }, + cancel: function (agreement_id, data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements/' + agreement_id + '/cancel', data, config, cb); + }, + reactivate: function (agreement_id, data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements/' + agreement_id + '/re-activate', data, config, cb); + }, + bill_balance: function (agreement_id, data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements/' + agreement_id + '/bill-balance', data, config, cb); + }, + set_balance: function (agreement_id, data, config, cb) { + executeHttp('POST', '/v1/payments/billing-agreements/' + agreement_id + '/set-balance', data, config, cb); + }, + search_transactions: function (agreement_id, start_date, end_date, config, cb) { + var date_range = { + "start-date": start_date, + "end-date": end_date + }; + executeHttp('GET', '/v1/payments/billing-agreements/' + agreement_id + '/transaction', date_range, config, cb); + } + }, credit_card: { create: function (data, config, cb) { executeHttp('POST', '/v1/vault/credit-card/', data, config, cb); diff --git a/package.json b/package.json index dde2b5b5..b8f17782 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "PayPal (https://developer.paypal.com/)", "name": "paypal-rest-sdk", "description": "SDK for PayPal REST APIs", - "version": "0.9.3", + "version": "0.10.0", "homepage": "https://github.com/paypal/rest-api-sdk-nodejs", "keywords": [ "paypal", diff --git a/samples/subscription/billing_agreements/cancel.js b/samples/subscription/billing_agreements/cancel.js new file mode 100644 index 00000000..58947302 --- /dev/null +++ b/samples/subscription/billing_agreements/cancel.js @@ -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); + } + }); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_agreements/create.js b/samples/subscription/billing_agreements/create.js new file mode 100644 index 00000000..409ca157 --- /dev/null +++ b/samples/subscription/billing_agreements/create.js @@ -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 + } + } + } + }); + } + }); + } +}); + + diff --git a/samples/subscription/billing_agreements/execute.js b/samples/subscription/billing_agreements/execute.js new file mode 100644 index 00000000..35601ddc --- /dev/null +++ b/samples/subscription/billing_agreements/execute.js @@ -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)); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_agreements/get.js b/samples/subscription/billing_agreements/get.js new file mode 100644 index 00000000..06cacabb --- /dev/null +++ b/samples/subscription/billing_agreements/get.js @@ -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)); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_agreements/search_transactions.js b/samples/subscription/billing_agreements/search_transactions.js new file mode 100644 index 00000000..f87c03a3 --- /dev/null +++ b/samples/subscription/billing_agreements/search_transactions.js @@ -0,0 +1,21 @@ +/* Copyright 2014 PayPal */ +"use strict"; + +var paypal_api = require('../../../'); +require('../../configure'); + +var billingAgreementId = "I-08413VDRU6DE"; + +var start_date = "2014-07-01"; +var end_date = "2014-07-20"; + +paypal_api.billing_agreement.search_transactions(billingAgreementId, start_date, end_date, function (error, results) { + if (error) { + console.log(error); + throw error; + } else { + console.log("Billing Agreement Transactions Search Response"); + console.log(results); + } +}); + diff --git a/samples/subscription/billing_agreements/set_balance_and_bill_balance.js b/samples/subscription/billing_agreements/set_balance_and_bill_balance.js new file mode 100644 index 00000000..9fa9954b --- /dev/null +++ b/samples/subscription/billing_agreements/set_balance_and_bill_balance.js @@ -0,0 +1,37 @@ +/* Copyright 2014 PayPal */ +"use strict"; + +var paypal_api = require('../../../'); +require('../../configure'); + +var billingAgreementId = "I-THNVHK6X9H0V"; + +var outstanding_amount = { + "value" : "10", + "currency" : "USD" +}; + +paypal_api.billing_agreement.set_balance(billingAgreementId, outstanding_amount, function (error, response) { + if (error) { + console.log(error); + throw error; + } else { + console.log("Billing Agreement Set Balance Response"); + console.log(response); + + var outstanding_amount_note = { + "note": "Billing Balance Amount", + "amount": outstanding_amount + }; + + paypal_api.billing_agreement.bill_balance(billingAgreementId, outstanding_amount_note, function (error, response) { + if (error) { + console.log(error); + throw error; + } else { + console.log("Billing Agreement Bill Balance Response"); + console.log(response); + } + }); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_agreements/suspend_and_re_activate.js b/samples/subscription/billing_agreements/suspend_and_re_activate.js new file mode 100644 index 00000000..3708be67 --- /dev/null +++ b/samples/subscription/billing_agreements/suspend_and_re_activate.js @@ -0,0 +1,35 @@ +/* Copyright 2014 PayPal */ +"use strict"; + +var paypal_api = require('../../../'); +require('../../configure'); + +var billingAgreementId = "I-08413VDRU6DE"; + +var suspend_note = { + "note": "Suspending the agreement" +}; + +paypal_api.billing_agreement.suspend(billingAgreementId, suspend_note, function (error, response) { + if (error) { + console.log(error); + throw error; + } else { + console.log("Suspend Billing Agreement Response"); + console.log(response); + + var reactivate_note = { + "note": "Reactivating the agreement" + }; + + paypal_api.billing_agreement.reactivate(billingAgreementId, reactivate_note, function (error, response) { + if (error) { + console.log(error); + throw error; + } else { + console.log("Reactivate Billing Agreement Response"); + console.log(response); + } + }); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_agreements/update.js b/samples/subscription/billing_agreements/update.js new file mode 100644 index 00000000..a0c9e5bc --- /dev/null +++ b/samples/subscription/billing_agreements/update.js @@ -0,0 +1,45 @@ +/* Copyright 2014 PayPal */ +"use strict"; + +var paypal_api = require('../../../'); +require('../../configure'); + +var billingAgreementId = "I-08413VDRU6DE"; + +var billing_agreement_update_attributes = [ + { + "op": "replace", + "path": "/", + "value": { + "description": "Newer Description", + "name": "New Name", + "shipping_address": { + "line1": "StayBr111idge Suites", + "line2": "Cro12ok Street", + "city": "San Jose", + "state": "CA", + "postal_code": "95112", + "country_code": "US" + } + } + } +]; + +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)); + + paypal_api.billing_agreement.update(billingAgreementId, billing_agreement_update_attributes, function (error, response) { + if (error) { + console.log(error); + throw error; + } else { + console.log(response); + } + }); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_plans/create.js b/samples/subscription/billing_plans/create.js index ba8975c1..0361e40a 100644 --- a/samples/subscription/billing_plans/create.js +++ b/samples/subscription/billing_plans/create.js @@ -1,53 +1,80 @@ -/* Copyright 2013 PayPal */ +/* Copyright 2014 PayPal */ "use strict"; var paypal_api = require('../../../'); require('../../configure'); var billingPlanAttributes = { - "name": "Fast Speed Plan", - "description": "Template creation.", - "type": "fixed", + "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": [ { - "name": "Payment Definition-1", - "type": "REGULAR", + "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": "2", + "frequency_interval": "1", + "name": "Regular 1", + "type": "REGULAR" + }, + { "amount": { - "value": "100", - "currency": "USD" + "currency": "USD", + "value": "20" }, - "cycles": "12", "charge_models": [ { - "type": "SHIPPING", "amount": { - "value": "10", - "currency": "USD" - } + "currency": "USD", + "value": "10.60" + }, + "type": "SHIPPING" }, { - "type": "TAX", "amount": { - "value": "12", - "currency": "USD" - } + "currency": "USD", + "value": "20" + }, + "type": "TAX" } - ] + ], + "cycles": "4", + "frequency": "MONTH", + "frequency_interval": "1", + "name": "Trial 1", + "type": "TRIAL" } ], - "merchant_preferences": { - "setup_fee": { - "value": "1", - "currency": "USD" - }, - "return_url": "http://www.paypal.com", - "cancel_url": "http://www.yahoo.com", - "autobill_amount": "YES", - "initial_amount_fail_action": "CONTINUE", - "max_fail_attempts": "0" - } + "type": "INFINITE" }; paypal_api.billing_plan.create(billingPlanAttributes, function (error, billingPlan) { diff --git a/samples/subscription/billing_plans/get.js b/samples/subscription/billing_plans/get.js index 0b547859..e9b870cf 100644 --- a/samples/subscription/billing_plans/get.js +++ b/samples/subscription/billing_plans/get.js @@ -1,10 +1,10 @@ -/* Copyright 2013 PayPal */ +/* Copyright 2014 PayPal */ "use strict"; var paypal_api = require('../../../'); require('../../configure'); -var billingPlanId = "P-0NJ10521L3680291SOAQIVTQ"; +var billingPlanId = "P-6KX77264SV996415P6K4MZZY"; paypal_api.billing_plan.get(billingPlanId, function (error, billingPlan) { if (error) { diff --git a/samples/subscription/billing_plans/list.js b/samples/subscription/billing_plans/list.js new file mode 100644 index 00000000..8b202ff1 --- /dev/null +++ b/samples/subscription/billing_plans/list.js @@ -0,0 +1,18 @@ +/* Copyright 2014 PayPal */ +"use strict"; + +var paypal_api = require('../../../'); +require('../../configure'); + +var list_billing_plan = { + 'status': 'ACTIVE' +}; + +paypal_api.billing_plan.list(function (error, billingPlan) { + if (error) { + throw error; + } else { + console.log("List Billing Plans Response"); + console.log(JSON.stringify(billingPlan)); + } +}); \ No newline at end of file diff --git a/samples/subscription/billing_plans/update.js b/samples/subscription/billing_plans/update.js new file mode 100644 index 00000000..224b244d --- /dev/null +++ b/samples/subscription/billing_plans/update.js @@ -0,0 +1,43 @@ +/* Copyright 2014 PayPal */ +"use strict"; + +var paypal_api = require('../../../'); +require('../../configure'); + +var billingPlanId = "P-81N60167551920806A4TNCYQ"; + +var billing_plan_update_attributes = [ + { + "op": "replace", + "path": "/", + "value": { + "state": "ACTIVE" + } + } +]; + +paypal_api.billing_plan.get(billingPlanId, function (error, billingPlan) { + if (error) { + console.log(error); + throw error; + } else { + console.log("Get Billing Plan"); + console.log(JSON.stringify(billingPlan)); + + paypal_api.billing_plan.update(billingPlanId, billing_plan_update_attributes, function (error, response) { + if (error) { + console.log(error.response); + throw error; + } else { + paypal_api.billing_plan.get(billingPlanId, function (error, billingPlan) { + if (error) { + console.log(error.response); + throw error; + } else { + console.log(billingPlan.state); + } + }); + } + }); + } +}); \ No newline at end of file diff --git a/test/configure-test.js b/test/configure-test.js new file mode 100644 index 00000000..03915365 --- /dev/null +++ b/test/configure-test.js @@ -0,0 +1,15 @@ +"use strict"; + +var chai = require('chai'), + expect = chai.expect, + should = chai.should(); + +var paypal_sdk = require('../'); +require('./configure'); + +describe('Configure Test', function () { + it('Should return default options', function () { + var config = paypal_sdk.configuration; + config.should.be.a('object'); + }); +}); diff --git a/test/invoice.js b/test/invoice.js index 2e65ee61..4cebf322 100644 --- a/test/invoice.js +++ b/test/invoice.js @@ -169,7 +169,7 @@ describe('SDK', function () { paypal_sdk.invoice.cancel(invoice.id, cancel_attr, function (error, rv) { expect(error).equal(null); - expect(rv).equal(''); + expect(rv.httpStatusCode).equal(204); var quantity_new = 500; var amount_new = "2500.00"; @@ -242,7 +242,7 @@ describe('SDK', function () { paypal_sdk.invoice.remind(invoice.id, remind_attr, function (error, rv) { expect(error).equal(null); - expect(rv).equal(''); + expect(rv.httpStatusCode).equal(202); done(); }); }); @@ -281,7 +281,7 @@ describe('SDK', function () { paypal_sdk.invoice.cancel(invoice.id, cancel_attr, function (error, rv) { expect(error).equal(null); - expect(rv).equal(''); + expect(rv.httpStatusCode).equal(204); paypal_sdk.invoice.get(invoice.id, function (error, invoice) { expect(error).equal(null); @@ -317,7 +317,7 @@ describe('SDK', function () { paypal_sdk.invoice.delete(invoice.id, function (error, rv) { expect(error).equal(null); - expect(rv).equal(''); + expect(rv.httpStatusCode).equal(204); paypal_sdk.invoice.get(invoice.id, function (error, invoice) { expect(error.response.message).equal("Resource is already deleted."); diff --git a/test/mocks/payment.js b/test/mocks/payment.js index b8847e00..e4e160e3 100644 --- a/test/mocks/payment.js +++ b/test/mocks/payment.js @@ -1,6 +1,6 @@ var nock = require('nock'); -nock('https://api.sandbox.paypal.com:443:443') +nock('https://api.sandbox.paypal.com') .post('/v1/oauth2/token', "grant_type=client_credentials") .reply(200, "{\"scope\":\"https://uri.paypal.com/services/invoicing openid https://api.paypal.com/v1/developer/.* https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/vault/credit-card\",\"access_token\":\"ukzk9kqlwF2IbFBjsCwsayTZYkTRGz2UTn46ucY1l2Q\",\"token_type\":\"Bearer\",\"app_id\":\"APP-2EJ531395M785864S\",\"expires_in\":28800}", { server: 'Apache-Coyote/1.1', proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=1305', @@ -11,7 +11,7 @@ nock('https://api.sandbox.paypal.com:443:443') 'content-type': 'application/json', 'transfer-encoding': 'chunked' }); -nock('https://api.sandbox.paypal.com:443:443') +nock('https://api.sandbox.paypal.com') .post('/v1/payments/payment/', {"intent":"sale","payer":{"payment_method":"credit_card","funding_instruments":[{"credit_card":{"type":"visa","number":"4417119669820331","expire_month":"11","expire_year":"2018","cvv2":"874"}}]},"transactions":[{"amount":{"total":"7","currency":"USD","details":{"subtotal":"5","tax":"1","shipping":"1"}},"description":"This is the payment transaction descriptiön."}]}) .reply(201, "{\"id\":\"PAY-3YT781515K9510419KNL4FMA\",\"create_time\":\"2014-04-23T13:40:00Z\",\"update_time\":\"2014-04-23T13:40:16Z\",\"state\":\"approved\",\"intent\":\"sale\",\"payer\":{\"payment_method\":\"credit_card\",\"funding_instruments\":[{\"credit_card\":{\"type\":\"visa\",\"number\":\"xxxxxxxxxxxx0331\",\"expire_month\":\"11\",\"expire_year\":\"2018\"}}]},\"transactions\":[{\"amount\":{\"total\":\"7.00\",\"currency\":\"USD\",\"details\":{\"subtotal\":\"5.00\",\"tax\":\"1.00\",\"shipping\":\"1.00\"}},\"description\":\"This is the payment transaction descriptiön.\",\"related_resources\":[{\"sale\":{\"id\":\"7PR173990Y544840C\",\"create_time\":\"2014-04-23T13:40:00Z\",\"update_time\":\"2014-04-23T13:40:16Z\",\"state\":\"completed\",\"amount\":{\"total\":\"7.00\",\"currency\":\"USD\"},\"parent_payment\":\"PAY-3YT781515K9510419KNL4FMA\",\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7PR173990Y544840C\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7PR173990Y544840C/refund\",\"rel\":\"refund\",\"method\":\"POST\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA\",\"rel\":\"parent_payment\",\"method\":\"GET\"}]}}]}],\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA\",\"rel\":\"self\",\"method\":\"GET\"}]}", { server: 'Apache-Coyote/1.1', proxy_server_info: 'host=slcsbjava1.slc.paypal.com;threadId=961', @@ -23,7 +23,7 @@ nock('https://api.sandbox.paypal.com:443:443') 'content-type': 'application/json', 'transfer-encoding': 'chunked' }); -nock('https://api.sandbox.paypal.com:443:443') +nock('https://api.sandbox.paypal.com') .get('/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA') .reply(200, "{\"id\":\"PAY-3YT781515K9510419KNL4FMA\",\"create_time\":\"2014-04-23T13:40:00Z\",\"update_time\":\"2014-04-23T13:40:16Z\",\"state\":\"approved\",\"intent\":\"sale\",\"payer\":{\"payment_method\":\"credit_card\",\"funding_instruments\":[{\"credit_card\":{\"type\":\"visa\",\"number\":\"xxxxxxxxxxxx0331\",\"expire_month\":\"11\",\"expire_year\":\"2018\"}}]},\"transactions\":[{\"amount\":{\"total\":\"7.00\",\"currency\":\"USD\",\"details\":{\"subtotal\":\"5.00\",\"tax\":\"1.00\",\"shipping\":\"1.00\"}},\"description\":\"This is the payment transaction descriptiön.\",\"related_resources\":[{\"sale\":{\"id\":\"7PR173990Y544840C\",\"create_time\":\"2014-04-23T13:40:00Z\",\"update_time\":\"2014-04-23T13:40:16Z\",\"state\":\"completed\",\"amount\":{\"total\":\"7.00\",\"currency\":\"USD\"},\"parent_payment\":\"PAY-3YT781515K9510419KNL4FMA\",\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7PR173990Y544840C\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7PR173990Y544840C/refund\",\"rel\":\"refund\",\"method\":\"POST\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA\",\"rel\":\"parent_payment\",\"method\":\"GET\"}]}}]}],\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA\",\"rel\":\"self\",\"method\":\"GET\"}]}", { server: 'Apache-Coyote/1.1', proxy_server_info: 'host=slcsbjava4.slc.paypal.com;threadId=21386', @@ -35,7 +35,7 @@ nock('https://api.sandbox.paypal.com:443:443') 'content-type': 'application/json', 'transfer-encoding': 'chunked' }); -nock('https://api.sandbox.paypal.com:443:443') +nock('https://api.sandbox.paypal.com') .get('/v1/payments/payment?count=2') .reply(200, "{\"payments\":[{\"id\":\"PAY-3YT781515K9510419KNL4FMA\",\"create_time\":\"2014-04-23T13:40:00Z\",\"update_time\":\"2014-04-23T13:40:16Z\",\"state\":\"approved\",\"intent\":\"sale\",\"payer\":{\"payment_method\":\"credit_card\",\"funding_instruments\":[{\"credit_card\":{\"type\":\"visa\",\"number\":\"xxxxxxxxxxxx0331\",\"expire_month\":\"11\",\"expire_year\":\"2018\"}}]},\"transactions\":[{\"amount\":{\"total\":\"7.00\",\"currency\":\"USD\",\"details\":{\"subtotal\":\"5.00\",\"tax\":\"1.00\",\"shipping\":\"1.00\"}},\"description\":\"This is the payment transaction descriptiön.\",\"related_resources\":[{\"sale\":{\"id\":\"7PR173990Y544840C\",\"create_time\":\"2014-04-23T13:40:00Z\",\"update_time\":\"2014-04-23T13:40:16Z\",\"state\":\"completed\",\"amount\":{\"total\":\"7.00\",\"currency\":\"USD\"},\"parent_payment\":\"PAY-3YT781515K9510419KNL4FMA\",\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7PR173990Y544840C\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/7PR173990Y544840C/refund\",\"rel\":\"refund\",\"method\":\"POST\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA\",\"rel\":\"parent_payment\",\"method\":\"GET\"}]}}]}],\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-3YT781515K9510419KNL4FMA\",\"rel\":\"self\",\"method\":\"GET\"}]},{\"id\":\"PAY-6RR68218JA5804912KNL4E2Y\",\"create_time\":\"2014-04-23T13:38:51Z\",\"update_time\":\"2014-04-23T13:39:10Z\",\"state\":\"approved\",\"intent\":\"sale\",\"payer\":{\"payment_method\":\"credit_card\",\"funding_instruments\":[{\"credit_card\":{\"type\":\"visa\",\"number\":\"xxxxxxxxxxxx0331\",\"expire_month\":\"11\",\"expire_year\":\"2018\"}}]},\"transactions\":[{\"amount\":{\"total\":\"7.47\",\"currency\":\"USD\",\"details\":{\"subtotal\":\"7.41\",\"tax\":\"0.03\",\"shipping\":\"0.03\"}},\"description\":\"This is the payment transaction description.\",\"related_resources\":[{\"sale\":{\"id\":\"0RV9732723904663W\",\"create_time\":\"2014-04-23T13:38:51Z\",\"update_time\":\"2014-04-23T13:39:10Z\",\"state\":\"refunded\",\"amount\":{\"total\":\"7.47\",\"currency\":\"USD\"},\"parent_payment\":\"PAY-6RR68218JA5804912KNL4E2Y\",\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/0RV9732723904663W\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/0RV9732723904663W/refund\",\"rel\":\"refund\",\"method\":\"POST\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RR68218JA5804912KNL4E2Y\",\"rel\":\"parent_payment\",\"method\":\"GET\"}]}},{\"refund\":{\"id\":\"64D48016E7728451R\",\"create_time\":\"2014-04-23T13:39:10Z\",\"update_time\":\"2014-04-23T13:39:10Z\",\"state\":\"completed\",\"amount\":{\"total\":\"7.47\",\"currency\":\"USD\"},\"sale_id\":\"0RV9732723904663W\",\"parent_payment\":\"PAY-6RR68218JA5804912KNL4E2Y\",\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/refund/64D48016E7728451R\",\"rel\":\"self\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RR68218JA5804912KNL4E2Y\",\"rel\":\"parent_payment\",\"method\":\"GET\"},{\"href\":\"https://api.sandbox.paypal.com/v1/payments/sale/0RV9732723904663W\",\"rel\":\"sale\",\"method\":\"GET\"}]}}]}],\"links\":[{\"href\":\"https://api.sandbox.paypal.com/v1/payments/payment/PAY-6RR68218JA5804912KNL4E2Y\",\"rel\":\"self\",\"method\":\"GET\"}]}],\"count\":2,\"next_id\":\"PAY-2LA223779R6625639KNL4EWI\"}", { server: 'Apache-Coyote/1.1', proxy_server_info: 'host=slcsbjava1.slc.paypal.com;threadId=960', diff --git a/test/mocks/subscription.js b/test/mocks/subscription.js new file mode 100644 index 00000000..8ea882c8 --- /dev/null +++ b/test/mocks/subscription.js @@ -0,0 +1,306 @@ +var nock = require('nock'); + +nock('https://api.sandbox.paypal.com') + .post('/v1/oauth2/token', "grant_type=client_credentials") + .reply(200, {"scope":"openid https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/vault/credit-card","access_token":"A015FCC322yoZ8Rjb74XpLS7wgWCkPpBZ0fiA9suvclx6kE","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":28800}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=127', + 'paypal-debug-id': '4f9c1f2c0d206', + server_info: 'identitysecuretokenserv:v1.oauth2.token&CalThreadId=126527&TopLevelTxnStartTime=1472080abf4&Host=slcsbidensectoken502.slc.paypal.com&pid=29059', + date: 'Thu, 10 Jul 2014 13:40:09 GMT', + 'content-type': 'application/json', + 'content-length': '374' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-plans/', {"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"}) + .reply(201, {"id":"P-12U98928TT9129128ECALAJY","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-3EC60609HF4313133ECALAJY","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-3WR87858RT4036731ECALAJY","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-7XR090190M4848722ECALAJY","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-8NT01713C33262114ECALAJY","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-0XR31434AS9044537ECALAJY","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-30159882YH277305AECALAJY","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:10.407Z","update_time":"2014-07-10T13:40:10.407Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-12U98928TT9129128ECALAJY","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=127', + 'paypal-debug-id': '8bb21ab20d65b', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=23732&TopLevelTxnStartTime=1472080b01b&Host=slcsbjm2.slc.paypal.com&pid=31339', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:09 GMT', + 'content-type': 'application/json', + 'content-length': '1415' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-plans/P-12U98928TT9129128ECALAJY') + .reply(200, {"id":"P-12U98928TT9129128ECALAJY","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-3EC60609HF4313133ECALAJY","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-7XR090190M4848722ECALAJY","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-3WR87858RT4036731ECALAJY","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-8NT01713C33262114ECALAJY","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-30159882YH277305AECALAJY","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-0XR31434AS9044537ECALAJY","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:10.407Z","update_time":"2014-07-10T13:40:10.407Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-12U98928TT9129128ECALAJY","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=298', + 'paypal-debug-id': '30395cb803536', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=21897&TopLevelTxnStartTime=1472080b197&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:10 GMT', + 'content-type': 'application/json', + 'content-length': '1415' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-plans/ABRACADABRA') + .reply(404, {"name":"TEMPLATE_ID_INVALID","details":[{"field":"template id is invalid","issue":"Incorrect Template Id."}],"message":"","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#TEMPLATE_ID_INVALID","debug_id":"64084bed036a4"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=300', + 'paypal-debug-id': '64084bed036a4', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=80830&TopLevelTxnStartTime=1472080b2cb&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:10 GMT', + 'content-type': 'application/json', + 'content-length': '248' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-plans') + .reply(200, {"plans":[{"id":"P-56K14732FM7771214EBTVYEI","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:12:30.481Z","update_time":"2014-07-10T13:12:30.775Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-56K14732FM7771214EBTVYEI","rel":"self","method":"GET"}]},{"id":"P-15J12908FF236313XEBTVINI","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:12:28.469Z","update_time":"2014-07-10T13:12:28.469Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-15J12908FF236313XEBTVINI","rel":"self","method":"GET"}]},{"id":"P-87R70106FP259230TEBTNNYY","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:11:56.387Z","update_time":"2014-07-10T13:11:56.677Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-87R70106FP259230TEBTNNYY","rel":"self","method":"GET"}]},{"id":"P-03K35470P3291683VEBTM5HY","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:11:54.271Z","update_time":"2014-07-10T13:11:54.271Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-03K35470P3291683VEBTM5HY","rel":"self","method":"GET"}]},{"id":"P-7M166512GD050554NEBTER7I","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:11:20.061Z","update_time":"2014-07-10T13:11:20.340Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-7M166512GD050554NEBTER7I","rel":"self","method":"GET"}]},{"id":"P-0HL51828N76948921EBTECDY","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:11:18.031Z","update_time":"2014-07-10T13:11:18.031Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-0HL51828N76948921EBTECDY","rel":"self","method":"GET"}]},{"id":"P-12U98928TT9129128ECALAJY","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:40:10.407Z","update_time":"2014-07-10T13:40:10.407Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-12U98928TT9129128ECALAJY","rel":"self","method":"GET"}]},{"id":"P-9X3132019F202640KEBSJMSA","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:09:28.776Z","update_time":"2014-07-10T13:09:28.776Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-9X3132019F202640KEBSJMSA","rel":"self","method":"GET"}]},{"id":"P-7WA212708X5761403C3Y5KKA","state":"CREATED","name":"Small organization plan","description":"5000 dollars, bi weekly for 10 periods","type":"FIXED","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-08T17:07:33.288Z","update_time":"2014-07-08T17:07:33.288Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-7WA212708X5761403C3Y5KKA","rel":"self","method":"GET"}]},{"id":"P-17E58005VN572770CEBSJ4ZI","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"create_time":"2014-07-10T13:09:30.853Z","update_time":"2014-07-10T13:09:31.138Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-17E58005VN572770CEBSJ4ZI","rel":"self","method":"GET"}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans?start_id=10&sort_order=desc&status=CREATED","rel":"next_page","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=127', + 'paypal-debug-id': 'b44d581f0ca46', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=212&TopLevelTxnStartTime=1472080b424&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:10 GMT', + 'content-type': 'application/json', + 'content-length': '4183' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-plans/', {"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"}) + .reply(201, {"id":"P-8LD263969Y859015PECALKYQ","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-2XN9272442074115HECALKYQ","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-18E70525LR7147727ECALKYQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-2WN159468S510294RECALKYQ","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-35S79259W9890913DECALKYQ","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-1JG92077V7533574MECALKYY","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-6KA376884M441091UECALKYY","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:11.746Z","update_time":"2014-07-10T13:40:11.746Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-8LD263969Y859015PECALKYQ","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=300', + 'paypal-debug-id': 'd57d141103134', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=80830&TopLevelTxnStartTime=1472080b557&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:11 GMT', + 'content-type': 'application/json', + 'content-length': '1415' }); + +nock('https://api.sandbox.paypal.com') + .patch('/v1/payments/billing-plans/P-8LD263969Y859015PECALKYQ', [{"op":"replace","path":"/","value":{"state":"ACTIVE"}}]) + .reply(200, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=127', + 'paypal-debug-id': '92812b350cfa8', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=22099&TopLevelTxnStartTime=1472080b691&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:12 GMT', + 'content-type': 'text/xml', + 'content-length': '0' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-plans/P-8LD263969Y859015PECALKYQ') + .reply(200, {"id":"P-8LD263969Y859015PECALKYQ","state":"ACTIVE","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-2XN9272442074115HECALKYQ","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-2WN159468S510294RECALKYQ","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-18E70525LR7147727ECALKYQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-35S79259W9890913DECALKYQ","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-6KA376884M441091UECALKYY","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-1JG92077V7533574MECALKYY","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:11.746Z","update_time":"2014-07-10T13:40:12.077Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-8LD263969Y859015PECALKYQ","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=127', + 'paypal-debug-id': 'c6aecf3c0ce60', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=212&TopLevelTxnStartTime=1472080b7ee&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:12 GMT', + 'content-type': 'application/json', + 'content-length': '1414' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-plans/', {"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"}) + .reply(201, {"id":"P-4L7057750C0051713ECALSNQ","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-3GD42119BU321004VECALSNQ","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-8CV96058SG380880YECALSNQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-4WY78494MD5274004ECALSNQ","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-7AW81949XG794561WECALSNQ","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-5TW28694V4632832EECALSNQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-3SA704469D752342WECALSNQ","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:12.726Z","update_time":"2014-07-10T13:40:12.726Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-4L7057750C0051713ECALSNQ","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=13627', + 'paypal-debug-id': 'e3c69fd703cd7', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=80830&TopLevelTxnStartTime=1472080b92b&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:11 GMT', + 'content-type': 'application/json', + 'content-length': '1415' }); + +nock('https://api.sandbox.paypal.com') + .patch('/v1/payments/billing-plans/P-4L7057750C0051713ECALSNQ', [{"op":"replace","path":"/merchant-preferences","value":{"cancel_url":"http://www.paypal123.com","setup_fee":{"value":"22","currency":"USD"}}}]) + .reply(200, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=13627', + 'paypal-debug-id': '51938bb403e13', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=80830&TopLevelTxnStartTime=1472080ba67&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:13 GMT', + 'content-type': 'text/xml', + 'content-length': '0' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-plans/P-4L7057750C0051713ECALSNQ') + .reply(200, {"id":"P-4L7057750C0051713ECALSNQ","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-3GD42119BU321004VECALSNQ","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-4WY78494MD5274004ECALSNQ","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-8CV96058SG380880YECALSNQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-7AW81949XG794561WECALSNQ","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-3SA704469D752342WECALSNQ","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-5TW28694V4632832EECALSNQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"22"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.paypal123.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:12.726Z","update_time":"2014-07-10T13:40:13.060Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-4L7057750C0051713ECALSNQ","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=3284', + 'paypal-debug-id': '34e25d470c179', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=80971&TopLevelTxnStartTime=1472080bbe1&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:13 GMT', + 'content-type': 'application/json', + 'content-length': '1418' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-plans/', {"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"}) + .reply(201, {"id":"P-09547233PB351442AECAL2HQ","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-52L66166C3279024HECAL2HQ","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-2NE68414GA015690AECAL2HQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-00G94514XL319523UECAL2HQ","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-5SG99877PJ9817422ECAL2HQ","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-7R198667TE764594PECAL2HQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-34V40150JS539644SECAL2HQ","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:13.726Z","update_time":"2014-07-10T13:40:13.726Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-09547233PB351442AECAL2HQ","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=13627', + 'paypal-debug-id': '5aee7aed038e4', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=80830&TopLevelTxnStartTime=1472080bd13&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:13 GMT', + 'content-type': 'application/json', + 'content-length': '1415' }); + +nock('https://api.sandbox.paypal.com') + .patch('/v1/payments/billing-plans/P-09547233PB351442AECAL2HQ', [{"op":"replace","path":"/","value":{"state":"ACTIVE"}}]) + .reply(200, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=10186', + 'paypal-debug-id': '2f48e76a03bac', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=23732&TopLevelTxnStartTime=1472080bfd5&Host=slcsbjm2.slc.paypal.com&pid=31339', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:14 GMT', + 'content-type': 'text/xml', + 'content-length': '0' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements', {"name":"Fast Speed Agreement","description":"Agreement for Fast Speed Plan","start_date":"2015-02-19T00:37:04Z","plan":{"id":"P-09547233PB351442AECAL2HQ"},"payer":{"payment_method":"paypal"},"shipping_address":{"line1":"StayBr111idge Suites","line2":"Cro12ok Street","city":"San Jose","state":"CA","postal_code":"95112","country_code":"US"}}) + .reply(201, {"name":"Fast Speed Agreement","description":"Agreement for Fast Speed Plan","plan":{"id":"P-09547233PB351442AECAL2HQ","state":"ACTIVE","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payment_definitions":[{"id":"PD-52L66166C3279024HECAL2HQ","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-00G94514XL319523UECAL2HQ","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-2NE68414GA015690AECAL2HQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-5SG99877PJ9817422ECAL2HQ","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-34V40150JS539644SECAL2HQ","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-7R198667TE764594PECAL2HQ","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.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-09V09565B74284046","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-09V09565B74284046/agreement-execute","rel":"execute","method":"POST"}],"start_date":"2015-02-19T00:37:04Z"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=127', + 'paypal-debug-id': 'e250e8cc0bae3', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=22099&TopLevelTxnStartTime=1472080c11f&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:14 GMT', + 'content-type': 'application/json', + 'content-length': '1575' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-agreements/I-08413VDRU6DE') + .reply(200, {"id":"I-08413VDRU6DE","state":"Cancelled","description":"Newer Description","plan":{"payment_definitions":[{"type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20.00"},"charge_models":[{"type":"TAX","amount":{"currency":"USD","value":"20.00"}},{"type":"SHIPPING","amount":{"currency":"USD","value":"10.60"}}],"cycles":"4","frequency_interval":"1"},{"type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100.00"},"charge_models":[{"type":"TAX","amount":{"currency":"USD","value":"20.00"}},{"type":"SHIPPING","amount":{"currency":"USD","value":"10.60"}}],"cycles":"0","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25.00"},"max_fail_attempts":"1","auto_bill_amount":"YES"}},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-08413VDRU6DE/suspend","rel":"suspend","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-08413VDRU6DE/re-activate","rel":"re_activate","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-08413VDRU6DE/cancel","rel":"cancel","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-08413VDRU6DE/bill-balance","rel":"self","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-08413VDRU6DE/set-balance","rel":"self","method":"POST"}],"start_date":"2015-02-18T23:00:00Z","agreement_details":{"outstanding_balance":{"currency":"USD","value":"0.00"},"cycles_remaining":"4","cycles_completed":"0","last_payment_date":"2014-07-02T07:10:57Z","last_payment_amount":{"currency":"USD","value":"25.00"},"final_payment_date":"1970-01-01T00:00:00Z","failed_payment_count":"0"}}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=13627', + 'paypal-debug-id': '5fa7f67f046a4', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=80830&TopLevelTxnStartTime=1472080c2dc&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:14 GMT', + 'content-type': 'application/json', + 'content-length': '1744' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-plans/', {"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"}) + .reply(201, {"id":"P-8M239038M4250351NECAMIPI","state":"CREATED","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payee":{"merchant_id":"2254677669463764251"},"payment_definitions":[{"id":"PD-6NM64917YN7765425ECAMIPI","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-5LV43906LJ307104DECAMIPI","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-0KE608780B2534216ECAMIPI","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-6C822850FP2569353ECAMIPI","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-7HY62822F8753893WECAMIPI","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}},{"id":"CHM-2B6251795H312091PECAMIPI","type":"TAX","amount":{"currency":"USD","value":"20"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.com","cancel_url":"http://www.cancel.com","auto_bill_amount":"YES","initial_fail_amount_action":"CONTINUE"},"create_time":"2014-07-10T13:40:15.549Z","update_time":"2014-07-10T13:40:15.549Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-plans/P-8M239038M4250351NECAMIPI","rel":"self","method":"GET"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=10599', + 'paypal-debug-id': '1c45c6a00b9e5', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=212&TopLevelTxnStartTime=1472080c431&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:15 GMT', + 'content-type': 'application/json', + 'content-length': '1415' }); + +nock('https://api.sandbox.paypal.com') + .patch('/v1/payments/billing-plans/P-8M239038M4250351NECAMIPI', [{"op":"replace","path":"/","value":{"state":"ACTIVE"}}]) + .reply(200, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=10599', + 'paypal-debug-id': '4b3143670bf17', + server_info: 'paymentsplatformserv:v1.payments.billing-plans&CalThreadId=212&TopLevelTxnStartTime=1472080c55b&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:15 GMT', + 'content-type': 'text/xml', + 'content-length': '0' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements', {"name":"Fast Speed Agreement","description":"Agreement for Fast Speed Plan","start_date":"2015-02-19T00:37:04Z","plan":{"id":"P-8M239038M4250351NECAMIPI"},"payer":{"payment_method":"paypal"},"shipping_address":{"line1":"StayBr111idge Suites","line2":"Cro12ok Street","city":"San Jose","state":"CA","postal_code":"95112","country_code":"US"}}) + .reply(201, {"name":"Fast Speed Agreement","description":"Agreement for Fast Speed Plan","plan":{"id":"P-8M239038M4250351NECAMIPI","state":"ACTIVE","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payment_definitions":[{"id":"PD-6NM64917YN7765425ECAMIPI","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-0KE608780B2534216ECAMIPI","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-5LV43906LJ307104DECAMIPI","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-6C822850FP2569353ECAMIPI","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-2B6251795H312091PECAMIPI","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-7HY62822F8753893WECAMIPI","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.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-28Y23504JA4250117","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-28Y23504JA4250117/agreement-execute","rel":"execute","method":"POST"}],"start_date":"2015-02-19T00:37:04Z"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=10599', + 'paypal-debug-id': '2c4c1b090bc6d', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=212&TopLevelTxnStartTime=1472080c6a4&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:15 GMT', + 'content-type': 'application/json', + 'content-length': '1575' }); + +nock('https://api.sandbox.paypal.com') + .patch('/v1/payments/billing-agreements/I-08413VDRU6DE', {"name":"Fast Speed Agreement","description":"Agreement for Fast Speed Plan","start_date":"2015-02-19T00:37:04Z","plan":{"id":"P-8M239038M4250351NECAMIPI"},"payer":{"payment_method":"paypal"},"shipping_address":{"line1":"StayBr111idge Suites","line2":"Cro12ok Street","city":"San Jose","state":"CA","postal_code":"95112","country_code":"US"}}) + .reply(201, {"name":"Fast Speed Agreement","description":"Agreement for Fast Speed Plan","plan":{"id":"P-8M239038M4250351NECAMIPI","state":"ACTIVE","name":"Testing1-Regular1","description":"Create Plan for Regular","type":"INFINITE","payment_definitions":[{"id":"PD-6NM64917YN7765425ECAMIPI","name":"Regular 1","type":"REGULAR","frequency":"Month","amount":{"currency":"USD","value":"100"},"charge_models":[{"id":"CHM-0KE608780B2534216ECAMIPI","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-5LV43906LJ307104DECAMIPI","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"0","frequency_interval":"1"},{"id":"PD-6C822850FP2569353ECAMIPI","name":"Trial 1","type":"TRIAL","frequency":"Month","amount":{"currency":"USD","value":"20"},"charge_models":[{"id":"CHM-2B6251795H312091PECAMIPI","type":"TAX","amount":{"currency":"USD","value":"20"}},{"id":"CHM-7HY62822F8753893WECAMIPI","type":"SHIPPING","amount":{"currency":"USD","value":"10.6"}}],"cycles":"4","frequency_interval":"1"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25"},"max_fail_attempts":"1","return_url":"http://www.success.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-28Y23504JA4250117","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/EC-28Y23504JA4250117/agreement-execute","rel":"execute","method":"POST"}],"start_date":"2015-02-19T00:37:04Z"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=10599', + 'paypal-debug-id': '2c4c1b090bc6d', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=212&TopLevelTxnStartTime=1472080c6a4&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 13:40:15 GMT', + 'content-type': 'application/json', + 'content-length': '1575' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/oauth2/token', "grant_type=client_credentials") + .reply(200, {"scope":"openid https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card/.* https://api.paypal.com/v1/vault/credit-card","access_token":"A015g1XmdAx6jM8lR6WXR9yNqf2gCMGpkbvyyBfOPQqjT.s","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":28800}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=13638', + 'paypal-debug-id': '962b7888216b7', + server_info: 'identitysecuretokenserv:v1.oauth2.token&CalThreadId=126527&TopLevelTxnStartTime=1472112bcac&Host=slcsbidensectoken502.slc.paypal.com&pid=29059', + date: 'Thu, 10 Jul 2014 16:19:42 GMT', + 'content-type': 'application/json', + 'content-length': '374' }); + +nock('https://api.sandbox.paypal.com') + .patch('/v1/payments/billing-agreements/I-W0CR3PB7KTBB', [{"op":"replace","path":"/","value":{"description":"New Description","name":"New Name","shipping_address":{"line1":"StayBridge Suites","line2":"Crook Street","city":"San Jose","state":"CA","postal_code":"95112","country_code":"US"}}}]) + .reply(200, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=13638', + 'paypal-debug-id': '4c2bc228214ef', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=21897&TopLevelTxnStartTime=1472112bf37&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 16:19:43 GMT', + 'content-type': 'text/xml', + 'content-length': '0' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-agreements/I-W0CR3PB7KTBB') + .reply(200, {"id":"I-W0CR3PB7KTBB","state":"Active","description":"New Description","plan":{"payment_definitions":[{"type":"REGULAR","frequency":"Week","amount":{"currency":"USD","value":"250.00"},"charge_models":[{"type":"TAX","amount":{"currency":"USD","value":"5.00"}},{"type":"SHIPPING","amount":{"currency":"USD","value":"25.00"}}],"cycles":"10","frequency_interval":"2"}],"merchant_preferences":{"setup_fee":{"currency":"USD","value":"25.00"},"max_fail_attempts":"1","auto_bill_amount":"YES"}},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-W0CR3PB7KTBB/suspend","rel":"suspend","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-W0CR3PB7KTBB/re-activate","rel":"re_activate","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-W0CR3PB7KTBB/cancel","rel":"cancel","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-W0CR3PB7KTBB/bill-balance","rel":"self","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/billing-agreements/I-W0CR3PB7KTBB/set-balance","rel":"self","method":"POST"}],"start_date":"2015-02-18T23:00:00Z","agreement_details":{"outstanding_balance":{"currency":"USD","value":"0.00"},"cycles_remaining":"10","cycles_completed":"0","next_billing_date":"2015-02-19T10:00:00Z","last_payment_date":"2014-07-08T02:01:02Z","last_payment_amount":{"currency":"USD","value":"25.00"},"final_payment_date":"2015-06-25T10:00:00Z","failed_payment_count":"0"}}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=13943', + 'paypal-debug-id': 'f8a239ee25af5', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=80830&TopLevelTxnStartTime=1472112c35b&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 16:19:43 GMT', + 'content-type': 'application/json', + 'content-length': '1522' }); + +nock('https://api.sandbox.paypal.com') + .get('/v1/payments/billing-agreements/I-W0CR3PB7KTBB/transaction?start-date=2014-07-01&end-date=2014-07-20') + .reply(200, {"agreement_transaction_list":[{"transaction_id":"I-W0CR3PB7KTBB","status":"Created","transaction_type":"Recurring Payment","payer_email":"","payer_name":"John Smith","time_stamp":"2014-07-07T22:16:19Z","time_zone":"GMT"},{"transaction_id":"6D127165PP237693N","status":"Unclaimed","transaction_type":"Recurring Payment","amount":{"currency":"USD","value":"25.00"},"fee_amount":{"currency":"USD","value":"0.00"},"net_amount":{"currency":"USD","value":"25.00"},"payer_email":"android_test1@gmail.com","payer_name":"John Smith","time_stamp":"2014-07-08T02:01:02Z","time_zone":"GMT"},{"transaction_id":"I-W0CR3PB7KTBB","status":"Updated","transaction_type":"Recurring Payment","payer_email":"","payer_name":"John Smith","time_stamp":"2014-07-10T16:17:43Z","time_zone":"GMT"},{"transaction_id":"I-W0CR3PB7KTBB","status":"Updated","transaction_type":"Recurring Payment","payer_email":"","payer_name":"John Smith","time_stamp":"2014-07-10T16:17:44Z","time_zone":"GMT"},{"transaction_id":"I-W0CR3PB7KTBB","status":"Updated","transaction_type":"Recurring Payment","payer_email":"","payer_name":"John Smith","time_stamp":"2014-07-10T16:19:42Z","time_zone":"GMT"}]}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=13943', + 'paypal-debug-id': '3f07358025e08', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=80830&TopLevelTxnStartTime=1472112c646&Host=slcsbjm1.slc.paypal.com&pid=17780', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 16:19:43 GMT', + 'content-type': 'application/json', + 'content-length': '1159' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements/I-W0CR3PB7KTBB/suspend', {"note": "Suspending the agreement"}) + .reply(204, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=250', + 'paypal-debug-id': '266f94b67502a', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=23732&TopLevelTxnStartTime=14721e79b9f&Host=slcsbjm2.slc.paypal.com&pid=31339', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 20:12:13 GMT' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements/I-W0CR3PB7KTBB/re-activate', {"note": "Reactivating the agreement"}) + .reply(204, "", { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=10186', + 'paypal-debug-id': '1ae0bc788fc79', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=128&TopLevelTxnStartTime=1472208339f&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Thu, 10 Jul 2014 20:47:48 GMT' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements/I-W0CR3PB7KTBB/set-balance', {"value":"100000","currency":"USD"}) + .reply(400, {"name":"RP_CANT_INCREASE_OUTSTANDING_AMOUNT","message":"Cannot increase delinquent amount","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#RP_CANT_INCREASE_OUTSTANDING_AMOUNT","debug_id":"1ba1f49a14f8f"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=230', + 'paypal-debug-id': '1ba1f49a14f8f', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=128&TopLevelTxnStartTime=1473bb57f0b&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Tue, 15 Jul 2014 20:27:36 GMT', + connection: 'close, close', + 'content-type': 'application/json', + 'content-length': '233' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements/I-W0CR3PB7KTBB/bill-balance', {"note":"Billing Balance Amount","amount":{"value":"100000","currency":"USD"}}) + .reply(400, {"name":"RP_CANT_INCREASE_OUTSTANDING_AMOUNT","message":"Cannot increase delinquent amount","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#RP_CANT_INCREASE_OUTSTANDING_AMOUNT","debug_id":"1ba1f49a14f8f"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava3.slc.paypal.com;threadId=230', + 'paypal-debug-id': '1ba1f49a14f8f', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=128&TopLevelTxnStartTime=1473bb57f0b&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Tue, 15 Jul 2014 20:27:36 GMT', + connection: 'close, close', + 'content-type': 'application/json', + 'content-length': '233' }); + +nock('https://api.sandbox.paypal.com') + .post('/v1/payments/billing-agreements/I-W0CR3PB7KTBB/cancel', {"note":"Canceling the agreement"}) + .reply(400, {"name":"RP_INVALID_STATUS_TO_CANCEL","message":"Invalid profile status for cancel action; profile should be active or suspended","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#RP_INVALID_STATUS_TO_CANCEL","debug_id":"0cc67ff0854e1"}, { server: 'Apache-Coyote/1.1', + proxy_server_info: 'host=slcsbjava2.slc.paypal.com;threadId=10318', + 'paypal-debug-id': '0cc67ff0854e1', + server_info: 'paymentsplatformserv:v1.payments.billing-agreements&CalThreadId=21897&TopLevelTxnStartTime=1473bcc55ed&Host=slcsbjm3.slc.paypal.com&pid=24310', + 'content-language': '*', + date: 'Tue, 15 Jul 2014 20:52:33 GMT', + connection: 'close, close', + 'content-type': 'application/json', + 'content-length': '263' }); \ No newline at end of file diff --git a/test/openid_connect.js b/test/openid_connect.js index 7f769f99..5da2ed16 100644 --- a/test/openid_connect.js +++ b/test/openid_connect.js @@ -48,6 +48,10 @@ describe('OpenIDConnect', function () { var url = openid_connect.authorize_url({'scope': 'openid profile'}); expect(url).to.not.contain('sandbox'); expect(url).to.contain('www.paypal.com'); + paypal_sdk.configure({ + 'mode': 'sandbox' + }); + done(); }); }); @@ -72,7 +76,10 @@ describe('OpenIDConnect', function () { var url = openid_connect.logout_url({'id_token': 'test'}); expect(url).to.not.contain('sandbox'); expect(url).to.contain('www.paypal.com'); - console.log(url); + paypal_sdk.configure({ + 'mode': 'sandbox' + }); + done(); }); }); diff --git a/test/subscription.js b/test/subscription.js index f4037eea..fddd15ef 100644 --- a/test/subscription.js +++ b/test/subscription.js @@ -11,49 +11,76 @@ require('./configure'); describe('SDK', function () { describe('Subscription', function () { var billing_plan_attributes = { - "name": "Fast Speed Plan", - "description": "Template creation.", - "type": "fixed", + "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": [ { - "name": "Payment Definition-1", - "type": "REGULAR", + "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": "2", + "frequency_interval": "1", + "name": "Regular 1", + "type": "REGULAR" + }, + { "amount": { - "value": "100", - "currency": "USD" + "currency": "USD", + "value": "20" }, - "cycles": "12", "charge_models": [ { - "type": "SHIPPING", "amount": { - "value": "10", - "currency": "USD" - } + "currency": "USD", + "value": "10.60" + }, + "type": "SHIPPING" }, { - "type": "TAX", "amount": { - "value": "12", - "currency": "USD" - } + "currency": "USD", + "value": "20" + }, + "type": "TAX" } - ] + ], + "cycles": "4", + "frequency": "MONTH", + "frequency_interval": "1", + "name": "Trial 1", + "type": "TRIAL" } ], - "merchant_preferences": { - "setup_fee": { - "value": "1", - "currency": "USD" - }, - "return_url": "http://www.paypal.com", - "cancel_url": "http://www.yahoo.com", - "autobill_amount": "YES", - "initial_amount_fail_action": "CONTINUE", - "max_fail_attempts": "0" - } + "type": "INFINITE" }; var billing_plan_update_attributes = [ @@ -66,6 +93,20 @@ describe('SDK', function () { } ]; + var update_merchant_preferences = [ + { + "op": "replace", + "path": "/merchant-preferences", + "value": { + "cancel_url": "http://www.paypal123.com", + "setup_fee": { + "value": "22", + "currency": "USD" + } + } + } + ]; + var billing_agreement_attributes = { "name": "Fast Speed Agreement", "description": "Agreement for Fast Speed Plan", @@ -86,6 +127,40 @@ describe('SDK', function () { } }; + var billing_agreement_attributes_cc = { + "name": "Fast Speed Agreement", + "description": "Agreement for the Fast Speed Plan", + "start_date": "2015-02-19T00:37:04Z", + "plan": { + "id": "P-9JJ08935W261554413DRYT4I" + }, + "payer": { + "payment_method": "credit_card", + "payer_info": { + "email": "anadas@paypal.com" + }, + "funding_instruments": [{ + "credit_card": { + "type": "visa", + "number": "4417119669820331", + "expire_month": "12", + "expire_year": "2017", + "cvv2": "128", + "start_month": "11", + "start_year": "2010" + } + }] + }, + "shipping_address": { + "line1": "StayBr111idge Suites", + "line2": "Cro12ok Street", + "city": "San Jose", + "state": "CA", + "postal_code": "95112", + "country_code": "US" + } + }; + var billing_agreement_update_attributes = [ { "op": "replace", @@ -94,8 +169,8 @@ describe('SDK', function () { "description": "New Description", "name": "New Name", "shipping_address": { - "line1": "StayBr111idge Suites", - "line2": "Cro12ok Street", + "line1": "StayBridge Suites", + "line2": "Crook Street", "city": "San Jose", "state": "CA", "postal_code": "95112", @@ -104,11 +179,11 @@ describe('SDK', function () { } } ]; - /* + var billing_agreement_id = 'I-W0CR3PB7KTBB'; + if (process.env.NOCK_OFF !== 'true') { require('./mocks/subscription'); } - */ it('billing plan create and get success', function (done) { paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { @@ -125,9 +200,7 @@ describe('SDK', function () { it('get nonexistent billing plan failure', function (done) { paypal_sdk.billing_plan.get('ABRACADABRA', function (error, billingPlan) { - //should fail - expect(error.response.name).to.equal('BUSINESS_ERROR'); - expect(error.response.message).to.equal('Invalid encrypted id.'); + expect(error.response.name).to.equal('TEMPLATE_ID_INVALID'); done(); }); }); @@ -139,85 +212,81 @@ describe('SDK', function () { }); }); - //QUESTION : is there a way to retrieve one billing agreement? how about all agreements - it('update billing plan success', function (done) { + it('activate billing plan success', function (done) { paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { expect(error).equal(null); expect(billingPlan.state).equal("CREATED"); - //wont work as patch returns a 204 so cannot expect billingPlan to be returned - //consider update vs replace paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - expect(billingPlan.state).equal("ACTIVE"); - done(); + expect(response.httpStatusCode).equal(200); + + paypal_sdk.billing_plan.get(billingPlan.id, function (error, billingPlan) { + expect(error).equal(null); + expect(billingPlan.state).to.contain('ACTIVE'); + done(); + }); }); }); }); - it('billing agreement create from billing plan success', function (done) { + it('update merchant preferences for billing plan success', function (done) { paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { expect(error).equal(null); expect(billingPlan.state).equal("CREATED"); - //wont work as patch returns a 204 so cannot expect billingPlan to be returned - //consider update vs replace - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { + paypal_sdk.billing_plan.update(billingPlan.id, update_merchant_preferences, function (error, response) { expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - expect(billingPlan.state).equal("ACTIVE"); + expect(response.httpStatusCode).equal(200); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { + paypal_sdk.billing_plan.get(billingPlan.id, function (error, billingPlan) { expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); - expect(billingAgreement.name).to.equal(billing_agreement_attributes.name); - expect(billingAgreement.plan.id).to.equal(billing_agreement_attributes.plan.id); + expect(billingPlan.merchant_preferences.setup_fee.value).to.equal('22'); + expect(billingPlan.merchant_preferences.cancel_url).to.equal('http://www.paypal123.com'); done(); }); }); }); }); - it('billing agreement create from billing plan and get success', function (done) { + it('billing agreement create from billing plan success', function (done) { paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { expect(error).equal(null); expect(billingPlan.state).equal("CREATED"); paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - expect(billingPlan.state).equal("ACTIVE"); + expect(response.httpStatusCode).equal(200); billing_agreement_attributes.plan.id = billingPlan.id; paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); - - paypal_sdk.billing_agreement.get(billingAgreement.id, function (error, billingAgreement) { - expect(billingAgreement.name).to.equal(billing_agreement_attributes.name); - expect(billingAgreement.plan.id).to.equal(billing_agreement_attributes.plan.id); - done(); - }); + expect(billingAgreement.name).to.equal(billing_agreement_attributes.name); + expect(billingAgreement.plan.id).to.equal(billing_agreement_attributes.plan.id); + done(); }); }); }); }); + it('billing agreement get success', function (done) { + paypal_sdk.billing_agreement.get(billing_agreement_id, function (error, billingAgreement) { + expect(error).equal(null); + expect(billingAgreement.id).equal(billing_agreement_id); + done(); + }); + }); + it('billing agreement execute after create from billing plan success', function (done) { paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { expect(error).equal(null); - //wont work as patch returns a 204 so cannot expect billingPlan to be returned - //consider update vs replace + paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { expect(error).equal(null); - expect(response.httpStatusCode).equal(204); billing_agreement_attributes.plan.id = billingPlan.id; paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); expect(billingAgreement).to.have.property('links'); for (var index = 0; index < billingAgreement.links.length; index++) { @@ -231,190 +300,87 @@ describe('SDK', function () { }); }); - it('billing agreement update success', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { - expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); - - paypal_sdk.billing_agreement.update(billingAgreement.id, billing_agreement_update_attributes, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - expect(billingAgreement.name).equal(billing_agreement_update_attributes.value.name); - expect(billingAgreement.description).equal(billing_agreement_update_attributes.value.description); - done(); - }); - }); - }); + it('search transactions for billing agreement not empty', function (done) { + var start_date = "2014-07-01"; + var end_date = "2014-07-20"; + + paypal_sdk.billing_agreement.search_transactions(billing_agreement_id, start_date, end_date, function (error, response) { + expect(response).to.have.property('agreement_transaction_list'); + expect(response.agreement_transaction_list).to.be.an('Array'); + expect(response.agreement_transaction_list).to.not.be.empty; + done(); }); }); it('billing agreement suspend success', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { - expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); - - var suspend_note = { - "note": "Suspending the agreement" - }; + var suspend_note = { + "note": "Suspending the agreement" + }; - paypal_sdk.billing_agreement.suspend(billingAgreement.id, suspend_note, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - done(); - }); - }); - }); + paypal_sdk.billing_agreement.suspend(billing_agreement_id, suspend_note, function (error, response) { + expect(error).equal(null); + done(); }); }); it('billing agreement reactivate success', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { - expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); - - paypal_sdk.billing_agreement.suspend(billingAgreement.id, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - - var reactivate_note = { - "note": "Reactivating the agreement" - }; - - paypal_sdk.billing_agreement.re_activate(billingAgreement.id, reactivate_note, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - done(); - }); - }); - }); - }); - }); - }); + var reactivate_note = { + "note": "Reactivating the agreement" + }; - it('search transactions for billing agreement finds none', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { + paypal_sdk.billing_agreement.reactivate(billing_agreement_id, reactivate_note, function (error, response) { expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - - paypal_sdk.billing_agreement.search_transactions(billingAgreement.id, function (error, response) { - expect(response).to.have.property('agreement_transaction_list'); - expect(response.agreement_transaction_list).to.be.empty(); - done(); - }); - }); - }); + expect(response.httpStatusCode).equal(204); + done(); }); }); - it('billing agreement cancel success', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { - expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - expect(billingAgreement.id).to.contain('I-'); - - var cancel_note = { - "note": "Canceling the agreement" - }; - - paypal_sdk.billing_agreement.cancel(billingAgreement.id, cancel_note, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - done(); - }); - }); - }); + it('set outstanding agreement amount fails with cannot increase delinquent amount', function (done) { + var outstanding_amount = { + "value": "100000", + "currency": "USD" + }; + + paypal_sdk.billing_agreement.set_balance(billing_agreement_id, outstanding_amount, function (error, response) { + expect(error.response.name).equal('RP_CANT_INCREASE_OUTSTANDING_AMOUNT'); + expect(error.response.message).equal('Cannot increase delinquent amount'); + expect(error.response.information_link).equal('https://developer.paypal.com/webapps/developer/docs/api/#RP_CANT_INCREASE_OUTSTANDING_AMOUNT'); + expect(error.httpStatusCode).equal(400); + done(); }); }); - it('set outstanding agreement amounts success', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { - expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - - var outstanding_amount = { - "value" : "100", - "currency" : "USD" - }; + it('bill outstanding agreement amount fails with cannot increase delinquent amount', function (done) { + var outstanding_amount = { + "note": "Billing Balance Amount", + "amount": { + "value": "100000", + "currency": "USD" + } + }; - paypal_sdk.billing_agreement.set_balance(billingAgreement.id, outstanding_amount, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - done(); - }); - }); - }); + paypal_sdk.billing_agreement.bill_balance(billing_agreement_id, outstanding_amount, function (error, response) { + expect(error.response.name).equal('RP_CANT_INCREASE_OUTSTANDING_AMOUNT'); + expect(error.response.message).equal('Cannot increase delinquent amount'); + expect(error.response.information_link).equal('https://developer.paypal.com/webapps/developer/docs/api/#RP_CANT_INCREASE_OUTSTANDING_AMOUNT'); + expect(error.httpStatusCode).equal(400); + done(); }); }); - it('bill outstanding agreement amounts success', function (done) { - paypal_sdk.billing_plan.create(billing_plan_attributes, function (error, billingPlan) { - expect(error).equal(null); - paypal_sdk.billing_plan.update(billingPlan.id, billing_plan_update_attributes, function (error, response) { - expect(error).equal(null); - billing_agreement_attributes.plan.id = billingPlan.id; - paypal_sdk.billing_agreement.create(billing_agreement_attributes, function (error, billingAgreement) { - expect(error).equal(null); - - var outstanding_amount = { - "value" : "100", - "currency" : "USD" - }; - paypal_sdk.billing_agreement.set_balance(billingAgreement.id, outstanding_amount, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - - var outstanding_amount_note = { - "note": "Billing Balance Amount", - "amount": outstanding_amount - }; - paypal_sdk.billing_agreement.bill_balance(billingAgreement.id, outstanding_amount_note, function (error, response) { - expect(error).equal(null); - expect(response.httpStatusCode).equal(204); - done(); - }); - }); - }); - }); + it('billing agreement cancel fails on invalid status', function (done) { + var cancel_note = { + "note": "Canceling the agreement" + }; + + paypal_sdk.billing_agreement.cancel(billing_agreement_id, cancel_note, function (error, response) { + expect(error.response.name).equal('RP_INVALID_STATUS_TO_CANCEL'); + expect(error.response.message).equal('Invalid profile status for cancel action; profile should be active or suspended'); + expect(error.response.information_link).equal('https://developer.paypal.com/webapps/developer/docs/api/#RP_INVALID_STATUS_TO_CANCEL'); + expect(error.response.debug_id).not.be.empty; + expect(error.httpStatusCode).equal(400); + done(); }); }); - - // QUESTION after you create Returns the agreement object based on the billing plan. - // after creating billing agreement does the id get returned - //QUESTION: documentation does not look like id is returned, is id only populated after buyer approval? - //QUESTION: will a plan be around for testing? - //QUESTION: Search for agreements transactions what will it return, can be different than recurring payments? - //Quesion: set-balance is not documented - - //QUESTION: test agreement-execute? - //QUESTION: does bill_balance and set_balance only start working after - //QUESTION: post of execute agreement does not seem to have details - //QUESTION: Retrieve an agreement not documented along with set_balance }); }); \ No newline at end of file