Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [2.0.0]

### Changed
- Refactored DirectDebit to new REST API.

### Removed
- Deprecated endpoints and dependencies, see UPGRADING.md for details.

## [1.2.0]

### Added
Expand Down
186 changes: 17 additions & 169 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const payNL = createPayNLClient({ apiToken: '***********************************

## Orders

Orders use the new Transaction Gateway Unit API. View the [examples](https://github.com/paynl/nodejs-sdk/tree/master/src/examples/connect) or [online documentation](https://developer.pay.nl/reference/api_create_order-1) for a complete overview of what is possible.
Orders use the new Transaction Gateway Unit API. View the [examples](https://github.com/paynl/nodejs-sdk/tree/master/examples) or [online documentation](https://developer.pay.nl/reference/api_create_order-1) for a complete overview of what is possible.

### Creating an order

Expand Down Expand Up @@ -66,186 +66,34 @@ const order = await payNL.Orders.get(orderId);
const orderStatus = await payNL.Orders.status(orderId);
```

## Basic transactions

> [!IMPORTANT]
> Orders created with the transaction API will not be available in the new transaction gateway unit.
> In the upcoming v2.0 release the `payNL.Transaction` methods will no longer be available. The transaction status endpoint will be kept for backwards compatibility.
> We recommend that you start using orders instead of transactions.

### Getting the available payment methods
This example shows how to fetch a list of the available payment methods.
The method ``` payNL.Paymentmethods.getList() ``` returns an observable array.
For more information about observables see [reactivex.io](http://reactivex.io/rxjs/)

```typescript
payNL.Paymentmethods.getList().forEach(
function(paymentmethod) {
console.log(paymentmethod.id + ' ' + paymentmethod.visibleName);
}
)
.catch(error => {
console.error(error)
});
```
### Starting a transaction
This example shows the minimum required attributes to start a transaction.
The full version with all supported options is located [here](https://github.com/paynl/nodejs-sdk/tree/master/src/samples/transaction/start.ts)

```typescript
payNL.Transaction.start({
//the amount in euro
amount: 19.95,

//we redirect the user back to this url after the payment
returnUrl: "https://my-return-url.com/return",

//the ip address of the user
ipAddress: '10.20.30.40'
})
.subscribe(
function (result) {
//redirect the user to this url to complete the payment
console.log(result.paymentURL);

// the transactionId, use this to fetch the transaction later
console.log(result.transactionId);
},
function (error) {
console.error(error);
}
);
```

### Fetching a transaction
The following example shows how to fetch a transaction.
```typescript
payNL.Transaction.get('123456789X12345e').subscribe(
function(result){
// some examples of what you can do with the result
if (result.isPaid()) {
console.log('The transaction is paid');
// refund a part of the transaction
result.refund({
amount: 0.5,
description: '50 cents refund'
});
}
if (result.isCanceled()) {
console.log('Tranasaction is canceled, restock the items');
}
if (result.isBeingVerified()) {
console.log('Transaction needs to be verified first, possible fraud');
result.decline(); //decline the transaction
result.approve(); //approve the transaction
}
},
function(error){
console.error(error);
}
);
```

## Instore payments (pin)

### Fetching available terminals

Before you can send a transaction, you need to know which terminal to send the transaction to.

```typescript
payNL.Instore.getTerminals()
.forEach(function (terminal) {
console.log(terminal.id + ' ' + terminal.name);
})
.catch(function (error) { return console.error(error); });
```

### 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.

```typescript
// Start transaction and send to the terminal
payNL.Transaction.start({
amount: 0.01,
paymentMethodId: 1927,
//returnUrl and ipAddres are not used for instore payments, but are mandatory
returnUrl: "not_applicable",
ipAddress: "10.20.30.40",
terminalId: "TH-####-####"
}).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("cardBrandIdentifier: ", 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.
This SDK can also add direct debit transactions. In order to do so, you need to create a mandate first.

```typescript
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);
const mandate = await payNL.DirectDebit.createMandate({
amount: { value: 1000, currency: 'EUR' },
description: 'example description',
type: 'FLEXIBLE',
});

const directDebit = await payNL.DirectDebit.add({
mandateId: mandate.code,
processDate: new Date('2025-10-10'),
description: 'Test direct debit',
amount: {
value: 1000,
currency: 'EUR',
},
});
```

### Fetching a Direct Debit transaction

Fetch a DirectDebit transaction to fetch the status.
Fetch a DirectDebit transaction to check the status.

```typescript
payNL.DirectDebit.get('IO-####-####-####').subscribe(function (transaction) {
console.log(transaction);
});
const directDebit = await payNL.DirectDebit.get('IO-####-####-####');
```
20 changes: 20 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable (breaking) changes to this project will be documented in this file.

## From 1.2.0 to 2.0.0

As of version 2.0.0, the SDK can no longer create or update transactions using the old REST API.
All orders need to be created using the new [order API](https://developer.pay.nl/reference/api_create_order-1).
The `payNL.Orders.status()` method still supports fetching the status of a transaction.

To upgrade, all calls to the following methods need to be replaced with new Order API calls or are no longer available:
* `payNL.Transaction.start()`
* `payNL.Transaction.getStatus()`
* `payNL.Transaction.approve()`
* `payNL.Transaction.decline()`
* `payNL.Transaction.refund()`
* `payNL.Transaction.get()`
* `payNL.Instore.getTerminals()`

The following have different in- and outputs:
* `payNL.PaymentMethods.all()` (previously called `payNL.Paymentmethods.getList()`)
* `payNL.DirectDebit.add()`
* `payNL.DirectDebit.get()`

## From 1.1.4 to 1.2.0

Pay.nl is moving from transaction operations to a Transaction Gateway Unit.
Expand Down
2 changes: 1 addition & 1 deletion examples/directDebit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const payNL = createPayNLClient({

const mandate = await payNL.DirectDebit.createMandate({
amount: { value: 1000, currency: 'EUR' },
description: 'Jeroens test',
description: 'example description',
type: 'FLEXIBLE',
});

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "paynl-sdk",
"version": "1.2.0",
"version": "2.0.0",
"repository": {
"type": "git",
"url": "https://github.com/paynl/nodejs-sdk.git"
Expand Down