node-radial
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -18,2 +18,3 @@ /* LIB */ | ||
PayPal.setExpress = require('./setExpress'); | ||
PayPal.getExpress = require('./getExpress'); | ||
@@ -25,5 +26,5 @@ /* NPM EXPORT */ | ||
} else { | ||
throw new Error('This module only works with NPM in NodeJS/IO.JS environments.'); | ||
throw new Error('This module only works with NPM in NodeJS environments.'); | ||
} | ||
}()); |
@@ -214,30 +214,122 @@ /* LIB */ | ||
}] | ||
}, { | ||
}] | ||
}] | ||
}; | ||
if (options.shipToName) { | ||
postBodyJson.elements[0].elements.push({ | ||
type: 'element', | ||
name: 'ShipToName', | ||
elements: [{ | ||
type: 'text', | ||
text: options.shipToName !== undefined ? | ||
options.shipToName : '' | ||
}] | ||
}); | ||
} | ||
if (options.shippingAddress && typeof options.shippingAddress === 'object') { | ||
var shippingAddressElements = [{ | ||
type: 'element', | ||
name: 'Line1', | ||
elements: [{ | ||
type: 'text', | ||
text: options.shippingAddress.line1 | ||
}] | ||
}]; | ||
if (options.shippingAddress.line2) { | ||
shippingAddressElements.push({ | ||
type: 'element', | ||
name: 'LineItems', | ||
elements: lineItemsXml | ||
}, { | ||
type: 'element', | ||
name: 'Recurring', | ||
name: 'Line2', | ||
elements: [{ | ||
type: 'text', | ||
text: recurring | ||
text: options.shippingAddress.line2 | ||
}] | ||
}, { | ||
}); | ||
} | ||
if (options.shippingAddress.line3) { | ||
shippingAddressElements.push({ | ||
type: 'element', | ||
name: 'Installment', | ||
name: 'Line3', | ||
elements: [{ | ||
type: 'text', | ||
text: installment | ||
text: options.shippingAddress.line3 | ||
}] | ||
}, { | ||
}); | ||
} | ||
if (options.shippingAddress.line4) { | ||
shippingAddressElements.push({ | ||
type: 'element', | ||
name: 'SchemaVersion', | ||
name: 'Line4', | ||
elements: [{ | ||
type: 'text', | ||
text: '1.1' | ||
text: options.shippingAddress.line4 | ||
}] | ||
}); | ||
} | ||
shippingAddressElements = shippingAddressElements.concat([{ | ||
type: 'element', | ||
name: 'City', | ||
elements: [{ | ||
type: 'text', | ||
text: options.shippingAddress.city | ||
}] | ||
}, { | ||
type: 'element', | ||
name: 'MainDivision', | ||
elements: [{ | ||
type: 'text', | ||
text: options.shippingAddress.mainDivision | ||
}] | ||
}, { | ||
type: 'element', | ||
name: 'CountryCode', | ||
elements: [{ | ||
type: 'text', | ||
text: options.shippingAddress.countryCode | ||
}] | ||
}, { | ||
type: 'element', | ||
name: 'PostalCode', | ||
elements: [{ | ||
type: 'text', | ||
text: options.shippingAddress.postalCode | ||
}] | ||
}]); | ||
postBodyJson.elements[0].elements.push({ | ||
type: 'element', | ||
name: 'ShippingAddress', | ||
elements: shippingAddressElements | ||
}); | ||
} | ||
postBodyJson.elements[0].elements = postBodyJson.elements[0].elements.concat([{ | ||
type: 'element', | ||
name: 'LineItems', | ||
elements: lineItemsXml | ||
}, { | ||
type: 'element', | ||
name: 'Recurring', | ||
elements: [{ | ||
type: 'text', | ||
text: recurring | ||
}] | ||
}; | ||
}, { | ||
type: 'element', | ||
name: 'Installment', | ||
elements: [{ | ||
type: 'text', | ||
text: installment | ||
}] | ||
}, { | ||
type: 'element', | ||
name: 'SchemaVersion', | ||
elements: [{ | ||
type: 'text', | ||
text: '1.2' | ||
}] | ||
}]); | ||
@@ -251,3 +343,14 @@ var xmlBody = xmlConvert.js2xml(postBodyJson); | ||
}, function (err, response) { | ||
return fn(err, response); | ||
if (err) return fn(err); | ||
var reply = response.PayPalSetExpressCheckoutReply; | ||
if (reply.ResponseCode._text === 'Failure') { | ||
return fn(reply.ErrorMessage._text); | ||
} | ||
return fn(null, { | ||
responseCode: reply.ResponseCode._text, | ||
orderId: reply.OrderId._text, | ||
token: reply.Token._text | ||
}); | ||
}); | ||
@@ -261,5 +364,5 @@ }; | ||
} else { | ||
throw new Error('This module only works with NPM in NodeJS/IO.JS environments.'); | ||
throw new Error('This module only works with NPM in NodeJS environments.'); | ||
} | ||
}()); |
@@ -43,15 +43,10 @@ /* LIB */ | ||
}); | ||
var reply = jsonBody.PayPalSetExpressCheckoutReply; | ||
if (response.statusCode !== 200) { | ||
return fn(reply); | ||
} else if (reply.ResponseCode._text === 'Failure') { | ||
return fn(reply.ErrorMessage._text); | ||
return fn(jsonBody); | ||
} else if (jsonBody.Fault) { | ||
return fn(jsonBody.Fault.Description._text); | ||
} | ||
return fn(null, { | ||
responseCode: reply.ResponseCode._text, | ||
orderId: reply.OrderId._text, | ||
token: reply.Token._text | ||
}); | ||
return fn(null, jsonBody); | ||
}); | ||
@@ -65,5 +60,5 @@ }; | ||
} else { | ||
throw new Error('This module only works with NPM in NodeJS/IO.JS environments.'); | ||
throw new Error('This module only works with NPM in NodeJS environments.'); | ||
} | ||
}()); |
{ | ||
"name": "node-radial", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "NodeJS SDK for the Radial APIs", | ||
@@ -5,0 +5,0 @@ "main": "radial.js", |
@@ -47,5 +47,5 @@ /* LIB */ | ||
} else { | ||
throw new Error('This module only works with NPM in NodeJS/IO.JS environments.'); | ||
throw new Error('This module only works with NPM in NodeJS environments.'); | ||
} | ||
}()); |
@@ -50,20 +50,87 @@ [![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url] | ||
currencyCode: 'USD', | ||
addressOverride: 0, | ||
noShippingAddressDisplay: 1, | ||
addressOverride: 0, // optional | ||
noShippingAddressDisplay: 1, // optional | ||
shipToName: 'John Doe', // optional | ||
shippingAddress: { // optional | ||
line1: '', | ||
line2: '', | ||
line3: '', | ||
line4: '', | ||
city: '', | ||
mainDivision: '', | ||
countryCode: '', | ||
postalCode: '' | ||
}, | ||
shippingTotal: 2.00, | ||
taxTotal: 1.23, | ||
lineItems: lineItems, | ||
installment: false, | ||
recurring: false | ||
installment: false, // optional | ||
recurring: false // optional | ||
}, function(err, response) { | ||
// response = { | ||
// responseCode: 'Success', | ||
// orderId: '12345', | ||
// token: 'EC-5YE59312K56892714' | ||
// }; | ||
/* | ||
response = { | ||
responseCode: 'Success', | ||
orderId: '12345', | ||
token: 'EC-5YE59312K56892714' | ||
}; | ||
*/ | ||
}); | ||
``` | ||
### PayPal GetExpress | ||
The second API in PayPal checkout flow. See the following reference for details. | ||
<https://docs.ptf.radial.com/Content/Topics/payments/paypal-get-express.htm> | ||
``` | ||
radial.paypal.getExpress({ | ||
orderId: '12345', | ||
token: 'EC-5YE59312K56892714', | ||
currencyCode: 'USD' | ||
}, function(err, response) { | ||
/* | ||
response = { | ||
responseCode: 'Success', | ||
orderId: '12345', | ||
payerId: '', | ||
payerEmail: '', | ||
payerStatus: '', | ||
payerName: { | ||
honorific: '', | ||
firstName: '', | ||
middleName: '', | ||
lastName: '' | ||
}, | ||
payerCountry: '', | ||
payerPhone: '', | ||
billingAddress: { | ||
line1: '', | ||
line2: '', | ||
line3: '', | ||
line4: '', | ||
city: '', | ||
mainDivision: '', | ||
countryCode: '', | ||
postalCode: '' | ||
}, | ||
shippingAddress: { | ||
line1: '', | ||
line2: '', | ||
line3: '', | ||
line4: '', | ||
city: '', | ||
mainDivision: '', | ||
countryCode: '', | ||
postalCode: '' | ||
}, | ||
shipToName: '' | ||
} | ||
*/ | ||
}); | ||
``` | ||
## CHANGELOG | ||
- **0.1.1:** Add PayPal getExpress endpoint. | ||
- **0.1.0:** Initial release. Only PayPal setExpress is available so far. | ||
@@ -70,0 +137,0 @@ |
23418
10
560
144