-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add saved payment method resources * chore: linting * chore: bump version * fix: update card type value * feat: add payment method notifications * test: add payment method notification tests * refactor: split payment method response types * refactor: use shared card type * feat: add generateAuthToken for customer * chore: update changelog
- Loading branch information
1 parent
3ca6241
commit 0827b17
Showing
50 changed files
with
721 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/__tests__/mocks/notifications/payment-method-deleted.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { IPaymentMethodDeletedNotificationResponse } from '../../../notifications'; | ||
import { type IEventsResponse } from '../../../types'; | ||
|
||
export const PaymentMethodDeletedMock: IEventsResponse<IPaymentMethodDeletedNotificationResponse> = { | ||
event_id: 'evt_01hwz6k64a210xcvsdbg3y4vmr', | ||
event_type: 'payment_method.deleted', | ||
occurred_at: '2024-05-03T12:24:18.826338Z', | ||
notification_id: 'ntf_01hwz6k66fp6cxtxyt6551wv7z', | ||
data: { | ||
id: 'paymtd_01hs8zx6x377xfsfrt2bqsevbw', | ||
customer_id: 'ctm_01hv6y1jedq4p1n0yqn5ba3ky4', | ||
address_id: 'add_01hv8gq3318ktkfengj2r75gfx', | ||
deletion_reason: 'api', | ||
type: 'card', | ||
origin: 'saved_during_purchase', | ||
saved_at: '2024-05-02T02:55:25.198953Z', | ||
updated_at: '2024-05-03T12:24:18.826338Z', | ||
}, | ||
}; | ||
|
||
export const PaymentMethodDeletedMockExpectation = { | ||
data: { | ||
id: 'paymtd_01hs8zx6x377xfsfrt2bqsevbw', | ||
customerId: 'ctm_01hv6y1jedq4p1n0yqn5ba3ky4', | ||
addressId: 'add_01hv8gq3318ktkfengj2r75gfx', | ||
deletionReason: 'api', | ||
type: 'card', | ||
origin: 'saved_during_purchase', | ||
savedAt: '2024-05-02T02:55:25.198953Z', | ||
updatedAt: '2024-05-03T12:24:18.826338Z', | ||
}, | ||
eventId: 'evt_01hwz6k64a210xcvsdbg3y4vmr', | ||
eventType: 'payment_method.deleted', | ||
notificationId: 'ntf_01hwz6k66fp6cxtxyt6551wv7z', | ||
occurredAt: '2024-05-03T12:24:18.826338Z', | ||
}; |
39 changes: 39 additions & 0 deletions
39
src/__tests__/mocks/notifications/payment-method-saved.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { type IEventsResponse, type IPaymentMethodResponse } from '../../../types'; | ||
|
||
export const PaymentMethodSavedMock: IEventsResponse<IPaymentMethodResponse> = { | ||
event_id: 'evt_01hwvkmsge7bhq1a31s35784zt', | ||
event_type: 'payment_method.saved', | ||
occurred_at: '2024-05-02T02:55:25.198953Z', | ||
notification_id: 'ntf_01hwvkmsknrgqw4z1598qw4ypt', | ||
data: { | ||
id: 'paymtd_01hs8zx6x377xfsfrt2bqsevbw', | ||
customer_id: 'ctm_01hv6y1jedq4p1n0yqn5ba3ky4', | ||
address_id: 'add_01hv8gq3318ktkfengj2r75gfx', | ||
type: 'card', | ||
origin: 'saved_during_purchase', | ||
saved_at: '2024-05-02T02:55:25.198953Z', | ||
updated_at: '2024-05-02T02:55:25.198953Z', | ||
}, | ||
}; | ||
|
||
export const PaymentMethodSavedMockExpectation = { | ||
data: { | ||
id: 'paymtd_01hs8zx6x377xfsfrt2bqsevbw', | ||
customerId: 'ctm_01hv6y1jedq4p1n0yqn5ba3ky4', | ||
addressId: 'add_01hv8gq3318ktkfengj2r75gfx', | ||
type: 'card', | ||
origin: 'saved_during_purchase', | ||
savedAt: '2024-05-02T02:55:25.198953Z', | ||
updatedAt: '2024-05-02T02:55:25.198953Z', | ||
}, | ||
eventId: 'evt_01hwvkmsge7bhq1a31s35784zt', | ||
eventType: 'payment_method.saved', | ||
notificationId: 'ntf_01hwvkmsknrgqw4z1598qw4ypt', | ||
occurredAt: '2024-05-02T02:55:25.198953Z', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { IPaymentMethodResponse } from '../../../types'; | ||
import { Response, ResponsePaginated } from '../../../internal'; | ||
|
||
export const PaymentMethodMock: IPaymentMethodResponse = { | ||
id: 'paymtd_123', | ||
customer_id: 'ctm_123', | ||
address_id: 'add_123', | ||
type: 'card', | ||
card: { | ||
type: 'visa', | ||
last4: '1234', | ||
expiry_month: 1, | ||
expiry_year: 2025, | ||
|
||
cardholder_name: 'Sam Miller', | ||
}, | ||
paypal: null, | ||
origin: 'saved_during_purchase', | ||
saved_at: '2024-05-03T11:50:23.422Z', | ||
updated_at: '2024-05-03T11:50:23.422Z', | ||
}; | ||
|
||
export const PaymentMethodMockResponse: Response<IPaymentMethodResponse> = { | ||
data: PaymentMethodMock, | ||
meta: { | ||
request_id: '', | ||
}, | ||
}; | ||
|
||
export const ListPaymentMethodMockResponse: ResponsePaginated<IPaymentMethodResponse> = { | ||
data: [PaymentMethodMock], | ||
meta: { | ||
request_id: '', | ||
pagination: { | ||
estimated_total: 10, | ||
has_more: true, | ||
next: '/customers/ctm_123/payment-methods?after=1', | ||
per_page: 10, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { PaymentMethodsResource, type ListCustomerPaymentMethodQueryParameters } from '../../resources'; | ||
import { getPaddleTestClient } from '../helpers/test-client'; | ||
import { | ||
PaymentMethodMockResponse, | ||
PaymentMethodMock, | ||
ListPaymentMethodMockResponse, | ||
} from '../mocks/resources/payment-methods.mock'; | ||
|
||
describe('PaymentMethodsResource', () => { | ||
test('should return a list of payment methods', async () => { | ||
const customerId = PaymentMethodMock.customer_id; | ||
|
||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.get = jest.fn().mockResolvedValue(ListPaymentMethodMockResponse); | ||
|
||
const paymentMethodsResource = new PaymentMethodsResource(paddleInstance); | ||
const paymentMethodCollection = paymentMethodsResource.list(customerId); | ||
|
||
let paymentMethods = await paymentMethodCollection.next(); | ||
expect(paddleInstance.get).toBeCalledWith(`/customers/${customerId}/payment-methods?`); | ||
expect(paymentMethods.length).toBe(1); | ||
|
||
paymentMethods = await paymentMethodCollection.next(); | ||
expect(paddleInstance.get).toBeCalledWith(`/customers/${customerId}/payment-methods?after=1`); | ||
expect(paymentMethods.length).toBe(1); | ||
}); | ||
|
||
test('should accept query params and return a list of payment methods', async () => { | ||
const customerId = PaymentMethodMock.customer_id; | ||
|
||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.get = jest.fn().mockResolvedValue(ListPaymentMethodMockResponse); | ||
const paymentMethodsResource = new PaymentMethodsResource(paddleInstance); | ||
const queryParams: ListCustomerPaymentMethodQueryParameters = { | ||
after: '2', | ||
addressId: ['adr_123'], | ||
}; | ||
|
||
const paymentMethodCollection = paymentMethodsResource.list(customerId, queryParams); | ||
let paymentMethods = await paymentMethodCollection.next(); | ||
|
||
expect(paddleInstance.get).toBeCalledWith(`/customers/${customerId}/payment-methods?after=2&address_id=adr_123`); | ||
expect(paymentMethods.length).toBe(1); | ||
}); | ||
|
||
test('should return a single payment method', async () => { | ||
const paymentMethodId = PaymentMethodMock.id; | ||
const customerId = PaymentMethodMock.customer_id; | ||
|
||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.get = jest.fn().mockResolvedValue(PaymentMethodMockResponse); | ||
|
||
const paymentMethodsResource = new PaymentMethodsResource(paddleInstance); | ||
const paymentMethod = await paymentMethodsResource.get(customerId, paymentMethodId); | ||
|
||
expect(paddleInstance.get).toBeCalledWith(`/customers/${customerId}/payment-methods/${paymentMethodId}`); | ||
expect(paymentMethod).toBeDefined(); | ||
expect(paymentMethod.id).toBe(paymentMethodId); | ||
}); | ||
|
||
test('should delete an existing payment method', async () => { | ||
const paymentMethodId = PaymentMethodMock.id; | ||
const customerId = PaymentMethodMock.customer_id; | ||
|
||
const paddleInstance = getPaddleTestClient(); | ||
paddleInstance.delete = jest.fn().mockResolvedValue(PaymentMethodMockResponse); | ||
|
||
const paymentMethodsResource = new PaymentMethodsResource(paddleInstance); | ||
const updatedPaymentMethod = await paymentMethodsResource.delete(customerId, paymentMethodId); | ||
|
||
expect(paddleInstance.delete).toBeCalledWith(`/customers/${customerId}/payment-methods/${paymentMethodId}`); | ||
expect(updatedPaymentMethod).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { type IAuthTokenResponse } from '../../types'; | ||
|
||
export class AuthToken { | ||
public readonly customerAuthToken: string; | ||
public readonly expiresAt: string; | ||
|
||
constructor(authToken: IAuthTokenResponse) { | ||
this.customerAuthToken = authToken.customer_auth_token; | ||
this.expiresAt = authToken.expires_at; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
export * from './payment-method'; | ||
export * from './payment-method-collection'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import { PaymentMethod } from '../../entities'; | ||
import { type IPaymentMethodResponse } from '../../types'; | ||
import { Collection } from '../../internal/base'; | ||
|
||
export class PaymentMethodCollection extends Collection<IPaymentMethodResponse, PaymentMethod> { | ||
override fromJson(data: IPaymentMethodResponse): PaymentMethod { | ||
return new PaymentMethod(data); | ||
} | ||
} |
Oops, something went wrong.