[PW-7765] add create/disablePermit and simple UT (#1082)

* add create/disablePermit and simple UT

* Add serializer for Date objects and quick test

Co-authored-by: Michael Paul <michael@michaelpaul.com.br>
This commit is contained in:
jillingk
2023-01-19 16:57:26 +01:00
committed by GitHub
parent 316542a166
commit bf1e643973
16 changed files with 457 additions and 151 deletions

View File

@@ -6,6 +6,9 @@ import { notifyShopperSuccess } from "../__mocks__/recurring/notifyShopperSucces
import RecurringService from "../services/recurring";
import Client from "../client";
import { recurring } from "../typings";
import {Permit} from "../typings/recurring/permit";
import {CreatePermitRequest} from "../typings/recurring/createPermitRequest";
import {ObjectSerializer} from "../typings/recurring/models";
const createRecurringDetailsRequest = (): recurring.RecurringDetailsRequest => {
return {
@@ -115,4 +118,57 @@ describe("Recurring", (): void => {
fail(e);
}
});
test("should do a createPermit request", async (): Promise<void> => {
const createPermitResultSuccess: recurring.CreatePermitResult = {
pspReference: "1234567890"
};
scope.post("/createPermit")
.reply(200, createPermitResultSuccess);
const permit: Permit = {
validTillDate: new Date("2022-03-25"),
partnerId: "partnerID"
};
const request: recurring.CreatePermitRequest = {
permits: [permit],
merchantAccount: process.env.ADYEN_MERCHANT!,
shopperReference: "shopperRef",
recurringDetailReference: "recurringRef",
};
const serializedRequest: CreatePermitRequest = ObjectSerializer.serialize(request, "CreatePermitRequest");
expect(serializedRequest.permits[0].validTillDate?.toString()).toBe("2022-03-25T00:00:00.000Z");
try {
const result = await recurringService.createPermit(request);
expect(result).toBeTruthy();
} catch (e) {
fail(e);
}
});
test("should do a disablePermit request", async (): Promise<void> => {
const disablePermitResultSuccess: recurring.DisablePermitResult = {
pspReference: "1234567890",
status: "disabled",
};
scope.post("/disablePermit")
.reply(200, disablePermitResultSuccess);
const request: recurring.DisablePermitRequest = {
merchantAccount: process.env.ADYEN_MERCHANT!,
token: "permitToken"
};
try {
const result = await recurringService.disablePermit(request);
expect(result).toBeTruthy();
} catch (e) {
fail(e);
}
});
});

View File

@@ -1,10 +1,6 @@
import Client from "../client";
import getJsonResponse from "../helpers/getJsonResponse";
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,
@@ -13,50 +9,79 @@ import {
ScheduleAccountUpdaterRequest,
ScheduleAccountUpdaterResult,
NotifyShopperRequest,
NotifyShopperResult
NotifyShopperResult,
CreatePermitRequest,
CreatePermitResult,
DisablePermitRequest,
DisablePermitResult, ObjectSerializer
} from "../typings/recurring/models";
import RecurringResource from "./resource/RecurringResource";
class Recurring extends Service {
private readonly _listRecurringDetails: ListRecurringDetails;
private readonly _disable: Disable;
private readonly _scheduleAccountUpdater: ScheduleAccountUpdater;
private readonly _notifyShopper: NotifyShopper;
private readonly _listRecurringDetails: RecurringResource;
private readonly _disable: RecurringResource;
private readonly _scheduleAccountUpdater: RecurringResource;
private readonly _notifyShopper: RecurringResource;
private readonly _createPermit: RecurringResource;
private readonly _disablePermit: RecurringResource;
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);
this._listRecurringDetails = new RecurringResource(this, "/listRecurringDetails");
this._disable = new RecurringResource(this, "/disable");
this._scheduleAccountUpdater = new RecurringResource(this, "/scheduleAccountUpdater");
this._notifyShopper = new RecurringResource(this, "/notifyShopper");
this._createPermit = new RecurringResource(this, "/createPermit");
this._disablePermit = new RecurringResource(this, "/disablePermit")
}
public listRecurringDetails(request: RecurringDetailsRequest): Promise<RecurringDetailsResult> {
public listRecurringDetails(recurringDetailsRequest: RecurringDetailsRequest): Promise<RecurringDetailsResult> {
const request: RecurringDetailsRequest = ObjectSerializer.serialize(recurringDetailsRequest, "RecurringDetailsRequest");
return getJsonResponse<RecurringDetailsRequest, RecurringDetailsResult>(
this._listRecurringDetails,
request,
);
}
public disable(request: DisableRequest): Promise<DisableResult> {
public disable(disableRequest: DisableRequest): Promise<DisableResult> {
const request: DisableRequest = ObjectSerializer.serialize(disableRequest, "DisableRequest");
return getJsonResponse<DisableRequest, DisableResult>(
this._disable,
request,
);
}
public scheduleAccountUpdater(request: ScheduleAccountUpdaterRequest): Promise<ScheduleAccountUpdaterResult> {
public scheduleAccountUpdater(scheduleAccountUpdaterRequest: ScheduleAccountUpdaterRequest): Promise<ScheduleAccountUpdaterResult> {
const request: ScheduleAccountUpdaterRequest = ObjectSerializer.serialize(scheduleAccountUpdaterRequest, "ScheduleAccountUpdaterRequest");
return getJsonResponse<ScheduleAccountUpdaterRequest, ScheduleAccountUpdaterResult>(
this._scheduleAccountUpdater,
request,
);
}
public notifyShopper(request: NotifyShopperRequest): Promise<NotifyShopperResult> {
public notifyShopper(notifyShopperRequest: NotifyShopperRequest): Promise<NotifyShopperResult> {
const request: NotifyShopperRequest = ObjectSerializer.serialize(notifyShopperRequest, "NotifyShopperRequest");
return getJsonResponse<NotifyShopperRequest, NotifyShopperResult>(
this._notifyShopper,
request
);
}
public createPermit(createPermitRequest: CreatePermitRequest): Promise<CreatePermitResult>{
const request: CreatePermitRequest = ObjectSerializer.serialize(createPermitRequest, "CreatePermitRequest");
return getJsonResponse<CreatePermitRequest, CreatePermitResult>(
this._createPermit,
request
);
}
public disablePermit(disablePermitRequest: DisablePermitRequest): Promise<DisablePermitResult>{
const request: DisablePermitRequest = ObjectSerializer.serialize(disablePermitRequest, "DisablePermitRequest");
return getJsonResponse<DisablePermitRequest, DisablePermitResult>(
this._disablePermit,
request
);
}
}
export default Recurring;

View File

@@ -0,0 +1,14 @@
import Client from "../../client";
import Service from "../../service";
import Resource from "../resource";
class RecurringResource extends Resource {
public constructor(service: Service, endpoint: string) {
super(
service,
`${service.client.config.endpoint}/pal/servlet/Recurring/${Client.RECURRING_API_VERSION}${endpoint}` ,
);
}
}
export default RecurringResource;

View File

@@ -1,33 +0,0 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* 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 Disable extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.endpoint}/pal/servlet/Recurring/${Client.RECURRING_API_VERSION}/disable`,
);
}
}
export default Disable;

View File

@@ -1,33 +0,0 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* 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 ListRecurringDetails extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.endpoint}/pal/servlet/Recurring/${Client.RECURRING_API_VERSION}/listRecurringDetails`,
);
}
}
export default ListRecurringDetails;

View File

@@ -1,33 +0,0 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* 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;

View File

@@ -1,33 +0,0 @@
/*
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
* 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 ScheduleAccountUpdater extends Resource {
public constructor(service: Service) {
super(
service,
`${service.client.config.endpoint}/pal/servlet/Recurring/${Client.RECURRING_API_VERSION}/scheduleAccountUpdater`,
);
}
}
export default ScheduleAccountUpdater;

View File

@@ -16,7 +16,7 @@ export class Card {
/**
* The card expiry month. Format: 2 digits, zero-padded for single digits. For example: * 03 = March * 11 = November
*/
'expiryMonth': string;
'expiryMonth'?: string;
/**
* The card expiry year. Format: 4 digits. For example: 2020
*/
@@ -32,7 +32,7 @@ export class Card {
/**
* The card number (4-19 characters). Do not use any separators. When this value is returned in a response, only the last 4 digits of the card number are returned.
*/
'number': string;
'number'?: string;
/**
* The month component of the start date (for some UK debit cards only).
*/

View File

@@ -0,0 +1,58 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { Permit } from './permit';
export class CreatePermitRequest {
/**
* The merchant account identifier, with which you want to process the transaction.
*/
'merchantAccount': string;
/**
* The permits to create for this recurring contract.
*/
'permits': Array<Permit>;
/**
* The recurring contract the new permits will use.
*/
'recurringDetailReference': string;
/**
* The shopper\'s reference to uniquely identify this shopper (e.g. user ID or account ID).
*/
'shopperReference': string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "merchantAccount",
"baseName": "merchantAccount",
"type": "string"
},
{
"name": "permits",
"baseName": "permits",
"type": "Array<Permit>"
},
{
"name": "recurringDetailReference",
"baseName": "recurringDetailReference",
"type": "string"
},
{
"name": "shopperReference",
"baseName": "shopperReference",
"type": "string"
} ];
static getAttributeTypeMap() {
return CreatePermitRequest.attributeTypeMap;
}
}

View File

@@ -0,0 +1,40 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { PermitResult } from './permitResult';
export class CreatePermitResult {
/**
* List of new permits.
*/
'permitResultList'?: Array<PermitResult>;
/**
* A unique reference associated with the request. This value is globally unique; quote it when communicating with us about this request.
*/
'pspReference'?: string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "permitResultList",
"baseName": "permitResultList",
"type": "Array<PermitResult>"
},
{
"name": "pspReference",
"baseName": "pspReference",
"type": "string"
} ];
static getAttributeTypeMap() {
return CreatePermitResult.attributeTypeMap;
}
}

View File

@@ -0,0 +1,39 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
export class DisablePermitRequest {
/**
* The merchant account identifier, with which you want to process the transaction.
*/
'merchantAccount': string;
/**
* The permit token to disable.
*/
'token': string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "merchantAccount",
"baseName": "merchantAccount",
"type": "string"
},
{
"name": "token",
"baseName": "token",
"type": "string"
} ];
static getAttributeTypeMap() {
return DisablePermitRequest.attributeTypeMap;
}
}

View File

@@ -0,0 +1,39 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
export class DisablePermitResult {
/**
* A unique reference associated with the request. This value is globally unique; quote it when communicating with us about this request.
*/
'pspReference'?: string;
/**
* Status of the disable request.
*/
'status'?: string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "pspReference",
"baseName": "pspReference",
"type": "string"
},
{
"name": "status",
"baseName": "status",
"type": "string"
} ];
static getAttributeTypeMap() {
return DisablePermitResult.attributeTypeMap;
}
}

View File

@@ -12,11 +12,18 @@ export * from './address';
export * from './amount';
export * from './bankAccount';
export * from './card';
export * from './createPermitRequest';
export * from './createPermitResult';
export * from './disablePermitRequest';
export * from './disablePermitResult';
export * from './disableRequest';
export * from './disableResult';
export * from './name';
export * from './notifyShopperRequest';
export * from './notifyShopperResult';
export * from './permit';
export * from './permitRestriction';
export * from './permitResult';
export * from './recurring';
export * from './recurringDetail';
export * from './recurringDetailsRequest';
@@ -31,11 +38,18 @@ import { Address } from './address';
import { Amount } from './amount';
import { BankAccount } from './bankAccount';
import { Card } from './card';
import { CreatePermitRequest } from './createPermitRequest';
import { CreatePermitResult } from './createPermitResult';
import { DisablePermitRequest } from './disablePermitRequest';
import { DisablePermitResult } from './disablePermitResult';
import { DisableRequest } from './disableRequest';
import { DisableResult } from './disableResult';
import { Name } from './name';
import { NotifyShopperRequest } from './notifyShopperRequest';
import { NotifyShopperResult } from './notifyShopperResult';
import { Permit } from './permit';
import { PermitRestriction } from './permitRestriction';
import { PermitResult } from './permitResult';
import { Recurring } from './recurring';
import { RecurringDetail } from './recurringDetail';
import { RecurringDetailsRequest } from './recurringDetailsRequest';
@@ -67,11 +81,18 @@ let typeMap: {[index: string]: any} = {
"Amount": Amount,
"BankAccount": BankAccount,
"Card": Card,
"CreatePermitRequest": CreatePermitRequest,
"CreatePermitResult": CreatePermitResult,
"DisablePermitRequest": DisablePermitRequest,
"DisablePermitResult": DisablePermitResult,
"DisableRequest": DisableRequest,
"DisableResult": DisableResult,
"Name": Name,
"NotifyShopperRequest": NotifyShopperRequest,
"NotifyShopperResult": NotifyShopperResult,
"Permit": Permit,
"PermitRestriction": PermitRestriction,
"PermitResult": PermitResult,
"Recurring": Recurring,
"RecurringDetail": RecurringDetail,
"RecurringDetailsRequest": RecurringDetailsRequest,

View File

@@ -0,0 +1,64 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { PermitRestriction } from './permitRestriction';
export class Permit {
/**
* Partner ID (when using the permit-per-partner token sharing model).
*/
'partnerId'?: string;
/**
* The profile to apply to this permit (when using the shared permits model).
*/
'profileReference'?: string;
'restriction'?: PermitRestriction;
/**
* The key to link permit requests to permit results.
*/
'resultKey'?: string;
/**
* The expiry date for this permit.
*/
'validTillDate'?: Date;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "partnerId",
"baseName": "partnerId",
"type": "string"
},
{
"name": "profileReference",
"baseName": "profileReference",
"type": "string"
},
{
"name": "restriction",
"baseName": "restriction",
"type": "PermitRestriction"
},
{
"name": "resultKey",
"baseName": "resultKey",
"type": "string"
},
{
"name": "validTillDate",
"baseName": "validTillDate",
"type": "Date"
} ];
static getAttributeTypeMap() {
return Permit.attributeTypeMap;
}
}

View File

@@ -0,0 +1,43 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { Amount } from './amount';
export class PermitRestriction {
'maxAmount'?: Amount;
'singleTransactionLimit'?: Amount;
/**
* Only a single payment can be made using this permit if set to true, otherwise multiple payments are allowed.
*/
'singleUse'?: boolean;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "maxAmount",
"baseName": "maxAmount",
"type": "Amount"
},
{
"name": "singleTransactionLimit",
"baseName": "singleTransactionLimit",
"type": "Amount"
},
{
"name": "singleUse",
"baseName": "singleUse",
"type": "boolean"
} ];
static getAttributeTypeMap() {
return PermitRestriction.attributeTypeMap;
}
}

View File

@@ -0,0 +1,39 @@
/*
* The version of the OpenAPI document: v68
* Contact: developer-experience@adyen.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
export class PermitResult {
/**
* The key to link permit requests to permit results.
*/
'resultKey'?: string;
/**
* The permit token which is used to make payments by the partner company.
*/
'token'?: string;
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "resultKey",
"baseName": "resultKey",
"type": "string"
},
{
"name": "token",
"baseName": "token",
"type": "string"
} ];
static getAttributeTypeMap() {
return PermitResult.attributeTypeMap;
}
}