Comparing version 0.0.3 to 0.0.4
'use strict'; | ||
var HPP = require('./HPP'); | ||
var | ||
HPP = require('./HPP'), | ||
ValidateHPP = require('./ValidateHPP'); | ||
module.exports.HPP = HPP; | ||
module.exports.HPP = HPP; | ||
module.exports.ValidateHPP = ValidateHPP; |
'use strict'; | ||
// TODO: Custom Payment method | ||
var | ||
@@ -10,2 +12,6 @@ crypto = require('crypto'), | ||
var HPP = function (options) { | ||
options = options || {}; | ||
// HMACKey | ||
if (!options.HMACKey) { | ||
@@ -15,2 +21,8 @@ throw new Error('HMAC key is required'); | ||
// paymentAmount | ||
if (!options.paymentAmount || isNaN(options.paymentAmount)) { | ||
throw new Error('paymentAmount is required and have to be a Number'); | ||
} | ||
// skinCode | ||
if (!options.skinCode) { | ||
@@ -20,2 +32,3 @@ throw new Error('skinCode is required'); | ||
// merchantAccount | ||
if (!options.merchantAccount) { | ||
@@ -25,2 +38,12 @@ throw new Error('merchantAccount is required'); | ||
// merchantReference: optional | ||
if(options.merchantReference && options.merchantReference.length > 80) { | ||
throw new Error('merchantReference: The maximum length is 80 characters.'); | ||
} | ||
// merchantReturnData: optional | ||
if(options.merchantReturnData && options.merchantReturnData.length > 128) { | ||
throw new Error('merchantReturnData: The maximum length is 128 characters.'); | ||
} | ||
this._HMACKey = options.HMACKey; | ||
@@ -36,4 +59,6 @@ this._url = 'https://live.adyen.com/hpp/pay.shtml?'; | ||
this._request = { | ||
merchantReference: options.merchantReference || 'PAYMENT-' + moment().format('YYYY-MM-DDThh:mm:ssTZD'), // The merchant reference is your reference for the payment | ||
paymentAmount: options.paymentAmount || 0, // Amount specified in minor units EUR 1,00 = 100 | ||
// Required for payment | ||
merchantReference: options.merchantReference || 'PAYMENT-' + moment().format('YYYY-MM-DDThh:mm:ssZ'), // The merchant reference is your reference for the payment | ||
paymentAmount: options.paymentAmount, // Amount specified in minor units EUR 1,00 = 100 | ||
currencyCode: options.currencyCode || 'EUR', // The three-letter capitalised ISO currency code to pay in i.e. EUR | ||
@@ -43,11 +68,18 @@ shipBeforeDate: options.shipBeforeDate || moment().format('YYYY-MM-DD'), // The date by which the goods or services are shipped. Format: YYYY-MM-DD | ||
merchantAccount: options.merchantAccount, // The merchant account you want to process this payment with. | ||
sessionValidity: options.sessionValidity || moment().add('days', 1).format('YYYY-MM-DD'), // The final time by which a payment needs to have been made. Format: YYYY-MM-DDThh:mm:ssTZD | ||
sessionValidity: options.sessionValidity || moment().add('days', 1).format('YYYY-MM-DDThh:mm:ssZ'), // The final time by which a payment needs to have been made. Format: YYYY-MM-DDThh:mm:ssZ | ||
// Optionals for payment | ||
shopperLocale: options.shopperLocale || 'en_US', // A combination of language code and country code to specify the language used in the session i.e. en_GB. | ||
orderData: null, // A fragment of HTML/text that will be displayed on the HPP (optional) | ||
countryCode: options.countryCode || 'US', // Country code according to ISO_3166-1_alpha-2 standard (optional) | ||
shopperEmail: options.shopperEmail || '', // The e-mailaddress of the shopper (optional) | ||
shopperReference: options.shopperReference || '', // The shopper reference, i.e. the shopper ID (optional) | ||
allowedMethods: options.allowedMethods || '', // Allowed payment methods separeted with a , i.e. "ideal,mc,visa" (optional) | ||
blockedMethods: options.blockedMethods || '', // Blocked payment methods separeted with a , i.e. "ideal,mc,visa" (optional) | ||
offset: options.offset || '', // Numeric value that will be added to the fraud score (optional) | ||
merchantReturnData: options.merchantReturnData || null, // This field willl be passed back as-is on the return URL when the shopper | ||
countryCode: options.countryCode || null, // Country code according to ISO_3166-1_alpha-2 standard (optional) | ||
shopperEmail: options.shopperEmail || null, // The e-mailaddress of the shopper (optional) | ||
shopperReference: options.shopperReference || null, // The shopper reference, i.e. the shopper ID (optional) | ||
allowedMethods: options.allowedMethods || null, // Allowed payment methods separeted with a , i.e. "ideal,mc,visa" (optional) | ||
blockedMethods: options.blockedMethods || null, // Blocked payment methods separeted with a , i.e. "ideal,mc,visa" (optional) | ||
offset: options.offset || null, // Numeric value that will be added to the fraud score (optional) | ||
offerEmail: options.offerEmail || null, | ||
shopperStatement: options.shopperStatement || null, | ||
// Signature for payment | ||
merchantSig: null // The HMAC signature used by Adyen to test the validy of the form; | ||
@@ -57,9 +89,18 @@ }; | ||
HPP.prototype.generateHash = function () { | ||
var | ||
hmac, | ||
hmacText; | ||
hmacText, | ||
key; | ||
for (key in this._request) { | ||
if (this._request.hasOwnProperty(key) || this._request[key]) { | ||
hmacText += this._request[key]; | ||
} | ||
} | ||
// Required fields | ||
hmacText = | ||
this._request.paymentAmount + | ||
this._request.paymentAmount + | ||
this._request.currencyCode + | ||
@@ -70,9 +111,13 @@ this._request.shipBeforeDate + | ||
this._request.merchantAccount + | ||
this._request.sessionValidity + | ||
this._request.shopperEmail + | ||
this._request.shopperReference + | ||
this._request.allowedMethods + | ||
this._request.blockedMethods + | ||
this._request.offset; | ||
this._request.sessionValidity; | ||
// Optional fields | ||
hmacText += this._request.shopperEmail || ''; | ||
hmacText += this._request.shopperReference || ''; | ||
hmacText += this._request.allowedMethods || ''; | ||
hmacText += this._request.blockedMethods || ''; | ||
hmacText += this._request.shopperStatement || ''; | ||
hmacText += this._request.merchantReturnData || ''; | ||
hmacText += this._request.offset || ''; | ||
hmac = crypto.createHmac('sha1', this._HMACKey); | ||
@@ -105,3 +150,3 @@ hmac.update(hmacText); | ||
for (key in _this._request) { | ||
if (_this._request.hasOwnProperty(key)) { | ||
if (_this._request.hasOwnProperty(key) && _this._request[key]) { | ||
requestUrl += '&' + key + '=' + encodeURIComponent(_this._request[key]); | ||
@@ -108,0 +153,0 @@ } |
{ | ||
"name": "adyen", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "NodeJS module for the Adyen payment provider", | ||
@@ -5,0 +5,0 @@ "main": "./lib/adyen", |
@@ -5,3 +5,3 @@ adyen | ||
npm module for the Adyen Payment service | ||
Non official npm module for the Adyen Payment service. | ||
@@ -12,4 +12,12 @@ | ||
$ npm install adyen | ||
## Example for HPP | ||
## What is HPP? | ||
**Adyen Hosted Payment Pages (HPPs)** | ||
For more information please check the Adyen's documenation | ||
http://www.adyen.com/developers/documentation/ | ||
## Example for the HPP payment | ||
// Init payment | ||
@@ -23,20 +31,25 @@ var | ||
HMACKey: 'YourHMAC_Key', | ||
merchantReference: 'DummyPaymentID', // optional, | ||
// default: 'PAYMENT-YYYY-MM-DDThh:mm:ssTZD' | ||
// Required for the payment | ||
merchantReference: 'DummyPaymentID', // optional (lib do this) | ||
// default: 'PAYMENT-YYYY-MM-DDThh:mm:ssTZD' | ||
paymentAmount: 100, // EUR 1,00 = 100 | ||
currencyCode: 'EUR', // optional, default: 'EUR' | ||
currencyCode: 'EUR', // optional (lib do this), default: 'EUR' | ||
shipBeforeDate: 2014-01-25 // 'YYYY-MM-DD' | ||
skinCode: 'YourSkinCode', | ||
merchantAccount: 'YourMerchantAccountName', | ||
sessionValidity: 'YYYY-MM-DD', // optional, default: 24h | ||
sessionValidity: 'YYYY-MM-DDThh:mm:ssZ', // optional (lib do this), default: 24h | ||
// Optional for the payment | ||
shopperLocale: 'nl_NL', // optional: 'en_US' | ||
orderData: 'XY 1 year subscription', // optional: '' | ||
countryCode: 'NL' // optional: 'US' | ||
// shopperReference // optional: check the Adyen documentation | ||
orderData: 'XY 1 year subscription', // optional | ||
merchantReturnData: '', // optional | ||
countryCode: 'NL', // optional | ||
shopperEmail: 'test@test.com', // optional | ||
shopperReference: 'shopperID' // optional | ||
// allowedMethods // optional: check the Adyen documentation | ||
// blockedMethods // optional: check the Adyen documentation | ||
// offset // optional: check the Adyen documentation | ||
// offerEmail // optional: check the Adyen documentation | ||
// shopperStatement: '' // optional | ||
}); | ||
@@ -55,4 +68,32 @@ | ||
}); | ||
## Example for the HPP validation | ||
// Init validator | ||
// Use the decodeURIComponent() values | ||
var | ||
ValidateHPP = require('adyen').ValidateHPP; | ||
validateHPP = new ValidateHPP({ | ||
HMACKey: 'YourHMAC_Key', | ||
// Required for the validation | ||
skinCode: 'SkinCode From the callback url', | ||
authResult: 'STATUS From the callback url', | ||
pspReference: 'pspReference From the callback url', | ||
merchantReference: 'merchantReference From the callback url', | ||
merchantSig: 'merchantSig From the callback url' | ||
// Optional for the validation | ||
merchantReturnData: '' // optional | ||
}); | ||
// true if valid | ||
var isValid = validateHPP.validatePayment(); | ||
console.log(isValid); | ||
## TODO | ||
- custom HPP payment | ||
- add more payment method |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41238
20
184
96