Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat: Api contract for gift cards (#1634)

Sangamesh Kulkarni836962677b95
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index a76dee4ff2..4c30d190c7 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -721,6 +721,17 @@ pub enum PaymentMethodData {
MandatePayment,
Reward(RewardData),
Upi(UpiData),
+ GiftCard(Box<GiftCardData>),
+}
+
+#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
+pub struct GiftCardData {
+ /// The gift card number
+ #[schema(value_type = String)]
+ pub number: Secret<String>,
+ /// The card verification code.
+ #[schema(value_type = String)]
+ pub cvc: Secret<String>,
}
#[derive(Default, Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
@@ -753,6 +764,7 @@ pub enum AdditionalPaymentData {
MandatePayment {},
Reward {},
Upi {},
+ GiftCard {},
}
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
@@ -1181,6 +1193,7 @@ pub enum PaymentMethodDataResponse {
MandatePayment,
Reward,
Upi,
+ GiftCard,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
@@ -1854,6 +1867,7 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
AdditionalPaymentData::Reward {} => Self::Reward,
AdditionalPaymentData::Upi {} => Self::Upi,
AdditionalPaymentData::BankTransfer {} => Self::BankTransfer,
+ AdditionalPaymentData::GiftCard {} => Self::GiftCard,
}
}
}
diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs
index 2478179bc1..228506cdc0 100644
--- a/crates/router/src/connector/aci/transformers.rs
+++ b/crates/router/src/connector/aci/transformers.rs
@@ -370,6 +370,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest {
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Reward(_)
+ | api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::Upi(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.payment_method),
connector: "Aci",
diff --git a/crates/router/src/connector/payme/transformers.rs b/crates/router/src/connector/payme/transformers.rs
index 5f87af07c8..ec3303d3fc 100644
--- a/crates/router/src/connector/payme/transformers.rs
+++ b/crates/router/src/connector/payme/transformers.rs
@@ -166,6 +166,7 @@ impl TryFrom<&PaymentMethodData> for SalePaymentMethod {
| PaymentMethodData::Crypto(_)
| PaymentMethodData::MandatePayment
| PaymentMethodData::Reward(_)
+ | PaymentMethodData::GiftCard(_)
| PaymentMethodData::Upi(_) => {
Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into())
}
diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs
index 245ee39918..ffce082576 100644
--- a/crates/router/src/connector/stripe/transformers.rs
+++ b/crates/router/src/connector/stripe/transformers.rs
@@ -2908,6 +2908,7 @@ impl
api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::Reward(_)
+ | api::PaymentMethodData::GiftCard(_)
| api::PaymentMethodData::Upi(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{pm_type:?}"),
connector: "Stripe",
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 4515063e06..8ddb12da8c 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -1279,6 +1279,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
(pm @ Some(api::PaymentMethodData::BankDebit(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::Upi(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::Reward(_)), _) => Ok(pm.to_owned()),
+ (pm @ Some(api::PaymentMethodData::GiftCard(_)), _) => Ok(pm.to_owned()),
(pm_opt @ Some(pm @ api::PaymentMethodData::BankTransfer(_)), _) => {
let token = vault::Vault::store_payment_method_data_in_locker(
state,
@@ -2613,6 +2614,9 @@ pub async fn get_additional_payment_data(
api_models::payments::PaymentMethodData::Upi(_) => {
api_models::payments::AdditionalPaymentData::Upi {}
}
+ api_models::payments::PaymentMethodData::GiftCard(_) => {
+ api_models::payments::AdditionalPaymentData::GiftCard {}
+ }
}
}
diff --git a/crates/router/src/openapi.rs b/crates/router/src/openapi.rs
index 1e1d2c45be..2afac28f98 100644
--- a/crates/router/src/openapi.rs
+++ b/crates/router/src/openapi.rs
@@ -285,6 +285,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::mandates::MandateCardDetails,
api_models::ephemeral_key::EphemeralKeyCreateResponse,
api_models::payments::CustomerDetails,
+ api_models::payments::GiftCardData,
api_models::payouts::PayoutCreateRequest,
api_models::payments::Address,
api_models::payouts::Card,
diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json
index dcffea6c7e..82f32b51a2 100644
--- a/openapi/openapi_spec.json
+++ b/openapi/openapi_spec.json
@@ -4705,6 +4705,23 @@
"GcashRedirection": {
"type": "object"
},
+ "GiftCardData": {
+ "type": "object",
+ "required": [
+ "number",
+ "cvc"
+ ],
+ "properties": {
+ "number": {
+ "type": "string",
+ "description": "The gift card number"
+ },
+ "cvc": {
+ "type": "string",
+ "description": "The card verification code."
+ }
+ }
+ },
"GoPayRedirection": {
"type": "object"
},
@@ -7028,6 +7045,17 @@
"$ref": "#/components/schemas/UpiData"
}
}
+ },
+ {
+ "type": "object",
+ "required": [
+ "gift_card"
+ ],
+ "properties": {
+ "gift_card": {
+ "$ref": "#/components/schemas/GiftCardData"
+ }
+ }
}
]
},