Socket
Socket
Sign inDemoInstall

paynl-sdk

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paynl-sdk - npm Package Compare versions

Comparing version 1.0.9 to 1.1.0

lib/api/api.js.map

4

lib/datatypes/transaction-start.d.ts

@@ -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);
}

12

lib/result/transaction/start.js

@@ -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"
}
}

@@ -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);
});
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc