Skip to content

Commit 93947ea

Browse files
AkshayaFoigerArjunKarthikjagan-jaya
authored
feat(Connector): [Stripe] Implement Wechatpay Digital Wallet (#1049)
Co-authored-by: Arjun Karthik <[email protected]> Co-authored-by: Jagan Elavarasan <[email protected]>
1 parent bc4ac52 commit 93947ea

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

crates/router/src/connector/stripe/transformers.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ pub enum StripeWallet {
298298
ApplepayToken(StripeApplePay),
299299
GooglepayToken(GooglePayToken),
300300
ApplepayPayment(ApplepayPayment),
301+
WechatpayPayment(WechatpayPayment),
301302
AlipayPayment(AlipayPayment),
302303
}
303304

@@ -333,6 +334,22 @@ pub struct AlipayPayment {
333334
pub payment_method_data_type: StripePaymentMethodType,
334335
}
335336

337+
#[derive(Debug, Eq, PartialEq, Serialize)]
338+
pub struct WechatpayPayment {
339+
#[serde(rename = "payment_method_types[]")]
340+
pub payment_method_types: StripePaymentMethodType,
341+
#[serde(rename = "payment_method_data[type]")]
342+
pub payment_method_data_type: StripePaymentMethodType,
343+
#[serde(rename = "payment_method_options[wechat_pay][client]")]
344+
pub client: WechatClient,
345+
}
346+
347+
#[derive(Debug, Eq, PartialEq, Serialize, Clone, Copy)]
348+
#[serde(rename_all = "snake_case")]
349+
pub enum WechatClient {
350+
Web,
351+
}
352+
336353
#[derive(Debug, Eq, PartialEq, Serialize)]
337354
pub struct GooglepayPayment {
338355
#[serde(rename = "payment_method_data[card][token]")]
@@ -361,6 +378,8 @@ pub enum StripePaymentMethodType {
361378
Becs,
362379
#[serde(rename = "bacs_debit")]
363380
Bacs,
381+
#[serde(rename = "wechat_pay")]
382+
Wechatpay,
364383
Alipay,
365384
}
366385

@@ -819,6 +838,15 @@ fn create_stripe_payment_method(
819838
StripeBillingAddress::default(),
820839
)),
821840

841+
payments::WalletData::WeChatPayRedirect(_) => Ok((
842+
StripePaymentMethodData::Wallet(StripeWallet::WechatpayPayment(WechatpayPayment {
843+
client: WechatClient::Web,
844+
payment_method_types: StripePaymentMethodType::Wechatpay,
845+
payment_method_data_type: StripePaymentMethodType::Wechatpay,
846+
})),
847+
StripePaymentMethodType::Wechatpay,
848+
StripeBillingAddress::default(),
849+
)),
822850
payments::WalletData::AliPay(_) => Ok((
823851
StripePaymentMethodData::Wallet(StripeWallet::AlipayPayment(AlipayPayment {
824852
payment_method_types: StripePaymentMethodType::Alipay,
@@ -832,7 +860,6 @@ fn create_stripe_payment_method(
832860
StripePaymentMethodType::Card,
833861
StripeBillingAddress::default(),
834862
)),
835-
836863
_ => Err(errors::ConnectorError::NotImplemented(
837864
"This wallet is not implemented for stripe".to_string(),
838865
)
@@ -1251,8 +1278,9 @@ impl ForeignFrom<(Option<StripePaymentMethodOptions>, String)> for types::Mandat
12511278
| StripePaymentMethodOptions::Ach {}
12521279
| StripePaymentMethodOptions::Bacs {}
12531280
| StripePaymentMethodOptions::Becs {}
1254-
| StripePaymentMethodOptions::Sepa {}
1255-
| StripePaymentMethodOptions::Alipay {} => None,
1281+
| StripePaymentMethodOptions::WechatPay {}
1282+
| StripePaymentMethodOptions::Alipay {}
1283+
| StripePaymentMethodOptions::Sepa {} => None,
12561284
}),
12571285
payment_method_id: Some(payment_method_id),
12581286
}
@@ -1412,6 +1440,7 @@ pub enum StripeNextActionResponse {
14121440
RedirectToUrl(StripeRedirectToUrlResponse),
14131441
AlipayHandleRedirect(StripeRedirectToUrlResponse),
14141442
VerifyWithMicrodeposits(StripeVerifyWithMicroDepositsResponse),
1443+
WechatPayDisplayQrCode(StripeRedirectToQr),
14151444
}
14161445

14171446
impl StripeNextActionResponse {
@@ -1420,6 +1449,7 @@ impl StripeNextActionResponse {
14201449
Self::RedirectToUrl(redirect_to_url) | Self::AlipayHandleRedirect(redirect_to_url) => {
14211450
redirect_to_url.url.to_owned()
14221451
}
1452+
Self::WechatPayDisplayQrCode(redirect_to_url) => redirect_to_url.data.to_owned(),
14231453
Self::VerifyWithMicrodeposits(verify_with_microdeposits) => {
14241454
verify_with_microdeposits.hosted_verification_url.to_owned()
14251455
}
@@ -1453,6 +1483,11 @@ pub struct StripeRedirectToUrlResponse {
14531483
url: Url,
14541484
}
14551485

1486+
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
1487+
pub struct StripeRedirectToQr {
1488+
data: Url,
1489+
}
1490+
14561491
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]
14571492
pub struct StripeVerifyWithMicroDepositsResponse {
14581493
hosted_verification_url: Url,
@@ -1612,8 +1647,8 @@ pub struct StripeBillingAddress {
16121647

16131648
#[derive(Debug, Clone, serde::Deserialize, Eq, PartialEq)]
16141649
pub struct StripeRedirectResponse {
1615-
pub payment_intent: String,
1616-
pub payment_intent_client_secret: String,
1650+
pub payment_intent: Option<String>,
1651+
pub payment_intent_client_secret: Option<String>,
16171652
pub source_redirect_slug: Option<String>,
16181653
pub redirect_status: Option<StripePaymentStatus>,
16191654
pub source_type: Option<Secret<String>>,
@@ -1657,6 +1692,7 @@ pub enum StripePaymentMethodOptions {
16571692
Becs {},
16581693
#[serde(rename = "bacs_debit")]
16591694
Bacs {},
1695+
WechatPay {},
16601696
Alipay {},
16611697
}
16621698

@@ -1945,6 +1981,14 @@ impl
19451981
Ok(Self::Wallet(wallet_info))
19461982
}
19471983

1984+
payments::WalletData::WeChatPayRedirect(_) => {
1985+
let wallet_info = StripeWallet::WechatpayPayment(WechatpayPayment {
1986+
client: WechatClient::Web,
1987+
payment_method_types: StripePaymentMethodType::Wechatpay,
1988+
payment_method_data_type: StripePaymentMethodType::Wechatpay,
1989+
});
1990+
Ok(Self::Wallet(wallet_info))
1991+
}
19481992
payments::WalletData::AliPay(_) => {
19491993
let wallet_info = StripeWallet::AlipayPayment(AlipayPayment {
19501994
payment_method_types: StripePaymentMethodType::Alipay,

0 commit comments

Comments
 (0)