Skip to content

Commit 99f0d12

Browse files
authored
add query parameters to function arguments (#1304)
* add query parameters to function arguments. applied template checkout only for review * removed code duplication from queryParameters feature * fix code smells * fix code smells on models import statements * include funtionality for Date query parameters. Tested through Transfers unit tests
1 parent 5ac72f0 commit 99f0d12

25 files changed

+359
-164
lines changed

src/__tests__/checkout.spec.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {CheckoutAPI} from "../services";
1313
import HttpClientException from "../httpClient/httpClientException";
1414
import { checkout } from "../typings";
1515
import { IRequest } from "../typings/requestOptions";
16+
import { SessionResultResponse } from "../typings/checkout/sessionResultResponse";
1617

1718
const merchantAccount = process.env.ADYEN_MERCHANT!;
1819
const reference = "Your order number";
@@ -386,8 +387,8 @@ describe("Checkout", (): void => {
386387
originDomains: ["https://www.your-domain.com"],
387388
};
388389

389-
nock(`https://checkout-test.adyen.com`)
390-
.post(`/v71/originKeys`)
390+
nock("https://checkout-test.adyen.com")
391+
.post("/v71/originKeys")
391392
.reply(200, originKeysSuccess);
392393

393394
const originKeysResponse = await checkoutUtility.UtilityApi.originKeys(originKeysRequest);
@@ -521,7 +522,7 @@ describe("Checkout", (): void => {
521522
expect(applePaySessionResponse.data).toEqual("eyJ2Z...");
522523
});
523524

524-
test("Should get stored paymentMethods", async (): Promise<void> => {
525+
test("Should get stored paymentMethods using params in requestOptions", async (): Promise<void> => {
525526
scope.get("/storedPaymentMethods?shopperReference=MYSHOPPERREFERENCE")
526527
.reply(200, {
527528
"merchantAccount": "YOUR_MERCHANT_ACCOUNT",
@@ -536,7 +537,7 @@ describe("Checkout", (): void => {
536537
shopperReference: "MYSHOPPERREFERENCE"
537538
}
538539
};
539-
const getStoredPaymentMethodsResponse = await checkoutService.RecurringApi.getTokensForStoredPaymentDetails(requestOptions);
540+
const getStoredPaymentMethodsResponse = await checkoutService.RecurringApi.getTokensForStoredPaymentDetails(undefined, undefined, requestOptions);
540541
expect(getStoredPaymentMethodsResponse.merchantAccount).toEqual("YOUR_MERCHANT_ACCOUNT");
541542
expect(getStoredPaymentMethodsResponse?.storedPaymentMethods?.length).toBe(1);
542543
});
@@ -550,4 +551,28 @@ describe("Checkout", (): void => {
550551
).resolves.not.toThrowError();
551552

552553
});
554+
555+
test("Should handle request without query parameters for getResultOfPaymentSession", async(): Promise<void> => {
556+
scope.get("/sessions/mySessionIdMock")
557+
.reply(200, {
558+
"id": "CS12345678",
559+
"status": "completed"
560+
});
561+
562+
const resultOfPaymentSessionResponse = await checkoutService.PaymentsApi.getResultOfPaymentSession("mySessionIdMock");
563+
expect(resultOfPaymentSessionResponse.id).toEqual("CS12345678");
564+
expect(resultOfPaymentSessionResponse.status).toEqual(SessionResultResponse.StatusEnum.Completed);
565+
});
566+
567+
test("Should handle query parameters for getResultOfPaymentSession", async(): Promise<void> => {
568+
scope.get("/sessions/mySessionIdMock?sessionResult=sessionResult")
569+
.reply(200, {
570+
"id": "CS12345678",
571+
"status": "completed"
572+
});
573+
574+
const resultOfPaymentSessionResponse = await checkoutService.PaymentsApi.getResultOfPaymentSession("mySessionIdMock", "sessionResult");
575+
expect(resultOfPaymentSessionResponse.id).toEqual("CS12345678");
576+
expect(resultOfPaymentSessionResponse.status).toEqual(SessionResultResponse.StatusEnum.Completed);
577+
});
553578
});

src/__tests__/transfers.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ describe("Transfers", (): void => {
5050
test("should get transaction", async (): Promise<void> => {
5151
scope.get("/transactions/123")
5252
.reply(200, getTransactionSuccess);
53-
const response: transfers.Transaction = await transfersAPI.TransactionsApi.getTransaction("123");
53+
const response: transfers.Transaction = await transfersAPI.TransactionsApi.getTransaction("123",);
5454
expect(response.id).toEqual("IZK7C25U7DYVX03Y");
5555
});
5656

5757
test("should list transactions", async (): Promise<void> => {
58-
scope.get("/transactions")
58+
scope.get("/transactions?balancePlatform=platform&createdSince=2023-12-12T00%3A00%3A00.000Z&createdUntil=2023-12-13T00%3A00%3A00.000Z")
5959
.reply(200, listTransactionsSuccess);
60-
const response: transfers.TransactionSearchResponse = await transfersAPI.TransactionsApi.getAllTransactions();
60+
const response: transfers.TransactionSearchResponse = await transfersAPI.TransactionsApi.getAllTransactions("platform", undefined, undefined, undefined, undefined, new Date("12-12-2023"), new Date("12-13-2023"));
6161
expect(response.data?.length).toEqual(3);
6262
if(response.data && response.data?.length > 0) {
6363
expect(response?.data[0]?.id).toEqual("1VVF0D5U66PIUIVP");

src/services/checkout/classicCheckoutSDKApi.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import getJsonResponse from "../../helpers/getJsonResponse";
1111
import Service from "../../service";
1212
import Client from "../../client";
13-
import { PaymentSetupRequest } from "../../typings/checkout/models";
14-
import { PaymentSetupResponse } from "../../typings/checkout/models";
15-
import { PaymentVerificationRequest } from "../../typings/checkout/models";
16-
import { PaymentVerificationResponse } from "../../typings/checkout/models";
13+
import {
14+
PaymentSetupRequest,
15+
PaymentSetupResponse,
16+
PaymentVerificationRequest,
17+
PaymentVerificationResponse,
18+
ObjectSerializer
19+
} from "../../typings/checkout/models";
1720
import { IRequest } from "../../typings/requestOptions";
1821
import Resource from "../resource";
19-
import { ObjectSerializer } from "../../typings/checkout/models";
2022

2123
export class ClassicCheckoutSDKApi extends Service {
2224

@@ -30,9 +32,8 @@ export class ClassicCheckoutSDKApi extends Service {
3032

3133
/**
3234
* @summary Create a payment session
33-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
3435
* @param paymentSetupRequest {@link PaymentSetupRequest }
35-
* @param requestOptions {@link IRequest.Options}
36+
* @param requestOptions {@link IRequest.Options }
3637
* @return {@link PaymentSetupResponse }
3738
*/
3839
public async paymentSession(paymentSetupRequest: PaymentSetupRequest, requestOptions?: IRequest.Options): Promise<PaymentSetupResponse> {
@@ -49,9 +50,8 @@ export class ClassicCheckoutSDKApi extends Service {
4950

5051
/**
5152
* @summary Verify a payment result
52-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
5353
* @param paymentVerificationRequest {@link PaymentVerificationRequest }
54-
* @param requestOptions {@link IRequest.Options}
54+
* @param requestOptions {@link IRequest.Options }
5555
* @return {@link PaymentVerificationResponse }
5656
*/
5757
public async verifyPaymentResult(paymentVerificationRequest: PaymentVerificationRequest, requestOptions?: IRequest.Options): Promise<PaymentVerificationResponse> {

src/services/checkout/donationsApi.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* The version of the OpenAPI document: v71
3+
*
4+
*
5+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
6+
* https://openapi-generator.tech
7+
* Do not edit this class manually.
8+
*/
9+
10+
import getJsonResponse from "../../helpers/getJsonResponse";
11+
import Service from "../../service";
12+
import Client from "../../client";
13+
import {
14+
DonationPaymentRequest,
15+
DonationPaymentResponse,
16+
ObjectSerializer
17+
} from "../../typings/checkout/models";
18+
import { IRequest } from "../../typings/requestOptions";
19+
import Resource from "../resource";
20+
21+
export class DonationsApi extends Service {
22+
23+
private readonly API_BASEPATH: string = "https://checkout-test.adyen.com/v71";
24+
private baseUrl: string;
25+
26+
public constructor(client: Client){
27+
super(client);
28+
this.baseUrl = this.createBaseUrl(this.API_BASEPATH);
29+
}
30+
31+
/**
32+
* @summary Start a transaction for donations
33+
* @param donationPaymentRequest {@link DonationPaymentRequest }
34+
* @param requestOptions {@link IRequest.Options }
35+
* @return {@link DonationPaymentResponse }
36+
*/
37+
public async donations(donationPaymentRequest: DonationPaymentRequest, requestOptions?: IRequest.Options): Promise<DonationPaymentResponse> {
38+
const endpoint = `${this.baseUrl}/donations`;
39+
const resource = new Resource(this, endpoint);
40+
const request: DonationPaymentRequest = ObjectSerializer.serialize(donationPaymentRequest, "DonationPaymentRequest");
41+
const response = await getJsonResponse<DonationPaymentRequest, DonationPaymentResponse>(
42+
resource,
43+
request,
44+
{ ...requestOptions, method: "POST" }
45+
);
46+
return ObjectSerializer.deserialize(response, "DonationPaymentResponse");
47+
}
48+
}

src/services/checkout/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import { ClassicCheckoutSDKApi } from "./classicCheckoutSDKApi";
11+
import { DonationsApi } from "./donationsApi";
1112
import { ModificationsApi } from "./modificationsApi";
1213
import { OrdersApi } from "./ordersApi";
1314
import { PaymentLinksApi } from "./paymentLinksApi";
@@ -28,6 +29,10 @@ export default class CheckoutAPI extends Service {
2829
return new ClassicCheckoutSDKApi(this.client);
2930
}
3031

32+
public get DonationsApi() {
33+
return new DonationsApi(this.client);
34+
}
35+
3136
public get ModificationsApi() {
3237
return new ModificationsApi(this.client);
3338
}

src/services/checkout/modificationsApi.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@
1010
import getJsonResponse from "../../helpers/getJsonResponse";
1111
import Service from "../../service";
1212
import Client from "../../client";
13-
import { PaymentAmountUpdateRequest } from "../../typings/checkout/models";
14-
import { PaymentAmountUpdateResponse } from "../../typings/checkout/models";
15-
import { PaymentCancelRequest } from "../../typings/checkout/models";
16-
import { PaymentCancelResponse } from "../../typings/checkout/models";
17-
import { PaymentCaptureRequest } from "../../typings/checkout/models";
18-
import { PaymentCaptureResponse } from "../../typings/checkout/models";
19-
import { PaymentRefundRequest } from "../../typings/checkout/models";
20-
import { PaymentRefundResponse } from "../../typings/checkout/models";
21-
import { PaymentReversalRequest } from "../../typings/checkout/models";
22-
import { PaymentReversalResponse } from "../../typings/checkout/models";
23-
import { StandalonePaymentCancelRequest } from "../../typings/checkout/models";
24-
import { StandalonePaymentCancelResponse } from "../../typings/checkout/models";
13+
import {
14+
PaymentAmountUpdateRequest,
15+
PaymentAmountUpdateResponse,
16+
PaymentCancelRequest,
17+
PaymentCancelResponse,
18+
PaymentCaptureRequest,
19+
PaymentCaptureResponse,
20+
PaymentRefundRequest,
21+
PaymentRefundResponse,
22+
PaymentReversalRequest,
23+
PaymentReversalResponse,
24+
StandalonePaymentCancelRequest,
25+
StandalonePaymentCancelResponse,
26+
ObjectSerializer
27+
} from "../../typings/checkout/models";
2528
import { IRequest } from "../../typings/requestOptions";
2629
import Resource from "../resource";
27-
import { ObjectSerializer } from "../../typings/checkout/models";
2830

2931
export class ModificationsApi extends Service {
3032

@@ -38,9 +40,8 @@ export class ModificationsApi extends Service {
3840

3941
/**
4042
* @summary Cancel an authorised payment
41-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
4243
* @param standalonePaymentCancelRequest {@link StandalonePaymentCancelRequest }
43-
* @param requestOptions {@link IRequest.Options}
44+
* @param requestOptions {@link IRequest.Options }
4445
* @return {@link StandalonePaymentCancelResponse }
4546
*/
4647
public async cancelAuthorisedPayment(standalonePaymentCancelRequest: StandalonePaymentCancelRequest, requestOptions?: IRequest.Options): Promise<StandalonePaymentCancelResponse> {
@@ -58,9 +59,8 @@ export class ModificationsApi extends Service {
5859
/**
5960
* @summary Update an authorised amount
6061
* @param paymentPspReference {@link string } The [&#x60;pspReference&#x60;](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/post/payments__resParam_pspReference) of the payment.
61-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
6262
* @param paymentAmountUpdateRequest {@link PaymentAmountUpdateRequest }
63-
* @param requestOptions {@link IRequest.Options}
63+
* @param requestOptions {@link IRequest.Options }
6464
* @return {@link PaymentAmountUpdateResponse }
6565
*/
6666
public async updateAuthorisedAmount(paymentPspReference: string, paymentAmountUpdateRequest: PaymentAmountUpdateRequest, requestOptions?: IRequest.Options): Promise<PaymentAmountUpdateResponse> {
@@ -79,9 +79,8 @@ export class ModificationsApi extends Service {
7979
/**
8080
* @summary Cancel an authorised payment
8181
* @param paymentPspReference {@link string } The [&#x60;pspReference&#x60;](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/post/payments__resParam_pspReference) of the payment that you want to cancel.
82-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
8382
* @param paymentCancelRequest {@link PaymentCancelRequest }
84-
* @param requestOptions {@link IRequest.Options}
83+
* @param requestOptions {@link IRequest.Options }
8584
* @return {@link PaymentCancelResponse }
8685
*/
8786
public async cancelAuthorisedPaymentByPspReference(paymentPspReference: string, paymentCancelRequest: PaymentCancelRequest, requestOptions?: IRequest.Options): Promise<PaymentCancelResponse> {
@@ -100,9 +99,8 @@ export class ModificationsApi extends Service {
10099
/**
101100
* @summary Capture an authorised payment
102101
* @param paymentPspReference {@link string } The [&#x60;pspReference&#x60;](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/post/payments__resParam_pspReference) of the payment that you want to capture.
103-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
104102
* @param paymentCaptureRequest {@link PaymentCaptureRequest }
105-
* @param requestOptions {@link IRequest.Options}
103+
* @param requestOptions {@link IRequest.Options }
106104
* @return {@link PaymentCaptureResponse }
107105
*/
108106
public async captureAuthorisedPayment(paymentPspReference: string, paymentCaptureRequest: PaymentCaptureRequest, requestOptions?: IRequest.Options): Promise<PaymentCaptureResponse> {
@@ -121,9 +119,8 @@ export class ModificationsApi extends Service {
121119
/**
122120
* @summary Refund a captured payment
123121
* @param paymentPspReference {@link string } The [&#x60;pspReference&#x60;](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/post/payments__resParam_pspReference) of the payment that you want to refund.
124-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
125122
* @param paymentRefundRequest {@link PaymentRefundRequest }
126-
* @param requestOptions {@link IRequest.Options}
123+
* @param requestOptions {@link IRequest.Options }
127124
* @return {@link PaymentRefundResponse }
128125
*/
129126
public async refundCapturedPayment(paymentPspReference: string, paymentRefundRequest: PaymentRefundRequest, requestOptions?: IRequest.Options): Promise<PaymentRefundResponse> {
@@ -142,9 +139,8 @@ export class ModificationsApi extends Service {
142139
/**
143140
* @summary Refund or cancel a payment
144141
* @param paymentPspReference {@link string } The [&#x60;pspReference&#x60;](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/post/payments__resParam_pspReference) of the payment that you want to reverse.
145-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
146142
* @param paymentReversalRequest {@link PaymentReversalRequest }
147-
* @param requestOptions {@link IRequest.Options}
143+
* @param requestOptions {@link IRequest.Options }
148144
* @return {@link PaymentReversalResponse }
149145
*/
150146
public async refundOrCancelPayment(paymentPspReference: string, paymentReversalRequest: PaymentReversalRequest, requestOptions?: IRequest.Options): Promise<PaymentReversalResponse> {

src/services/checkout/ordersApi.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
import getJsonResponse from "../../helpers/getJsonResponse";
1111
import Service from "../../service";
1212
import Client from "../../client";
13-
import { BalanceCheckRequest } from "../../typings/checkout/models";
14-
import { BalanceCheckResponse } from "../../typings/checkout/models";
15-
import { CancelOrderRequest } from "../../typings/checkout/models";
16-
import { CancelOrderResponse } from "../../typings/checkout/models";
17-
import { CreateOrderRequest } from "../../typings/checkout/models";
18-
import { CreateOrderResponse } from "../../typings/checkout/models";
13+
import {
14+
BalanceCheckRequest,
15+
BalanceCheckResponse,
16+
CancelOrderRequest,
17+
CancelOrderResponse,
18+
CreateOrderRequest,
19+
CreateOrderResponse,
20+
ObjectSerializer
21+
} from "../../typings/checkout/models";
1922
import { IRequest } from "../../typings/requestOptions";
2023
import Resource from "../resource";
21-
import { ObjectSerializer } from "../../typings/checkout/models";
2224

2325
export class OrdersApi extends Service {
2426

@@ -32,9 +34,8 @@ export class OrdersApi extends Service {
3234

3335
/**
3436
* @summary Create an order
35-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
3637
* @param createOrderRequest {@link CreateOrderRequest }
37-
* @param requestOptions {@link IRequest.Options}
38+
* @param requestOptions {@link IRequest.Options }
3839
* @return {@link CreateOrderResponse }
3940
*/
4041
public async orders(createOrderRequest: CreateOrderRequest, requestOptions?: IRequest.Options): Promise<CreateOrderResponse> {
@@ -51,9 +52,8 @@ export class OrdersApi extends Service {
5152

5253
/**
5354
* @summary Cancel an order
54-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
5555
* @param cancelOrderRequest {@link CancelOrderRequest }
56-
* @param requestOptions {@link IRequest.Options}
56+
* @param requestOptions {@link IRequest.Options }
5757
* @return {@link CancelOrderResponse }
5858
*/
5959
public async cancelOrder(cancelOrderRequest: CancelOrderRequest, requestOptions?: IRequest.Options): Promise<CancelOrderResponse> {
@@ -70,9 +70,8 @@ export class OrdersApi extends Service {
7070

7171
/**
7272
* @summary Get the balance of a gift card
73-
* @param idempotencyKey {@link string } A unique identifier for the message with a maximum of 64 characters (we recommend a UUID).
7473
* @param balanceCheckRequest {@link BalanceCheckRequest }
75-
* @param requestOptions {@link IRequest.Options}
74+
* @param requestOptions {@link IRequest.Options }
7675
* @return {@link BalanceCheckResponse }
7776
*/
7877
public async getBalanceOfGiftCard(balanceCheckRequest: BalanceCheckRequest, requestOptions?: IRequest.Options): Promise<BalanceCheckResponse> {

0 commit comments

Comments
 (0)