Comparing version 1.0.9 to 1.1.0
@@ -69,2 +69,6 @@ import { Address, InvoiceAddress } from './address'; | ||
/** | ||
* The TH-code of the terminal | ||
*/ | ||
terminalId?: string; | ||
/** | ||
* The description of the transaction. | ||
@@ -71,0 +75,0 @@ */ |
@@ -69,2 +69,4 @@ "use strict"; | ||
data['paymentOptionSubId'] = this.bankId; | ||
if (this.terminalId) | ||
data['paymentOptionSubId'] = this.terminalId; | ||
if (this.testMode) | ||
@@ -71,0 +73,0 @@ data['testMode'] = 1; |
import { Observable } from 'rxjs/Observable'; | ||
import { TransactionStatus } from './result/instore/transactionStatus'; | ||
import { Terminal } from './result/instore/getTerminals'; | ||
import { Status } from './result/instore/status'; | ||
import { Receipt } from './result/instore/receipt'; | ||
import 'rxjs/add/operator/map'; | ||
export declare class Instore { | ||
@@ -10,2 +12,4 @@ static getTerminals(): Observable<Terminal>; | ||
static getReceipt(hash: string): Observable<Receipt>; | ||
private static pollTransactionStatus(observable, statusUrl); | ||
static getTransactionStatus(statusUrl: string): Observable<TransactionStatus>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Observable_1 = require("rxjs/Observable"); | ||
var transactionStatus_1 = require("./result/instore/transactionStatus"); | ||
var getTerminals_1 = require("./result/instore/getTerminals"); | ||
var request = require("request"); | ||
var api_1 = require("./api/api"); | ||
require("rxjs/add/operator/map"); | ||
var Instore = /** @class */ (function () { | ||
@@ -89,4 +92,32 @@ function Instore() { | ||
}; | ||
Instore.pollTransactionStatus = function (observable, statusUrl) { | ||
var _this = this; | ||
request.get({ | ||
url: statusUrl, | ||
headers: { 'Content-Type': 'application/json' } | ||
}, function (error, response, body) { | ||
if (error) | ||
return observable.error(error); | ||
try { | ||
body = JSON.parse(body); | ||
var status = new transactionStatus_1.TransactionStatus(body); | ||
if (status.isFinal) { | ||
observable.next(status); | ||
return observable.complete(); | ||
} | ||
_this.pollTransactionStatus(observable, statusUrl); | ||
} | ||
catch (e) { | ||
return observable.error(e); | ||
} | ||
}); | ||
}; | ||
Instore.getTransactionStatus = function (statusUrl) { | ||
var _this = this; | ||
return Observable_1.Observable.create(function (observable) { | ||
_this.pollTransactionStatus(observable, statusUrl); | ||
}); | ||
}; | ||
return Instore; | ||
}()); | ||
exports.Instore = Instore; |
@@ -12,3 +12,8 @@ export declare class StartResult { | ||
paymentReference: string; | ||
/** | ||
* Hash to fetch the status or receipt from the terminal | ||
*/ | ||
terminalHash?: string; | ||
terminalStatusUrl?: string; | ||
constructor(data: any); | ||
} |
@@ -5,6 +5,10 @@ "use strict"; | ||
function StartResult(data) { | ||
this.transactionId = data.transactionId; | ||
this.paymentURL = data.paymentURL; | ||
this.popupAllowed = data.popupAllowed; | ||
this.paymentReference = data.paymentReference; | ||
this.transactionId = data.transaction.transactionId; | ||
this.paymentURL = data.transaction.paymentURL; | ||
this.popupAllowed = data.transaction.popupAllowed; | ||
this.paymentReference = data.transaction.paymentReference; | ||
if (data.terminal) { | ||
this.terminalHash = data.terminal.hash; | ||
this.terminalStatusUrl = data.terminal.statusUrl; | ||
} | ||
} | ||
@@ -11,0 +15,0 @@ return StartResult; |
@@ -6,39 +6,37 @@ "use strict"; | ||
Paynl.Config.setServiceId('SL-0123-4567'); | ||
// Get the terminals by calling getTerminals | ||
var terminalId = "TH-0123-4567"; | ||
// First we need to start a transaction | ||
// Start transaction and send to the terminal | ||
Paynl.Transaction.start({ | ||
amount: 0.01, | ||
paymentMethodId: 1729, | ||
paymentMethodId: 1927, | ||
//returnUrl and ipAddres make no sense for instore payments, but are mandatory | ||
returnUrl: 'not_applicable', | ||
ipAddress: '10.20.30.40' | ||
ipAddress: '10.20.30.40', | ||
terminalId: "TH-0123-4567" | ||
}).subscribe( | ||
// the resulting transaction will be sent to a terminal | ||
function (transaction) { return sendToTerminal(transaction.transactionId, terminalId); }); | ||
function sendToTerminal(transactionId, terminalId) { | ||
var lastStatus = null; | ||
Paynl.Instore.payment(transactionId, terminalId).subscribe( | ||
//this gets called every 3 seconds | ||
function (status) { | ||
//save the last status so we can access it in the complete function | ||
lastStatus = status; | ||
console.log(status.state + ' Percentage: ' + status.percentage); | ||
}, function (error) { return console.trace(error); }, function () { | ||
// if the transaction has reached a final state this function gets called | ||
if (lastStatus.state == 'approved') { | ||
// fetch the receipt of the transaction | ||
fetchReceipt(lastStatus.hash); | ||
} | ||
else { | ||
console.log('Payment was not completed'); | ||
} | ||
//when the transaction is started, get the status | ||
function (transaction) { | ||
return getStatus(transaction.terminalStatusUrl); | ||
} | ||
); | ||
function getStatus(statusUrl) { | ||
Paynl.Instore.getTransactionStatus(statusUrl).subscribe(function (status) { | ||
console.log("isFinal: ", status.isFinal); | ||
console.log("status: ", status.status); | ||
console.log("txId: ", status.txId); | ||
console.log("terminal: ", status.terminal); | ||
console.log("ssai: ", status.ssai); | ||
console.log("isCanceled: ", status.isCanceled); | ||
console.log("isApproved: ", status.isApproved); | ||
console.log("isError: ", status.isError); | ||
console.log("needsSignature: ", status.needsSignature); | ||
console.log("amount: ", status.amount); | ||
console.log("approvalId: ", status.approvalId); | ||
console.log("carBrandIdentifier: ", status.cardBrandIdentifier); | ||
console.log("cardBrandLabelName: ", status.cardBrandLabelName); | ||
console.log("incidentCode: ", status.incidentCode); | ||
console.log("incidentCodeText: ", status.incidentCodeText); | ||
console.log("receipt: ", status.receipt); | ||
}, function (error) { return console.error(error); }, function () { | ||
console.log("Completed"); | ||
}); | ||
} | ||
function fetchReceipt(hash) { | ||
Paynl.Instore.getReceipt(hash).subscribe(function (receipt) { | ||
console.log(receipt.receipt); | ||
}, function (error) { | ||
console.trace(error); | ||
}); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Paynl = require("../../index"); | ||
Paynl.Config.setApiToken('Your-api-token'); | ||
Paynl.Config.setServiceId('SL-0123-4567'); | ||
Paynl.Config.setApiToken('babaa5749268116614797f8620309cecee2022a5'); | ||
Paynl.Config.setServiceId('SL-4241-3001'); | ||
Paynl.Transaction.start({ | ||
@@ -7,0 +7,0 @@ amount: 20, |
@@ -33,3 +33,3 @@ "use strict"; | ||
} | ||
api_1.Api.post('transaction', 'start', _this.version, startData.getForApi()).map(function (result) { return new start_1.StartResult(result.transaction); }).subscribe(function (result) { return observable.next(result); }, function (error) { return observable.error(error); }, function () { return observable.complete(); }); | ||
api_1.Api.post('transaction', 'start', _this.version, startData.getForApi()).map(function (result) { return new start_1.StartResult(result); }).subscribe(function (result) { return observable.next(result); }, function (error) { return observable.error(error); }, function () { return observable.complete(); }); | ||
}); | ||
@@ -62,5 +62,5 @@ }; | ||
}; | ||
Transaction.version = 5; | ||
Transaction.version = 8; | ||
return Transaction; | ||
}()); | ||
exports.Transaction = Transaction; |
{ | ||
"name": "paynl-sdk", | ||
"version": "1.0.9", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -20,9 +20,11 @@ "type": "git", | ||
"dependencies": { | ||
"dateformat": "^3.0.3", | ||
"request": "^2.85.0", | ||
"rxjs": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/dateformat": "^1.0.1", | ||
"@types/es6-shim": "^0.31.32", | ||
"@types/request": "0.0.32", | ||
"dateformat": "^1.0.12", | ||
"request": "^2.75.0", | ||
"rxjs": "^5.0.0-rc.1" | ||
"@types/es6-shim": "^0.31.36", | ||
"@types/request": "^2.47.0" | ||
} | ||
} |
111
README.md
@@ -123,35 +123,90 @@ # Pay.nl NodeJS SDK | ||
### Sending a transaction to a terminal | ||
### Starting an instore transaction | ||
An instore transaction is started in the same way as a normal transaction with the addition of a terminalId. | ||
After the transaction has been started, you can use the terminalStatusUrl to get the status of the transaction. | ||
First you need to start a transaction. | ||
After the transaction is started and you have a transactionId, you can send the transaction to the terminal. | ||
You can get the terminalId from the example above. | ||
```javascript | ||
var lastStatus = null; | ||
Paynl.Instore.payment(transactionId, terminalId).subscribe( | ||
//this gets called every 3 seconds | ||
status => { | ||
//save the last status so we can access it in the complete function | ||
lastStatus = status; | ||
console.log(status.state + ' Percentage: ' + status.percentage); | ||
}, | ||
error => console.trace(error), | ||
() => { | ||
// if the transaction has reached a final state this function gets called | ||
if (lastStatus.state == 'approved') { | ||
// fetch the receipt of the transaction | ||
Paynl.Instore.getReceipt(hash).subscribe(receipt => { | ||
console.log(receipt.receipt); | ||
}, error => { | ||
console.trace(error); | ||
}); | ||
} else { | ||
console.log('Payment was not completed'); | ||
} | ||
// Start transaction and send to the terminal | ||
Paynl.Transaction.start({ | ||
amount: 0.01, | ||
paymentMethodId: 1927, | ||
//returnUrl and ipAddres make no sense for instore payments, but are mandatory | ||
returnUrl: "not_applicable", | ||
ipAddress: "10.20.30.40", | ||
terminalId: "TH-0123-4567" | ||
}).subscribe( | ||
//when the transaction is started, get the status | ||
function (transaction) { | ||
getStatus(transaction.terminalStatusUrl); | ||
} | ||
); | ||
function getStatus(statusUrl) { | ||
Paynl.Instore.getTransactionStatus(statusUrl).subscribe(function (status) { | ||
console.log("isFinal: ", status.isFinal); | ||
console.log("status: ", status.status); | ||
console.log("txId: ", status.txId); | ||
console.log("terminal: ", status.terminal); | ||
console.log("ssai: ", status.ssai); | ||
console.log("isCanceled: ", status.isCanceled); | ||
console.log("isApproved: ", status.isApproved); | ||
console.log("isError: ", status.isError); | ||
console.log("needsSignature: ", status.needsSignature); | ||
console.log("amount: ", status.amount); | ||
console.log("approvalId: ", status.approvalId); | ||
console.log("carBrandIdentifier: ", status.cardBrandIdentifier); | ||
console.log("cardBrandLabelName: ", status.cardBrandLabelName); | ||
console.log("incidentCode: ", status.incidentCode); | ||
console.log("incidentCodeText: ", status.incidentCodeText); | ||
console.log("receipt: ", status.receipt); | ||
}, function (error) { | ||
console.error(error); | ||
}, function () { | ||
console.log("Completed"); | ||
}); | ||
} | ||
``` | ||
## Direct Debit (Incasso) | ||
### Creating a new Direct Debit | ||
This SDK can also add direct debit transactions. | ||
Only amount, bankaccountHolder and bankaccountNumber are mandatory, the rest of the arguments are optional. | ||
```javascript | ||
Paynl.DirectDebit.add({ | ||
amount: 0.01, | ||
bankaccountHolder: "N Name", | ||
bankaccountNumber: "NL00RABO0000012345678", | ||
// optional | ||
bankaccountBic: "RABONL2U", | ||
processDate: new Date("2018-03-01"), | ||
description: "Uw omschrijving", | ||
ipAddress: "192.168.10.1", | ||
email: "a@a.nl", | ||
promotorId: 1234, | ||
tool: "tool", | ||
info: "info", | ||
object: "object", | ||
extra1: "extra1", | ||
extra2: "extra2", | ||
extra3: "extra3", | ||
currency: "EUR", | ||
exchangeUrl: "https://your-exchange.url", | ||
}).subscribe(function (mandateId) { | ||
console.log("The mandateId is: " + mandateId); | ||
}, function (error) { | ||
console.error("Error " + error); | ||
}); | ||
``` | ||
### Fetching a Direct Debit transaction | ||
Fetch a DirectDebit transaction to fetch the status. | ||
```javascript | ||
Paynl.DirectDebit.get('IO-5289-5134-1580').subscribe(function (transaction) { | ||
console.log(transaction); | ||
}); | ||
``` |
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
101445
3
86
1898
212
3
+ Addeddateformat@3.0.3(transitive)
- Removed@types/dateformat@^1.0.1
- Removed@types/es6-shim@^0.31.32
- Removed@types/request@0.0.32
- Removed@types/dateformat@1.0.4(transitive)
- Removed@types/es6-shim@0.31.45(transitive)
- Removed@types/form-data@2.5.0(transitive)
- Removed@types/node@22.7.4(transitive)
- Removed@types/request@0.0.32(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddateformat@1.0.12(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedform-data@4.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedundici-types@6.19.8(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
Updateddateformat@^3.0.3
Updatedrequest@^2.85.0
Updatedrxjs@^5.0.0