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

Remove Basic Integration references #1765

Merged
merged 12 commits into from
Oct 30, 2024
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@

## Unreleased

**Breaking changes**

- Removed support for FPX payments via the bank picker UI. If you'd like to accept FPX payments, we recommend using [Mobile Payment Element](https://docs.stripe.com/payments/accept-a-payment?platform=react-native). Also see the [FPX Payment guide](https://docs.stripe.com/payments/fpx/accept-a-payment?web-or-mobile=mobile) for more info on how to integrate FPX specifically.

**Features**

- `CustomerSheet` is now generally available!
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ import com.stripe.android.googlepaylauncher.GooglePayLauncher
import com.stripe.android.model.*
import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.view.AddPaymentMethodActivityStarter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -77,14 +76,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
}
else -> {
dispatchActivityResultsToFragments(requestCode, resultCode, data)
try {
val result = AddPaymentMethodActivityStarter.Result.fromIntent(data)
if (data?.getParcelableExtra<Parcelable>("extra_activity_result") != null) {
onFpxPaymentMethodResult(result)
}
} catch (e: java.lang.Exception) {
Log.d("StripeReactNative", e.localizedMessage ?: e.toString())
}
}
}
}
@@ -219,48 +210,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
paymentSheetFragment?.paymentSheetIntentCreationCallback?.complete(params)
}

private fun payWithFpx() {
getCurrentActivityOrResolveWithError(confirmPromise)?.let {
AddPaymentMethodActivityStarter(it)
.startForResult(AddPaymentMethodActivityStarter.Args.Builder()
.setPaymentMethodType(PaymentMethod.Type.Fpx)
.build()
)
}
}

private fun onFpxPaymentMethodResult(result: AddPaymentMethodActivityStarter.Result) {
when (result) {
is AddPaymentMethodActivityStarter.Result.Success -> {
if (confirmPaymentClientSecret != null && confirmPromise != null) {
paymentLauncherFragment = PaymentLauncherFragment.forPayment(
context = reactApplicationContext,
stripe,
publishableKey,
stripeAccountId,
confirmPromise!!,
confirmPaymentClientSecret!!,
ConfirmPaymentIntentParams.createWithPaymentMethodId(
result.paymentMethod.id!!,
confirmPaymentClientSecret!!
)
)
} else {
Log.e("StripeReactNative", "FPX payment failed. Promise and/or client secret is not set.")
confirmPromise?.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), "FPX payment failed. Client secret is not set."))
}
}
is AddPaymentMethodActivityStarter.Result.Failure -> {
confirmPromise?.resolve(createError(ConfirmPaymentErrorType.Failed.toString(), result.exception))
}
is AddPaymentMethodActivityStarter.Result.Canceled -> {
confirmPromise?.resolve(createError(ConfirmPaymentErrorType.Canceled.toString(), "The payment has been canceled"))
}
}
this.confirmPaymentClientSecret = null
this.confirmPromise = null
}

@ReactMethod
fun createPaymentMethod(data: ReadableMap, options: ReadableMap, promise: Promise) {
val paymentMethodType = getValOr(data, "paymentMethodType")?.let { mapToPaymentMethodType(it) } ?: run {
@@ -460,15 +409,6 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
else
null // Expect that payment method was attached on the server

val testOfflineBank = getBooleanOrFalse(params, "testOfflineBank")

if (paymentMethodType == PaymentMethod.Type.Fpx && !testOfflineBank) {
confirmPaymentClientSecret = paymentIntentClientSecret
confirmPromise = promise
payWithFpx()
return
}

// if (paymentMethodType == PaymentMethod.Type.WeChatPay) {
// val appId = getValOr(params, "appId") ?: run {
// promise.resolve(createError("Failed", "You must provide appId"))
21 changes: 0 additions & 21 deletions e2e-tests/android-only/local-only/fpx.yml

This file was deleted.

21 changes: 0 additions & 21 deletions e2e-tests/ios-only/local-only/fpx.yml

This file was deleted.

3 changes: 0 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ import AlipayPaymentScreen from './screens/AlipayPaymentScreen';
import PaymentResultScreen from './screens/PaymentResultScreen';
import SofortPaymentScreen from './screens/SofortPaymentScreen';
import SofortSetupFuturePaymentScreen from './screens/SofortSetupFuturePaymentScreen';
import FPXPaymentScreen from './screens/FPXPaymentScreen';
import BancontactPaymentScreen from './screens/BancontactPaymentScreen';
import BancontactSetupFuturePaymentScreen from './screens/BancontactSetupFuturePaymentScreen';
import SepaPaymentScreen from './screens/SepaPaymentScreen';
@@ -65,7 +64,6 @@ export type RootStackParamList = {
PaymentResultScreen: { url: string };
SofortPaymentScreen: undefined;
SofortSetupFuturePaymentScreen: undefined;
FPXPaymentScreen: undefined;
BancontactPaymentScreen: undefined;
BancontactSetupFuturePaymentScreen: undefined;
SepaPaymentScreen: undefined;
@@ -190,7 +188,6 @@ export default function App() {
name="PaymentResultScreen"
component={PaymentResultScreen}
/>
<Stack.Screen name="FPXPaymentScreen" component={FPXPaymentScreen} />
<Stack.Screen
name="SofortPaymentScreen"
component={SofortPaymentScreen}
97 changes: 0 additions & 97 deletions example/src/screens/FPXPaymentScreen.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -239,14 +239,6 @@ export default function HomeScreen() {
/>
</View>

<View style={styles.buttonContainer}>
<Button
title="FPX"
onPress={() => {
navigation.navigate('FPXPaymentScreen');
}}
/>
</View>
<View style={styles.buttonContainer}>
<Button
title="giropay"
17 changes: 0 additions & 17 deletions ios/CardFieldView.swift
Original file line number Diff line number Diff line change
@@ -194,21 +194,4 @@ class CardFieldView: UIView, STPPaymentCardTextFieldDelegate {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {
//
}

func paymentContextDidChange(_ paymentContext: STPPaymentContext) {
//
}

func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPPaymentStatusBlock) {
//
}

func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {
//
}

}
95 changes: 29 additions & 66 deletions ios/StripeSdk.swift
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import StripeFinancialConnections
import Foundation

@objc(StripeSdk)
class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdaptivePresentationControllerDelegate {
class StripeSdk: RCTEventEmitter, UIAdaptivePresentationControllerDelegate {
public var cardFieldView: CardFieldView? = nil
public var cardFormView: CardFormView? = nil

@@ -14,21 +14,21 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
internal var paymentSheet: PaymentSheet?
internal var paymentSheetFlowController: PaymentSheet.FlowController?
var paymentSheetIntentCreationCallback: ((Result<String, Error>) -> Void)?

var urlScheme: String? = nil

var confirmPaymentResolver: RCTPromiseResolveBlock? = nil

var confirmApplePayResolver: RCTPromiseResolveBlock? = nil
var confirmApplePayPaymentClientSecret: String? = nil
var confirmApplePaySetupClientSecret: String? = nil
var confirmApplePayPaymentMethod: STPPaymentMethod? = nil

var applePaymentAuthorizationController: PKPaymentAuthorizationViewController? = nil
var createPlatformPayPaymentMethodResolver: RCTPromiseResolveBlock? = nil
var platformPayUsesDeprecatedTokenFlow = false
var applePaymentMethodFlowCanBeCanceled = false

var confirmPaymentClientSecret: String? = nil

var shippingMethodUpdateCompletion: ((PKPaymentRequestShippingMethodUpdate) -> Void)? = nil
@@ -48,7 +48,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
var applePayShippingMethods: [PKShippingMethod] = []
var applePayShippingAddressErrors: [Error]? = nil
var applePayCouponCodeErrors: [Error]? = nil

var customerSheetConfiguration = CustomerSheet.Configuration()
var customerSheet: CustomerSheet? = nil
var customerAdapter: StripeCustomerAdapter? = nil
@@ -59,15 +59,15 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
var setSelectedPaymentOptionCallback: (() -> Void)? = nil
var fetchSelectedPaymentOptionCallback: ((CustomerPaymentOption?) -> Void)? = nil
var setupIntentClientSecretForCustomerAttachCallback: ((String) -> Void)? = nil

var hasEventListeners = false
override func startObserving() {
hasEventListeners = true
}
override func stopObserving() {
hasEventListeners = false
}

override func supportedEvents() -> [String]! {
return ["onOrderTrackingCallback", "onConfirmHandlerCallback", "onCustomerAdapterFetchPaymentMethodsCallback", "onCustomerAdapterAttachPaymentMethodCallback",
"onCustomerAdapterDetachPaymentMethodCallback", "onCustomerAdapterSetSelectedPaymentOptionCallback", "onCustomerAdapterFetchSelectedPaymentOptionCallback",
@@ -124,10 +124,10 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
resolve(error)
return
}

preparePaymentSheetInstance(params: params, configuration: configuration, resolve: resolve)
}

@objc(intentCreationCallback:resolver:rejecter:)
func intentCreationCallback(result: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
@@ -174,7 +174,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
}
}
}

@objc(resetPaymentSheetCustomer:rejecter:)
func resetPaymentSheetCustomer(resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
@@ -187,7 +187,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
var paymentSheetViewController: UIViewController?

if let timeout = options["timeout"] as? Double {
DispatchQueue.main.asyncAfter(deadline: .now() + timeout/1000) {
if let paymentSheetViewController = paymentSheetViewController {
@@ -278,7 +278,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
err = Errors.createError(ErrorType.Failed, error as NSError?)
}
}

parameters.mandateData = factory.createMandateData()

return parameters
@@ -330,28 +330,28 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
}
return false
}()

if (shippingMethodUpdateCompletion == nil && shippingContactUpdateCompletion == nil && couponUpdateHandlerIsNil) {
resolve(Errors.createError(ErrorType.Failed, "You can use this method only after either onShippingContactSelected, onShippingMethodSelected, or onCouponCodeEntered callbacks are triggered"))
return
}

do {
applePaySummaryItems = try ApplePayUtils.buildPaymentSummaryItems(items: summaryItems as? [[String : Any]])
} catch {
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
return
}

applePayShippingMethods = ApplePayUtils.buildShippingMethods(items: shippingMethods as? [[String : Any]])

do {
(applePayShippingAddressErrors, applePayCouponCodeErrors) = try ApplePayUtils.buildApplePayErrors(errorItems: errors)
} catch {
resolve(Errors.createError(ErrorType.Failed, error.localizedDescription))
return
}


shippingMethodUpdateCompletion?(PKPaymentRequestShippingMethodUpdate.init(paymentSummaryItems: applePaySummaryItems))
shippingContactUpdateCompletion?(PKPaymentRequestShippingContactUpdate.init(errors: applePayShippingAddressErrors, paymentSummaryItems: applePaySummaryItems, shippingMethods: applePayShippingMethods))
@@ -386,14 +386,14 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
}
}
}

@objc(isPlatformPaySupported:resolver:rejecter:)
func isPlatformPaySupported(params: NSDictionary,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
resolve(StripeAPI.deviceSupportsApplePay())
}

@objc(createPlatformPayPaymentMethod:usesDeprecatedTokenFlow:resolver:rejecter:)
func createPlatformPayPaymentMethod(params: NSDictionary,
usesDeprecatedTokenFlow: Bool,
@@ -408,7 +408,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
resolve(error)
return
}

self.applePaySummaryItems = paymentRequest.paymentSummaryItems
self.applePayShippingMethods = paymentRequest.shippingMethods ?? []
self.applePayShippingAddressErrors = nil
@@ -431,13 +431,13 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
resolve(Errors.createError(ErrorType.Failed, "Invalid in-app payment request. Search the iOS logs for `NSUnderlyingError` to get more information."))
}
}

@objc(dismissPlatformPay:rejecter:)
func dismissPlatformPay(resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
let didDismiss = maybeDismissApplePay()
resolve(didDismiss)
}

@objc(confirmPlatformPay:params:isPaymentIntent:resolver:rejecter:)
func confirmPlatformPay(
clientSecret: String?,
@@ -475,7 +475,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
resolve(Errors.createError(ErrorType.Failed, "Payment not completed"))
}
}

func configure3dSecure(_ params: NSDictionary) {
let threeDSCustomizationSettings = STPPaymentHandler.shared().threeDSCustomizationSettings
let uiCustomization = Mappers.mapUICustomization(params)
@@ -695,7 +695,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
}
}
}

@objc(collectBankAccount:clientSecret:params:resolver:rejecter:)
func collectBankAccount(
isPaymentIntent: Bool,
@@ -806,14 +806,6 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
return
}

if (paymentMethodType == .FPX) {
let testOfflineBank = paymentMethodData?["testOfflineBank"] as? Bool
if (testOfflineBank == false || testOfflineBank == nil) {
payWithFPX(paymentIntentClientSecret)
return
}
}

let (error, paymentIntentParams) = createPaymentIntentParams(paymentIntentClientSecret: paymentIntentClientSecret, paymentMethodType: paymentMethodType, paymentMethodData: paymentMethodData, options: options)

if (error != nil) {
@@ -864,14 +856,14 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
err = Errors.createError(ErrorType.Failed, error as NSError?)
}
}

do {
parameters.paymentMethodOptions = try factory.createOptions(paymentMethodType: paymentMethodType)
parameters.mandateData = factory.createMandateData()
} catch {
err = Errors.createError(ErrorType.Failed, error as NSError?)
}

return parameters
}
}()
@@ -1071,7 +1063,7 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
}
FinancialConnections.present(withClientSecret: clientSecret, returnURL: returnURL, resolve: resolve)
}

@objc(configureOrderTracking:orderIdentifier:webServiceUrl:authenticationToken:resolver:rejecter:)
func configureOrderTracking(
orderTypeIdentifier: String,
@@ -1102,35 +1094,6 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap
confirmPaymentResolver?(Errors.createError(ErrorType.Canceled, "FPX Payment has been canceled"))
}

func payWithFPX(_ paymentIntentClientSecret: String) {
let vc = STPBankSelectionViewController.init(bankMethod: .FPX)

vc.delegate = self

DispatchQueue.main.async {
vc.presentationController?.delegate = self

let share = UIApplication.shared.delegate
share?.window??.rootViewController?.present(vc, animated: true)
}
}

func bankSelectionViewController(_ bankViewController: STPBankSelectionViewController, didCreatePaymentMethodParams paymentMethodParams: STPPaymentMethodParams) {
guard let clientSecret = confirmPaymentClientSecret else {
confirmPaymentResolver?(Errors.createError(ErrorType.Failed, "Missing paymentIntentClientSecret"))
return
}
let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret)
paymentIntentParams.paymentMethodParams = paymentMethodParams

if let urlScheme = urlScheme {
paymentIntentParams.returnURL = Mappers.mapToReturnURL(urlScheme: urlScheme)
}
let paymentHandler = STPPaymentHandler.shared()
bankViewController.dismiss(animated: true)
paymentHandler.confirmPayment(paymentIntentParams, with: self, completion: onCompleteConfirmPayment)
}

func onCompleteConfirmPayment(status: STPPaymentHandlerActionStatus, paymentIntent: STPPaymentIntent?, error: NSError?) {
self.confirmPaymentClientSecret = nil
switch (status) {