2020-12-01 17:55:23 +01:00
|
|
|
import apiClient from './api-client';
|
|
|
|
import { AxiosResponse } from 'axios';
|
2021-02-09 12:09:26 +01:00
|
|
|
import { CartItems, IntentConfirmation, PaymentConfirmation, UpdateCardResponse } from '../models/payment';
|
2020-12-01 17:55:23 +01:00
|
|
|
|
|
|
|
export default class PaymentAPI {
|
|
|
|
static async confirm (stp_payment_method_id: string, cart_items: CartItems): Promise<PaymentConfirmation> {
|
2020-12-02 10:06:18 +01:00
|
|
|
const res: AxiosResponse = await apiClient.post(`/api/payments/confirm_payment`, {
|
2020-12-01 17:55:23 +01:00
|
|
|
payment_method_id: stp_payment_method_id,
|
|
|
|
cart_items
|
|
|
|
});
|
|
|
|
return res?.data;
|
|
|
|
}
|
2020-12-08 12:26:03 +01:00
|
|
|
|
|
|
|
static async setupIntent (user_id: number): Promise<IntentConfirmation> {
|
|
|
|
const res: AxiosResponse = await apiClient.get(`/api/payments/setup_intent/${user_id}`);
|
|
|
|
return res?.data;
|
|
|
|
}
|
2020-12-08 17:30:33 +01:00
|
|
|
|
2021-02-09 12:09:26 +01:00
|
|
|
// TODO, type the response
|
2020-12-08 17:30:33 +01:00
|
|
|
static async confirmPaymentSchedule (setup_intent_id: string, cart_items: CartItems): Promise<any> {
|
|
|
|
const res: AxiosResponse = await apiClient.post(`/api/payments/confirm_payment_schedule`, {
|
|
|
|
setup_intent_id,
|
|
|
|
cart_items
|
|
|
|
});
|
|
|
|
return res?.data;
|
|
|
|
}
|
2021-02-09 12:09:26 +01:00
|
|
|
|
|
|
|
static async updateCard (user_id: number, stp_payment_method_id: string): Promise<UpdateCardResponse> {
|
|
|
|
const res: AxiosResponse = await apiClient.post(`/api/payments/update_card`, {
|
|
|
|
user_id,
|
|
|
|
payment_method_id: stp_payment_method_id,
|
|
|
|
});
|
|
|
|
return res?.data;
|
|
|
|
}
|
2020-12-01 17:55:23 +01:00
|
|
|
}
|
|
|
|
|