@bebapps/rapyd-sdk
Version:
An un-official [Rapyd](https://rapyd.net) SDK for Node.js.
51 lines (44 loc) • 2.73 kB
text/typescript
import { RapydClient } from '../../../core/RapydClient';
import { CustomerPaymentMethod } from '../types/CustomerPaymentMethod';
import { CustomerPaymentMethodError } from '../enums/CustomerPaymentMethodError';
import { AddPaymentMethodToCustomerRequest } from '../requests/AddPaymentMethodToCustomerRequest';
import { UpdatePaymentMethodRequest } from '../requests/UpdatePaymentMethodRequest';
import { RetrievePaymentMethodRequest } from '../requests/RetrievePaymentMethodRequest';
import { ListPaymentMethodsOfCustomerRequest } from '../requests/ListPaymentMethodsOfCustomerRequest';
import { DeletePaymentMethodRequest } from '../requests/DeletePaymentMethodRequest';
export async function addPaymentMethodToCustomer<R = CustomerPaymentMethod>(client: RapydClient, request: AddPaymentMethodToCustomerRequest): Promise<R> {
const response = await client.post('/v1/customers/{}/payment_methods', request.customer, {
address: request.address,
fields: request.fields,
metadata: request.metadata,
token: request.token,
type: request.type,
});
return await response.data<R, CustomerPaymentMethodError>();
}
export async function updatePaymentMethod<R = CustomerPaymentMethod>(client: RapydClient, request: UpdatePaymentMethodRequest): Promise<R> {
const response = await client.post('/v1/customers/{}/payment_methods/{}', request.customer, request.payment_method, {
address: request.address,
fields: request.fields,
metadata: request.metadata,
});
return await response.data<R, CustomerPaymentMethodError>();
}
export async function retrievePaymentMethod<R = CustomerPaymentMethod>(client: RapydClient, request: RetrievePaymentMethodRequest): Promise<R> {
const response = await client.get('/v1/customers/{}/payment_methods/{}', request.customer, request.payment_method);
return await response.data<R, CustomerPaymentMethodError>();
}
export async function listPaymentMethodsOfCustomer<R = CustomerPaymentMethod>(client: RapydClient, request: ListPaymentMethodsOfCustomerRequest): Promise<R> {
const queryParams = client.queryParams({
ending_before: request.ending_before,
limit: request.limit,
starting_after: request.starting_after,
type: request.type,
});
const response = await client.get('/v1/customers/{}/payment_methods' + queryParams, request.customer);
return await response.data<R, CustomerPaymentMethodError>();
}
export async function deletePaymentMethod<R = CustomerPaymentMethod>(client: RapydClient, request: DeletePaymentMethodRequest): Promise<R> {
const response = await client.delete('/v1/customers/{}/payment_methods/{}', request.customer, request.payment_method);
return await response.data<R, CustomerPaymentMethodError>();
}