feat(compatibility): add list payment_method by customer api (#398)

This commit is contained in:
Abhishek
2023-01-18 19:07:38 +05:30
committed by GitHub
parent f4072d390d
commit 46bf1341cb
4 changed files with 90 additions and 1 deletions

View File

@ -52,5 +52,6 @@ impl Customers {
.service(customer_retrieve)
.service(customer_update)
.service(customer_delete)
.service(list_customer_payment_method_api)
}
}

View File

@ -6,7 +6,7 @@ use router_env::{instrument, tracing};
use crate::{
compatibility::{stripe::errors, wrap},
core::customers,
core::{customers, payment_methods::cards},
routes,
services::{api, authentication as auth},
types::api::customers as customer_types,
@ -148,3 +148,30 @@ pub async fn customer_delete(
)
.await
}
#[instrument(skip_all)]
#[get("/{customer_id}/payment_methods")]
pub async fn list_customer_payment_method_api(
state: web::Data<routes::AppState>,
req: HttpRequest,
path: web::Path<String>,
) -> HttpResponse {
let customer_id = path.into_inner();
wrap::compatibility_api_wrap::<
_,
_,
_,
_,
_,
types::CustomerPaymentMethodListResponse,
errors::StripeErrorCode,
>(
&state,
&req,
customer_id.as_ref(),
cards::list_customer_payment_method,
&auth::ApiKeyAuth,
)
.await
}

View File

@ -1,5 +1,6 @@
use std::{convert::From, default::Default};
use api_models::payment_methods as api_types;
use common_utils::date_time;
use masking;
use serde::{Deserialize, Serialize};
@ -120,3 +121,63 @@ impl From<api::CustomerDeleteResponse> for CustomerDeleteResponse {
}
}
}
#[derive(Default, Serialize, PartialEq, Eq)]
pub struct CustomerPaymentMethodListResponse {
pub object: &'static str,
pub data: Vec<PaymentMethodData>,
}
#[derive(Default, Serialize, PartialEq, Eq)]
pub struct PaymentMethodData {
pub id: String,
pub object: &'static str,
pub card: Option<CardDetails>,
pub created: Option<time::PrimitiveDateTime>,
}
#[derive(Default, Serialize, PartialEq, Eq)]
pub struct CardDetails {
pub country: Option<String>,
pub last4: Option<String>,
pub exp_month: Option<masking::Secret<String>>,
pub exp_year: Option<masking::Secret<String>>,
pub fingerprint: Option<masking::Secret<String>>,
}
impl From<api::ListCustomerPaymentMethodsResponse> for CustomerPaymentMethodListResponse {
fn from(item: api::ListCustomerPaymentMethodsResponse) -> Self {
let customer_payment_methods = item.customer_payment_methods;
let data = customer_payment_methods
.into_iter()
.map(From::from)
.collect();
Self {
object: "list",
data,
}
}
}
impl From<api_types::CustomerPaymentMethod> for PaymentMethodData {
fn from(item: api_types::CustomerPaymentMethod) -> Self {
Self {
id: item.payment_token,
object: "payment_method",
card: item.card.map(From::from),
created: item.created,
}
}
}
impl From<api_types::CardDetailFromLocker> for CardDetails {
fn from(item: api_types::CardDetailFromLocker) -> Self {
Self {
country: item.issuer_country,
last4: item.last4_digits,
exp_month: item.expiry_month,
exp_year: item.expiry_year,
fingerprint: item.card_fingerprint,
}
}
}