added notifyShopper endpoint to recurring API service

This commit is contained in:
wouterboe
2021-05-04 13:21:20 +02:00
parent 601e45d6fe
commit 32c40b652d
4 changed files with 103 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* Adyen NodeJS API Library
* Copyright (c) 2020 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
export const notifyShopperSuccess = {
"message": "Request Processed Successfully",
"resultCode": "Success",
"shopperNotificationReference": "9915003646742627",
"storedPaymentMethodId": "8415995487234100",
"pspReference": "9915003646742627",
"reference": "Example reference",
"displayedReference": "Example displayed reference"
};

View File

@@ -21,6 +21,7 @@ import nock from "nock";
import { createClient } from "../__mocks__/base";
import { disableSuccess } from "../__mocks__/recurring/disableSuccess";
import { listRecurringDetailsSuccess } from "../__mocks__/recurring/listRecurringDetailsSuccess";
import { notifyShopperSuccess } from "../__mocks__/recurring/notifyShopperSuccess";
import RecurringService from "../services/recurring";
import Client from "../client";
import { paymentsSuccess } from "../__mocks__/checkout/paymentsSuccess";
@@ -32,7 +33,8 @@ import {
ScheduleAccountUpdaterResult,
DisableRequest,
RecurringDetailsRequest,
Recurring
Recurring,
NotifyShopperRequest
} from "../typings/recurring/models";
const createRecurringDetailsRequest = (): RecurringDetailsRequest => {
@@ -103,6 +105,32 @@ describe("Recurring", (): void => {
}
});
test.each([isCI, true])("should send pre-debit Notification, isMock %p", async (isMock): Promise<void> => {
!isMock && nock.restore();
scope.post("/notifyShopper")
.reply(200, notifyShopperSuccess);
const notifyShopperRequest: NotifyShopperRequest = {
merchantAccount: process.env.ADYEN_MERCHANT!,
shopperReference: "shopperReference",
storedPaymentMethodId: "8415995487234100",
amount: {
currency: "INR",
value: 1000
},
billingDate: "2021-03-16",
reference: "Example reference",
displayedReference: "Example displayed reference"
};
try {
const result = await recurring.notifyShopper(notifyShopperRequest);
expect(result).toBeTruthy();
} catch (e) {
fail(e.message);
}
});
// TODO: register account for AccountUpdater and unmock test
test.each([true])("should schedule account updater, isMock: %p", async (isMock): Promise<void> => {

View File

@@ -23,25 +23,30 @@ import Service from "../service";
import Disable from "./resource/recurring/disable";
import ListRecurringDetails from "./resource/recurring/listRecurringDetails";
import ScheduleAccountUpdater from "./resource/recurring/scheduleAccountUpdater";
import NotifyShopper from "./resource/recurring/notifyShopper";
import {
RecurringDetailsRequest,
RecurringDetailsResult,
DisableRequest,
DisableResult,
ScheduleAccountUpdaterRequest,
ScheduleAccountUpdaterResult
ScheduleAccountUpdaterResult,
NotifyShopperRequest,
NotifyShopperResult
} from "../typings/recurring/models";
class Recurring extends Service {
private readonly _listRecurringDetails: ListRecurringDetails;
private readonly _disable: Disable;
private readonly _scheduleAccountUpdater: ScheduleAccountUpdater;
private readonly _notifyShopper: NotifyShopper
public constructor(client: Client) {
super(client);
this._listRecurringDetails = new ListRecurringDetails(this);
this._disable = new Disable(this);
this._scheduleAccountUpdater = new ScheduleAccountUpdater(this);
this._notifyShopper = new NotifyShopper(this);
}
public listRecurringDetails(request: RecurringDetailsRequest): Promise<RecurringDetailsResult> {
@@ -64,6 +69,13 @@ class Recurring extends Service {
request,
);
}
public notifyShopper(request: NotifyShopperRequest): Promise<NotifyShopperResult> {
return getJsonResponse<NotifyShopperRequest, NotifyShopperResult>(
this._notifyShopper,
request
);
}
}
export default Recurring;

View File

@@ -0,0 +1,33 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* Adyen NodeJS API Library
* Copyright (c) 2020 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*/
import Client from "../../../client";
import Service from "../../../service";
import Resource from "../../resource";
class NotifyShopper extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.endpoint}/pal/servlet/Recurring/${Client.RECURRING_API_VERSION}/notifyShopper`,
);
}
}
export default NotifyShopper;