Skip to content

Commit

Permalink
upravená platba a návratové hodnoty
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Feb 7, 2013
1 parent f3417bf commit 6289286
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
45 changes: 43 additions & 2 deletions index.js
Expand Up @@ -46,6 +46,13 @@ Paypal.prototype.params = function() {
};
};

/*
Get payment detail
@token {String}
@payer {String} :: PayerID
@callback {Function} :: callback(err, data, invoiceNumber, price);
return {Paypal}
*/
Paypal.prototype.detail = function(token, payer, callback) {

if (typeof(token.get) !== 'undefined' && typeof(payer) === 'function') {
Expand Down Expand Up @@ -89,20 +96,29 @@ Paypal.prototype.detail = function(token, payer, callback) {
return;
}

callback(null, data, custom[1]);
callback(null, data, custom[0], custom[1]);
});
});

return self;
};

/*
Get payment detail
@invoiceNumber {String}
@amout {Number}
@description {String}
@currency {String} :: EUR, USD
@callback {Function} :: callback(err, url);
return {Paypal}
*/
Paypal.prototype.pay = function(invoiceNumber, amout, description, currency, callback) {

var self = this;
var params = self.params();

params.PAYMENTACTION = 'Sale';
params.AMT = amout.toString().replace(',', '.');
params.AMT = prepareNumber(amout);
params.RETURNURL = self.returnUrl;
params.CANCELURL = self.cancelUrl;
params.DESC = description;
Expand Down Expand Up @@ -131,6 +147,14 @@ Paypal.prototype.pay = function(invoiceNumber, amout, description, currency, cal
return self;
};

/*
Internal function
@url {String}
@method {String}
@data {String}
@callback {Function} :: callback(err, data);
return {Paypal}
*/
Paypal.prototype.request = function(url, method, data, callback) {

var self = this;
Expand Down Expand Up @@ -184,6 +208,23 @@ Paypal.prototype.request = function(url, method, data, callback) {
return self;
};

function prepareNumber(num, doubleZero) {
var str = num.toString().replace(',', '.');

var index = str.indexOf('.');
if (index > -1) {
var len = str.substring(index + 1).length;
if (len === 1)
str += '0';
if (len > 2)
str = str.substring(0, index + 3);
} else {
if (doubleZero || true)
str += '.00';
}
return str;
}

exports.version = 1002;
exports.Paypal = Paypal;
exports.init = function(username, password, signature, returnUrl, cancelUrl, debug) {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Expand Up @@ -32,12 +32,12 @@ paypal.pay('20130001', 123.23, 'iPad', 'EUR', function(err, url) {
response.redirect(url);
});

// result
// result in GET method
// paypal.detail('token', 'PayerID', callback);
// or
// paypal.detail(partialjs.controller, callback);

paypal.detail('EC-788441863R616634K', '9TM892TKTDWCE', function(err, data) {
paypal.detail('EC-788441863R616634K', '9TM892TKTDWCE', function(err, data, invoiceNumber) {

if (err) {
console.log(err);
Expand Down

0 comments on commit 6289286

Please sign in to comment.