diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ab0f1..5c0ee97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index f094530..0039acb 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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-####-####-####'); ``` diff --git a/UPGRADING.md b/UPGRADING.md index c609252..f916f1a 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -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. diff --git a/examples/directDebit.ts b/examples/directDebit.ts index 2b2fa7b..ae6ff09 100644 --- a/examples/directDebit.ts +++ b/examples/directDebit.ts @@ -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', }); diff --git a/package-lock.json b/package-lock.json index 9f005b7..c721148 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "paynl-sdk", - "version": "1.2.0", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "paynl-sdk", - "version": "1.2.0", + "version": "2.0.0", "license": "MIT", "devDependencies": { "@eslint/js": "^9.33.0", diff --git a/package.json b/package.json index 69e3b01..c644fab 100644 --- a/package.json +++ b/package.json @@ -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"