Skip to content

Commit

Permalink
feat: ACH transfers (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangamesh26 authored May 19, 2023
1 parent 39405bb commit 23bca66
Show file tree
Hide file tree
Showing 39 changed files with 1,247 additions and 66 deletions.
1 change: 1 addition & 0 deletions crates/api_models/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ pub enum PaymentMethod {
PayLater,
Wallet,
BankRedirect,
BankTransfer,
Crypto,
BankDebit,
}
Expand Down
10 changes: 10 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,13 @@ pub struct TokenizedWalletValue1 {
pub struct TokenizedWalletValue2 {
pub customer_id: Option<String>,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct TokenizedBankTransferValue1 {
pub data: payments::BankTransferData,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct TokenizedBankTransferValue2 {
pub customer_id: Option<String>,
}
54 changes: 52 additions & 2 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ pub enum PaymentMethodData {
PayLater(PayLaterData),
BankRedirect(BankRedirectData),
BankDebit(BankDebitData),
BankTransfer(Box<BankTransferData>),
Crypto(CryptoData),
MandatePayment,
}
Expand All @@ -563,6 +564,7 @@ pub enum AdditionalPaymentData {
},
Wallet {},
PayLater {},
BankTransfer {},
Crypto {},
BankDebit {},
MandatePayment {},
Expand All @@ -589,6 +591,7 @@ impl From<&PaymentMethodData> for AdditionalPaymentData {
},
PaymentMethodData::Wallet(_) => Self::Wallet {},
PaymentMethodData::PayLater(_) => Self::PayLater {},
PaymentMethodData::BankTransfer(_) => Self::BankTransfer {},
PaymentMethodData::Crypto(_) => Self::Crypto {},
PaymentMethodData::BankDebit(_) => Self::BankDebit {},
PaymentMethodData::MandatePayment => Self::MandatePayment {},
Expand Down Expand Up @@ -695,6 +698,16 @@ pub enum BankRedirectData {
},
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct AchBankTransferData {
pub billing_details: AchBillingDetails,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct AchBillingDetails {
pub email: Email,
}

#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub struct CryptoData {}
Expand All @@ -716,6 +729,12 @@ pub struct BankRedirectBilling {
pub email: Option<Email>,
}

#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum BankTransferData {
AchBankTransfer(AchBankTransferData),
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone, ToSchema, Eq, PartialEq)]
pub struct BankDebitBilling {
/// The billing name for bank debits
Expand Down Expand Up @@ -836,8 +855,7 @@ pub struct CardResponse {
pub enum PaymentMethodDataResponse {
#[serde(rename = "card")]
Card(CardResponse),
#[serde(rename(deserialize = "bank_transfer"))]
BankTransfer,
BankTransfer(BankTransferData),
Wallet(WalletData),
PayLater(PayLaterData),
Paypal,
Expand All @@ -855,6 +873,8 @@ pub enum PaymentIdType {
ConnectorTransactionId(String),
/// The identifier for payment attempt
PaymentAttemptId(String),
/// The identifier for preprocessing step
PreprocessingId(String),
}

impl std::fmt::Display for PaymentIdType {
Expand All @@ -870,6 +890,9 @@ impl std::fmt::Display for PaymentIdType {
Self::PaymentAttemptId(payment_attempt_id) => {
write!(f, "payment_attempt_id = \"{payment_attempt_id}\"")
}
Self::PreprocessingId(preprocessing_id) => {
write!(f, "preprocessing_id = \"{preprocessing_id}\"")
}
}
}
}
Expand Down Expand Up @@ -1004,15 +1027,39 @@ pub enum NextActionType {
DisplayQrCode,
InvokeSdkClient,
TriggerApi,
DisplayBankTransferInformation,
}
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, ToSchema)]
pub struct NextAction {
/// Specifying the action type to be performed next
#[serde(rename = "type")]
pub next_action_type: NextActionType,
//TODO: Make an enum having redirect_to_url and bank_transfer_steps_and_charges_details and use here
/// Contains the url for redirection flow
#[schema(example = "https://router.juspay.io/redirect/fakushdfjlksdfasklhdfj")]
pub redirect_to_url: Option<String>,
/// Informs the next steps for bank transfer and also contains the charges details (ex: amount received, amount charged etc)
pub bank_transfer_steps_and_charges_details: Option<NextStepsRequirements>,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct NextStepsRequirements {
pub ach_credit_transfer: AchTransfer,
pub receiver: ReceiverDetails,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct AchTransfer {
pub account_number: Secret<String>,
pub bank_name: String,
pub routing_number: Secret<String>,
pub swift_code: Secret<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ReceiverDetails {
pub amount_received: i64,
pub amount_charged: i64,
}

#[derive(Setter, Clone, Default, Debug, Eq, PartialEq, serde::Serialize, ToSchema)]
Expand Down Expand Up @@ -1391,6 +1438,9 @@ impl From<PaymentMethodData> for PaymentMethodDataResponse {
PaymentMethodData::BankRedirect(bank_redirect_data) => {
Self::BankRedirect(bank_redirect_data)
}
PaymentMethodData::BankTransfer(bank_transfer_data) => {
Self::BankTransfer(*bank_transfer_data)
}
PaymentMethodData::Crypto(crpto_data) => Self::Crypto(crpto_data),
PaymentMethodData::BankDebit(bank_debit_data) => Self::BankDebit(bank_debit_data),
PaymentMethodData::MandatePayment => Self::MandatePayment,
Expand Down
7 changes: 7 additions & 0 deletions crates/api_models/src/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub enum IncomingWebhookEvent {
PaymentIntentProcessing,
PaymentActionRequired,
EventNotSupported,
SourceChargeable,
SourceTransactionCreated,
ChargeSucceeded,
RefundFailure,
RefundSuccess,
DisputeOpened,
Expand All @@ -32,6 +35,7 @@ pub enum WebhookFlow {
Dispute,
Subscription,
ReturnResponse,
BankTransfer,
}

impl From<IncomingWebhookEvent> for WebhookFlow {
Expand All @@ -52,6 +56,9 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
IncomingWebhookEvent::DisputeWon => Self::Dispute,
IncomingWebhookEvent::DisputeLost => Self::Dispute,
IncomingWebhookEvent::EndpointVerification => Self::ReturnResponse,
IncomingWebhookEvent::SourceChargeable
| IncomingWebhookEvent::SourceTransactionCreated => Self::BankTransfer,
IncomingWebhookEvent::ChargeSucceeded => Self::Payment,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/connector/aci/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest {

api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::BankTransfer(_)
| api::PaymentMethodData::MandatePayment => {
Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.payment_method),
Expand Down
4 changes: 3 additions & 1 deletion crates/router/src/connector/authorizedotnet/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum PaymentDetails {
Paypal,
#[serde(rename = "bankRedirect")]
BankRedirect,
BankTransfer,
}

fn get_pm_and_subsequent_auth_detail(
Expand Down Expand Up @@ -137,7 +138,8 @@ fn get_pm_and_subsequent_auth_detail(
}
api::PaymentMethodData::Crypto(_)
| api::PaymentMethodData::BankDebit(_)
| api::PaymentMethodData::MandatePayment => {
| api::PaymentMethodData::MandatePayment
| api::PaymentMethodData::BankTransfer(_) => {
Err(errors::ConnectorError::NotSupported {
message: format!("{:?}", item.request.payment_method_data),
connector: "AuthorizeDotNet",
Expand Down
Loading

0 comments on commit 23bca66

Please sign in to comment.