diff --git a/src/endpoints/orders.js b/src/endpoints/orders.js index 53148b902..c7c097aac 100644 --- a/src/endpoints/orders.js +++ b/src/endpoints/orders.js @@ -14,6 +14,11 @@ class OrdersEndpoint extends BaseExtend { Payment(id, body) { return this.request.send(`${this.endpoint}/${id}/payments`, 'POST', body); } + + Transactions(id) { + return this.request.send(`${this.endpoint}/${id}/transactions`, 'GET'); + } + } export default OrdersEndpoint; diff --git a/test/factories.js b/test/factories.js index 269e3055e..77f4031de 100644 --- a/test/factories.js +++ b/test/factories.js @@ -161,3 +161,40 @@ export const orderItemsArray = [{ quantity: 1, product_id: 'product-2', }]; + +export const orderTransactionsArray = [{ + id: 'transaction-1', + type: 'transaction', + reference: 'ch_1AzkYiFnpfya5sMz8gVp6Ds6', + gateway: 'stripe', + amount: 159800, + currency: 'NOK', + 'transaction-type': 'purchase', + status: 'complete', + relationships: { + order: { + data: { + type: 'order', + id: 'c5530906-7b68-42ee-99c3-68cfebdcd749', + }, + }, + }, +}, +{ + id: 'transaction-2', + type: 'transaction', + reference: 'ch_1AzkYiFnpfya5sMz8gVp6Ds6', + gateway: 'stripe', + amount: 159800, + currency: 'NOK', + 'transaction-type': 'purchase', + status: 'complete', + relationships: { + order: { + data: { + type: 'order', + id: 'c5530906-7b68-42ee-99c3-68cfebdcd749', + }, + }, + }, +}]; diff --git a/test/unit/orders.js b/test/unit/orders.js index a735e9741..29b083c42 100644 --- a/test/unit/orders.js +++ b/test/unit/orders.js @@ -1,7 +1,7 @@ import { assert } from 'chai'; import nock from 'nock'; import { gateway as MoltinGateway } from '../../src/moltin'; -import { ordersArray as orders, orderItemsArray as orderItems } from '../factories'; +import { ordersArray as orders, orderItemsArray as orderItems, orderTransactionsArray as orderTransactions } from '../factories'; const apiUrl = 'https://api.moltin.com/v2'; @@ -64,6 +64,24 @@ describe('Moltin orders', () => { }); }); + it('should return an array of transactions from an order', () => { + // Intercept the API request + nock(apiUrl, { + reqHeaders: { + Authorization: 'a550d8cbd4a4627013452359ab69694cd446615a', + 'Content-Type': 'application/json', + }, + }) + .get('/orders/order-1/transactions') + .reply(200, orderTransactions[0]); + + return Moltin.Orders.Transactions(orders[0].id) + .then((response) => { + assert.propertyVal(response, 'id', 'transaction-1'); + assert.nestedPropertyVal(response, 'relationships.order.data.id', 'c5530906-7b68-42ee-99c3-68cfebdcd749'); + }); + }); + it('should complete a payment for an order', () => { // Intercept the API request nock(apiUrl, {