Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cashapp and paypal payment methods, and option to pass MandateData via SDK #1331

Merged
merged 5 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
StripeSdk_kotlinVersion=1.8.0
StripeSdk_stripeVersion=[20.19.2, 20.20.0[
StripeSdk_stripeVersion=[20.20.0, 20.22.0[
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PaymentMethodCreateParamsFactory(
PaymentMethod.Type.USBankAccount -> createUSBankAccountParams(paymentMethodData)
PaymentMethod.Type.PayPal -> createPayPalParams()
PaymentMethod.Type.Affirm -> createAffirmParams()
PaymentMethod.Type.CashAppPay -> createCashAppParams()
else -> {
throw Exception("This paymentMethodType is not supported yet")
}
Expand Down Expand Up @@ -202,13 +203,17 @@ class PaymentMethodCreateParamsFactory(
return PaymentMethodCreateParams.createAffirm(billingDetailsParams)
}

@Throws(PaymentMethodCreateParamsException::class)
private fun createCashAppParams(): PaymentMethodCreateParams {
return PaymentMethodCreateParams.createCashAppPay(billingDetailsParams)
}

@Throws(PaymentMethodCreateParamsException::class)
fun createParams(clientSecret: String, paymentMethodType: PaymentMethod.Type?, isPaymentIntent: Boolean): ConfirmStripeIntentParams {
try {
return when (paymentMethodType) {
PaymentMethod.Type.Card -> createCardStripeIntentParams(clientSecret, isPaymentIntent)
PaymentMethod.Type.USBankAccount -> createUSBankAccountStripeIntentParams(clientSecret, isPaymentIntent)
PaymentMethod.Type.PayPal -> createPayPalStripeIntentParams(clientSecret, isPaymentIntent)
PaymentMethod.Type.Affirm -> createAffirmStripeIntentParams(clientSecret, isPaymentIntent)
PaymentMethod.Type.Ideal,
PaymentMethod.Type.Alipay,
Expand All @@ -223,7 +228,9 @@ class PaymentMethodCreateParamsFactory(
PaymentMethod.Type.Fpx,
PaymentMethod.Type.AfterpayClearpay,
PaymentMethod.Type.AuBecsDebit,
PaymentMethod.Type.Klarna -> {
PaymentMethod.Type.Klarna,
PaymentMethod.Type.PayPal,
PaymentMethod.Type.CashAppPay -> {
val params = createPaymentMethodParams(paymentMethodType)

return if (isPaymentIntent) {
Expand All @@ -232,11 +239,13 @@ class PaymentMethodCreateParamsFactory(
paymentMethodCreateParams = params,
clientSecret = clientSecret,
setupFutureUsage = mapToPaymentIntentFutureUsage(getValOr(options, "setupFutureUsage")),
mandateData = buildMandateDataParams()
)
} else {
ConfirmSetupIntentParams.create(
paymentMethodCreateParams = params,
clientSecret = clientSecret,
mandateData = buildMandateDataParams()
)
}
}
Expand Down Expand Up @@ -339,20 +348,6 @@ class PaymentMethodCreateParamsFactory(
}
}

@Throws(PaymentMethodCreateParamsException::class)
private fun createPayPalStripeIntentParams(clientSecret: String, isPaymentIntent: Boolean): ConfirmStripeIntentParams {
if (!isPaymentIntent) {
throw PaymentMethodCreateParamsException("PayPal is not yet supported through SetupIntents.")
}

val params = createPayPalParams()

return ConfirmPaymentIntentParams.createWithPaymentMethodCreateParams(
paymentMethodCreateParams = params,
clientSecret = clientSecret,
)
}

@Throws(PaymentMethodCreateParamsException::class)
private fun createAffirmStripeIntentParams(clientSecret: String, isPaymentIntent: Boolean): ConfirmStripeIntentParams {
if (!isPaymentIntent) {
Expand All @@ -366,6 +361,7 @@ class PaymentMethodCreateParamsFactory(
paymentMethodCreateParams = params,
clientSecret = clientSecret,
setupFutureUsage = mapToPaymentIntentFutureUsage(getValOr(options, "setupFutureUsage")),
mandateData = buildMandateDataParams()
)
}

Expand Down Expand Up @@ -401,6 +397,20 @@ class PaymentMethodCreateParamsFactory(
null
)
}

private fun buildMandateDataParams(): MandateDataParams? {
getMapOrNull(paymentMethodData, "mandateData")?.let { mandateData ->
getMapOrNull(mandateData, "customerAcceptance")?.let { customerAcceptance ->
getMapOrNull(customerAcceptance, "online")?.let { onlineParams ->
return MandateDataParams(MandateDataParams.Type.Online(
ipAddress = getValOr(onlineParams, "ipAddress", "") ?: "",
userAgent = getValOr(onlineParams, "userAgent", "") ?: "",
))
}
}
}
return null
}
}

class PaymentMethodCreateParamsException(message: String) : Exception(message)
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ internal fun mapPaymentMethodType(type: PaymentMethod.Type?): String {
PaymentMethod.Type.USBankAccount -> "USBankAccount"
PaymentMethod.Type.PayPal -> "PayPal"
PaymentMethod.Type.Affirm -> "Affirm"
PaymentMethod.Type.CashAppPay -> "CashApp"
else -> "Unknown"
}
}
Expand Down Expand Up @@ -152,6 +153,7 @@ internal fun mapToPaymentMethodType(type: String?): PaymentMethod.Type? {
"USBankAccount" -> PaymentMethod.Type.USBankAccount
"PayPal" -> PaymentMethod.Type.PayPal
"Affirm" -> PaymentMethod.Type.Affirm
"CashApp" -> PaymentMethod.Type.CashAppPay
else -> null
}
}
Expand Down
21 changes: 21 additions & 0 deletions e2e-tests/cashapp-payment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appId: ${APP_ID}
---
- launchApp
- tapOn: "Wallets"
- scrollUntilVisible:
element:
text: "CashApp"
direction: DOWN
- tapOn: "CashApp"
- assertVisible:
text: "E-mail"
- tapOn:
text: "E-mail"
- inputText: "[email protected]"
- tapOn:
text: "Pay"
retryTapIfNoChange: false
- tapOn: "AUTHORIZE TEST PAYMENT"
- assertVisible:
text: "Success"
- tapOn: "OK"
21 changes: 21 additions & 0 deletions e2e-tests/cashapp-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appId: ${APP_ID}
---
- launchApp
- tapOn: "Wallets"
- scrollUntilVisible:
element:
text: "CashApp"
direction: DOWN
- tapOn: "CashApp"
- assertVisible:
text: "E-mail"
- tapOn:
text: "E-mail"
- inputText: "[email protected]"
- tapOn:
text: "Setup for later"
retryTapIfNoChange: false
- tapOn: "AUTHORIZE TEST SETUP"
- assertVisible:
text: "Success"
- tapOn: "OK"
25 changes: 12 additions & 13 deletions e2e-tests/paypal-payment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ appId: ${APP_ID}
text: "PayPal"
direction: DOWN
- tapOn: "PayPal"
# Disable until Paypal is available
# - assertVisible:
# text: "E-mail"
# - tapOn:
# text: "E-mail"
# - inputText: "[email protected]"
# - tapOn:
# text: "Pay"
# retryTapIfNoChange: false
# - tapOn: "AUTHORIZE TEST PAYMENT"
# - assertVisible:
# text: "Success"
# - tapOn: "OK"
- assertVisible:
text: "E-mail"
- tapOn:
text: "E-mail"
- inputText: "[email protected]"
- tapOn:
text: "Pay"
retryTapIfNoChange: false
- tapOn: "AUTHORIZE TEST PAYMENT"
- assertVisible:
text: "Success"
- tapOn: "OK"
21 changes: 21 additions & 0 deletions e2e-tests/paypal-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
appId: ${APP_ID}
---
- launchApp
- tapOn: "Wallets"
- scrollUntilVisible:
element:
text: "PayPal"
direction: DOWN
- tapOn: "PayPal"
- assertVisible:
text: "E-mail"
- tapOn:
text: "E-mail"
- inputText: "[email protected]"
- tapOn:
text: "Setup for later"
retryTapIfNoChange: false
- tapOn: "AUTHORIZE TEST SETUP"
- assertVisible:
text: "Success"
- tapOn: "OK"
98 changes: 49 additions & 49 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -368,50 +368,50 @@ PODS:
- React-Core
- React-RCTImage
- SocketRocket (0.6.0)
- Stripe (23.4.2):
- StripeApplePay (= 23.4.2)
- StripeCore (= 23.4.2)
- StripePayments (= 23.4.2)
- StripePaymentsUI (= 23.4.2)
- StripeUICore (= 23.4.2)
- Stripe (23.5.0):
- StripeApplePay (= 23.5.0)
- StripeCore (= 23.5.0)
- StripePayments (= 23.5.0)
- StripePaymentsUI (= 23.5.0)
- StripeUICore (= 23.5.0)
- stripe-react-native (0.25.0):
- React-Core
- Stripe (~> 23.4.0)
- StripeApplePay (~> 23.4.0)
- StripeFinancialConnections (~> 23.4.0)
- StripePayments (~> 23.4.0)
- StripePaymentSheet (~> 23.4.0)
- StripePaymentsUI (~> 23.4.0)
- Stripe (~> 23.5.0)
- StripeApplePay (~> 23.5.0)
- StripeFinancialConnections (~> 23.5.0)
- StripePayments (~> 23.5.0)
- StripePaymentSheet (~> 23.5.0)
- StripePaymentsUI (~> 23.5.0)
- stripe-react-native/Tests (0.25.0):
- React-Core
- Stripe (~> 23.4.0)
- StripeApplePay (~> 23.4.0)
- StripeFinancialConnections (~> 23.4.0)
- StripePayments (~> 23.4.0)
- StripePaymentSheet (~> 23.4.0)
- StripePaymentsUI (~> 23.4.0)
- StripeApplePay (23.4.2):
- StripeCore (= 23.4.2)
- StripeCore (23.4.2)
- StripeFinancialConnections (23.4.2):
- StripeCore (= 23.4.2)
- StripeUICore (= 23.4.2)
- StripePayments (23.4.2):
- StripeCore (= 23.4.2)
- StripePayments/Stripe3DS2 (= 23.4.2)
- StripePayments/Stripe3DS2 (23.4.2):
- StripeCore (= 23.4.2)
- StripePaymentSheet (23.4.2):
- StripeApplePay (= 23.4.2)
- StripeCore (= 23.4.2)
- StripePayments (= 23.4.2)
- StripePaymentsUI (= 23.4.2)
- StripePaymentsUI (23.4.2):
- StripeCore (= 23.4.2)
- StripePayments (= 23.4.2)
- StripeUICore (= 23.4.2)
- StripeUICore (23.4.2):
- StripeCore (= 23.4.2)
- Stripe (~> 23.5.0)
- StripeApplePay (~> 23.5.0)
- StripeFinancialConnections (~> 23.5.0)
- StripePayments (~> 23.5.0)
- StripePaymentSheet (~> 23.5.0)
- StripePaymentsUI (~> 23.5.0)
- StripeApplePay (23.5.0):
- StripeCore (= 23.5.0)
- StripeCore (23.5.0)
- StripeFinancialConnections (23.5.0):
- StripeCore (= 23.5.0)
- StripeUICore (= 23.5.0)
- StripePayments (23.5.0):
- StripeCore (= 23.5.0)
- StripePayments/Stripe3DS2 (= 23.5.0)
- StripePayments/Stripe3DS2 (23.5.0):
- StripeCore (= 23.5.0)
- StripePaymentSheet (23.5.0):
- StripeApplePay (= 23.5.0)
- StripeCore (= 23.5.0)
- StripePayments (= 23.5.0)
- StripePaymentsUI (= 23.5.0)
- StripePaymentsUI (23.5.0):
- StripeCore (= 23.5.0)
- StripePayments (= 23.5.0)
- StripeUICore (= 23.5.0)
- StripeUICore (23.5.0):
- StripeCore (= 23.5.0)
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -636,15 +636,15 @@ SPEC CHECKSUMS:
RNCPicker: 0bf8ef8f7800524f32d2bb2a8bcadd53eda0ecd1
RNScreens: 34cc502acf1b916c582c60003dc3089fa01dc66d
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Stripe: d66defd3c57dd95373078c87449737913230f918
stripe-react-native: bf67d91ee381e8972b1b183ee7e0ab90ba0932ce
StripeApplePay: 3b5644c55b3bd58e6fc54bb0d89352cd96496fa0
StripeCore: 727a9f9ec21aa20eccdb357950a7886f8f3bbf8a
StripeFinancialConnections: 65ffa16c4fc0ae86bf6ad17982bc4d8e2f7c0180
StripePayments: 08793f39f68c4551ccb501717e4c1b892536ff86
StripePaymentSheet: cbdd507e72773c3d16a3e87059f8113aa75e8ce9
StripePaymentsUI: 2b1647054756be34abaf52e1f58dba7d08bfedd3
StripeUICore: 1fbe9a33b73633127205175c0e255a4bfb052212
Stripe: 52dea7bd3ef1a679af8406915724b30017713ae9
stripe-react-native: 479082d9d2ffd0cade3b1b8d2e3425a46d4ce2cb
StripeApplePay: e17b49bd1b44817325fcd3c2400b2b21f2462a9a
StripeCore: 8cfb64927054f378af165629d2522894d03bd8fc
StripeFinancialConnections: 607d63237ec9304b42507d3fd4b4a754f01d41e1
StripePayments: 99c899c85eec727e35ecbccb76e21eb42aeb680b
StripePaymentSheet: a6f0116067fec8b3fe8ca583db9efc019725e4ac
StripePaymentsUI: e832ad4db17c3e2b82a69efbd86aea354d1cd77a
StripeUICore: e2c0f925b7446fb7bf73314bd2435dadb1d4057c
Yoga: 0b84a956f7393ef1f37f3bb213c516184e4a689d
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"nodemon": "^2.0.19",
"path": "^0.12.7",
"react-test-renderer": "18.0.0",
"stripe": "^9.0.0",
"stripe": "^11.0.0",
"typescript": "^4.5.5"
}
}
Loading