Skip to content

Commit

Permalink
feat(payment_method): [upi] add new payment method and use in iatapay (
Browse files Browse the repository at this point in the history
…#1528)

Co-authored-by: arvindpatel24 <arvind.patel@juspay.in>
  • Loading branch information
arvindpatel24 and arvindpatel24 committed Jun 30, 2023
1 parent 88860b9 commit 2d11bf5
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 183 deletions.
2 changes: 2 additions & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ pub enum PaymentMethodType {
Sofort,
Swish,
Trustly,
UpiCollect,
Walley,
WeChatPay,
}
Expand Down Expand Up @@ -478,6 +479,7 @@ pub enum PaymentMethod {
Crypto,
BankDebit,
Reward,
Upi,
}

#[derive(
Expand Down
12 changes: 12 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ pub enum PaymentMethodData {
Crypto(CryptoData),
MandatePayment,
Reward(RewardData),
Upi(UpiData),
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
Expand All @@ -609,6 +610,7 @@ pub enum AdditionalPaymentData {
BankDebit {},
MandatePayment {},
Reward {},
Upi {},
}

impl From<&PaymentMethodData> for AdditionalPaymentData {
Expand Down Expand Up @@ -637,6 +639,7 @@ impl From<&PaymentMethodData> for AdditionalPaymentData {
PaymentMethodData::BankDebit(_) => Self::BankDebit {},
PaymentMethodData::MandatePayment => Self::MandatePayment {},
PaymentMethodData::Reward(_) => Self::Reward {},
PaymentMethodData::Upi(_) => Self::Upi {},
}
}
}
Expand Down Expand Up @@ -775,6 +778,13 @@ pub struct CryptoData {
pub pay_currency: Option<String>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct UpiData {
#[schema(value_type = Option<String>, example = "successtest@iata")]
pub vpa_id: Option<Secret<String>>,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct SofortBilling {
/// The country associated with the billing
Expand Down Expand Up @@ -976,6 +986,7 @@ pub enum PaymentMethodDataResponse {
BankDebit(BankDebitData),
MandatePayment,
Reward(RewardData),
Upi(UpiData),
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down Expand Up @@ -1606,6 +1617,7 @@ impl From<PaymentMethodData> for PaymentMethodDataResponse {
PaymentMethodData::BankDebit(bank_debit_data) => Self::BankDebit(bank_debit_data),
PaymentMethodData::MandatePayment => Self::MandatePayment,
PaymentMethodData::Reward(reward_data) => Self::Reward(reward_data),
PaymentMethodData::Upi(upi_data) => Self::Upi(upi_data),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/aci/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest {
api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Reward(_) => Err(errors::ConnectorError::NotSupported {
| api::PaymentMethodData::Reward(_)
| api::PaymentMethodData::Upi(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.payment_method),
connector: "Aci",
payment_experience: api_models::enums::PaymentExperience::RedirectToUrl.to_string(),
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/authorizedotnet/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ fn get_pm_and_subsequent_auth_detail(
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::Reward(_) => Err(errors::ConnectorError::NotSupported {
| api::PaymentMethodData::Reward(_)
| api::PaymentMethodData::Upi(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.request.payment_method_data),
connector: "AuthorizeDotNet",
payment_experience: api_models::enums::PaymentExperience::RedirectToUrl.to_string(),
Expand Down
15 changes: 15 additions & 0 deletions crates/router/src/connector/iatapay/transformers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use masking::Secret;
use serde::{Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -58,6 +59,12 @@ pub struct RedirectUrls {
failure_url: String,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PayerInfo {
token_id: Secret<String>,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct IatapayPaymentsRequest {
Expand All @@ -68,20 +75,28 @@ pub struct IatapayPaymentsRequest {
locale: String,
redirect_urls: RedirectUrls,
notification_url: String,
payer_info: Option<PayerInfo>,
}

impl TryFrom<&types::PaymentsAuthorizeRouterData> for IatapayPaymentsRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
let country = item.get_billing_country()?.to_string();
let return_url = item.get_return_url()?;
let payer_info = match item.request.payment_method_data.clone() {
api::PaymentMethodData::Upi(upi_data) => {
upi_data.vpa_id.map(|id| PayerInfo { token_id: id })
}
_ => None,
};
let payload = Self {
merchant_id: IatapayAuthType::try_from(&item.connector_auth_type)?.merchant_id,
amount: item.request.amount,
currency: item.request.currency.to_string(),
country: country.clone(),
locale: format!("en-{}", country),
redirect_urls: get_redirect_url(return_url),
payer_info,
notification_url: item.request.get_webhook_url()?,
};
Ok(payload)
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,8 @@ impl
}
api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::Reward(_) => Err(errors::ConnectorError::NotSupported {
| api::PaymentMethodData::Reward(_)
| api::PaymentMethodData::Upi(_) => Err(errors::ConnectorError::NotSupported {
message: format!("{pm_type:?}"),
connector: "Stripe",
payment_experience: api_models::enums::PaymentExperience::RedirectToUrl.to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
(pm @ Some(api::PaymentMethodData::BankRedirect(_)), _) => Ok(pm.to_owned()),
(pm @ Some(api::PaymentMethodData::Crypto(_)), _) => Ok(pm.to_owned()),
(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_opt @ Some(pm @ api::PaymentMethodData::BankTransfer(_)), _) => {
let token = vault::Vault::store_payment_method_data_in_locker(
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::BankDebitBilling,
api_models::payments::CryptoData,
api_models::payments::RewardData,
api_models::payments::UpiData,
api_models::payments::Address,
api_models::payments::BankRedirectData,
api_models::payments::BankRedirectBilling,
Expand Down
2 changes: 2 additions & 0 deletions crates/storage_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ pub enum PaymentMethod {
Crypto,
BankDebit,
Reward,
Upi,
}

#[derive(
Expand Down Expand Up @@ -706,6 +707,7 @@ pub enum PaymentMethodType {
Sofort,
Swish,
Trustly,
UpiCollect,
Walley,
WeChatPay,
}
Expand Down
Loading

0 comments on commit 2d11bf5

Please sign in to comment.