Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

upravená platba a návratové hodnoty

  • Loading branch information...
commit 6289286e821386e6759d5ad351269623ea1de4cc 1 parent f3417bf
@petersirka authored
Showing with 45 additions and 4 deletions.
  1. +43 −2 index.js
  2. +2 −2 readme.md
View
45 index.js
@@ -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') {
@@ -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;
@@ -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;
@@ -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) {
View
4 readme.md
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.