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

[ios] Update stripe-react-native to 0.18.1 to fix compilation errors in Xcode 14 #19055

Merged
merged 1 commit into from Sep 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ Package-specific changes not released in any SDK will be added here just before

### 📚 3rd party library updates

- Updated `@stripe/stripe-react-native` from `0.13.1` to `0.18.1` on iOS. ([#19055](https://github.com/expo/expo/pull/19055) by [@tsapeta](https://github.com/tsapeta))

### 🛠 Breaking changes

### 🎉 New features
Expand Down
64 changes: 32 additions & 32 deletions ios/Podfile.lock
Expand Up @@ -623,8 +623,8 @@ PODS:
- ABI45_0_0React-RCTImage
- ABI45_0_0stripe-react-native (0.6.0):
- ABI45_0_0React-Core
- Stripe (~> 22.4.0)
- StripeFinancialConnections (~> 22.4.0)
- Stripe (~> 22.7.0)
- StripeFinancialConnections (~> 22.7.0)
- ABI45_0_0UMAppLoader (3.1.0)
- ABI45_0_0Yoga (1.14.0)
- ABI46_0_0EASClient (0.3.0):
Expand Down Expand Up @@ -1269,8 +1269,8 @@ PODS:
- ABI46_0_0React-RCTImage
- ABI46_0_0stripe-react-native (0.13.1):
- ABI46_0_0React-Core
- Stripe (~> 22.4.0)
- StripeFinancialConnections (~> 22.4.0)
- Stripe (~> 22.7.0)
- StripeFinancialConnections (~> 22.7.0)
- ABI46_0_0UMAppLoader (3.1.0)
- ABI46_0_0Yoga (1.14.0)
- Amplitude (6.0.0)
Expand Down Expand Up @@ -2027,27 +2027,27 @@ PODS:
- RNScreens (3.15.0):
- React-Core
- React-RCTImage
- Stripe (22.4.0):
- Stripe/Stripe3DS2 (= 22.4.0)
- StripeApplePay (= 22.4.0)
- StripeCore (= 22.4.0)
- StripeUICore (= 22.4.0)
- stripe-react-native (0.13.1):
- Stripe (22.7.1):
- Stripe/Stripe3DS2 (= 22.7.1)
- StripeApplePay (= 22.7.1)
- StripeCore (= 22.7.1)
- StripeUICore (= 22.7.1)
- stripe-react-native (0.18.1):
- React-Core
- Stripe (~> 22.4.0)
- StripeFinancialConnections (~> 22.4.0)
- Stripe/Stripe3DS2 (22.4.0):
- StripeApplePay (= 22.4.0)
- StripeCore (= 22.4.0)
- StripeUICore (= 22.4.0)
- StripeApplePay (22.4.0):
- StripeCore (= 22.4.0)
- StripeCore (22.4.0)
- StripeFinancialConnections (22.4.0):
- StripeCore (= 22.4.0)
- StripeUICore (= 22.4.0)
- StripeUICore (22.4.0):
- StripeCore (= 22.4.0)
- Stripe (~> 22.7.0)
- StripeFinancialConnections (~> 22.7.0)
- Stripe/Stripe3DS2 (22.7.1):
- StripeApplePay (= 22.7.1)
- StripeCore (= 22.7.1)
- StripeUICore (= 22.7.1)
- StripeApplePay (22.7.1):
- StripeCore (= 22.7.1)
- StripeCore (22.7.1)
- StripeFinancialConnections (22.7.1):
- StripeCore (= 22.7.1)
- StripeUICore (= 22.7.1)
- StripeUICore (22.7.1):
- StripeCore (= 22.7.1)
- UMAppLoader (3.1.0)
- Yoga (1.14.0)
- ZXingObjC/Core (3.6.5)
Expand Down Expand Up @@ -3223,7 +3223,7 @@ SPEC CHECKSUMS:
ABI45_0_0RNGestureHandler: c6a3399e797896b51aaafa5ffd9ef3217a965554
ABI45_0_0RNReanimated: 7dbc4ffd288bfbb8657e5d28d8c633108a4fbc7a
ABI45_0_0RNScreens: 09474fa5b21fada696fcfda7029ea1de53af363b
ABI45_0_0stripe-react-native: 165947b4b857c03da141aae92470620c0d2e742c
ABI45_0_0stripe-react-native: 48734eb853a923bbf041ceab5ac065c9a2c08d49
ABI45_0_0UMAppLoader: 9f4f8ab793e254030a3e1986ce2d75b89308168b
ABI45_0_0Yoga: 59ff587f79c3e37f52418bef27055ecf8e0bce1c
ABI46_0_0EASClient: c419fef100fbdac83e755c790d6b427594d4263e
Expand Down Expand Up @@ -3330,7 +3330,7 @@ SPEC CHECKSUMS:
ABI46_0_0RNGestureHandler: 42f00c4ce0ac12c4c51081de65e2ba831dfd5cb7
ABI46_0_0RNReanimated: c68969af1eae15d09ee5b8b3b61407feb5db9884
ABI46_0_0RNScreens: f521a4613dc2207aab4fcd72b5bb7cef74104a39
ABI46_0_0stripe-react-native: 7f12b5c30e713ef7d444295e7021acb13ccff2fb
ABI46_0_0stripe-react-native: 599bc13001fb6eae9a687e1eb587c720d04ee744
ABI46_0_0UMAppLoader: 271ab738d153f711d91da6b1b7a3a981d668dcfe
ABI46_0_0Yoga: 898c6ba86e91d19b0810efa11e8a6c7e5559a64d
Amplitude: cc34fcd8dfffc3470bc2e05f3a4abb0178f6d963
Expand Down Expand Up @@ -3483,12 +3483,12 @@ SPEC CHECKSUMS:
RNGestureHandler: bad495418bcbd3ab47017a38d93d290ebd406f50
RNReanimated: 5c8c17e26787fd8984cd5accdc70fef2ca70aafd
RNScreens: 4a1af06327774490d97342c00aee0c2bafb497b7
Stripe: a925dfa9a7e51aa8f782f428abc10cb828b45a85
stripe-react-native: 01069cba9dfaaf108df9c65a266ff753f311ddc8
StripeApplePay: 369857bafe8baf02e31b47478db1574febd2a2f3
StripeCore: a94d2823817c97c79fce60884ab9027a2da798c1
StripeFinancialConnections: 269658b79f639c2d6b7d513235d469418b04c2dd
StripeUICore: a8e24a6c91a5c99075c7a490d45695fb912876e8
Stripe: fb29a476e4866fec4ef22fb76207363dd32795aa
stripe-react-native: 5663bf9de94bff6b3d92c16d32784433b5e94cf7
StripeApplePay: 09955cdf3f49b367af2feadd9c5b3bddb35446c0
StripeCore: 39ea580c26ccc324fb9671288a2ae21114e54dca
StripeFinancialConnections: 0e1d638388572d52ce829416fbc7b0af2bde3865
StripeUICore: eed17e95a4517fc02482e250a6422c2a81a14ce8
UMAppLoader: 6185e8c45922f187002b85afae097961c4781df4
Yoga: 7ab6e3ee4ce47d7b789d1cb520163833e515f452
ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb
Expand Down
Expand Up @@ -16,10 +16,10 @@
"dependencies": {
"ABI45_0_0React-Core": [],
"Stripe": [
"~> 22.4.0"
"~> 22.7.0"
],
"StripeFinancialConnections": [
"~> 22.4.0"
"~> 22.7.0"
]
},
"pod_target_xcconfig": {
Expand Down
Expand Up @@ -16,10 +16,10 @@
"dependencies": {
"ABI46_0_0React-Core": [],
"Stripe": [
"~> 22.4.0"
"~> 22.7.0"
],
"StripeFinancialConnections": [
"~> 22.4.0"
"~> 22.7.0"
]
},
"pod_target_xcconfig": {
Expand Down
@@ -0,0 +1,159 @@
//
// ApplePayUtils.swift
// stripe-react-native
//
// Created by Charles Cruzan on 6/27/22.
//

import Foundation
import Stripe

class ApplePayUtils {

@available(iOS 15.0, *)
internal class func createDeferredPaymentSummaryItem(item: [String : Any]) throws -> PKPaymentSummaryItem {
let label = item["label"] as? String ?? ""
let amount = NSDecimalNumber(string: item["amount"] as? String ?? "")

let deferredItem = PKDeferredPaymentSummaryItem(
label: label,
amount: amount
)
guard let date = item["deferredDate"] as? Double else {
throw ApplePayUtilsError.missingParameter(label, "deferredDate")
}
deferredItem.deferredDate = Date(timeIntervalSince1970: date)
return deferredItem
}

@available(iOS 15.0, *)
internal class func createRecurringPaymentSummaryItem(item: [String : Any]) throws -> PKPaymentSummaryItem {
let label = item["label"] as? String ?? ""
let amount = NSDecimalNumber(string: item["amount"] as? String ?? "")

let recurringItem = PKRecurringPaymentSummaryItem(
label: label,
amount: amount
)
guard let intervalCount = item["intervalCount"] as? Int else {
throw ApplePayUtilsError.missingParameter(label, "intervalCount")
}
recurringItem.intervalCount = intervalCount
recurringItem.intervalUnit = try mapToIntervalUnit(intervalString: item["intervalUnit"] as? String)
if let startDate = item["startDate"] as? Double {
recurringItem.startDate = Date(timeIntervalSince1970: startDate)
}
if let endDate = item["endDate"] as? Double {
recurringItem.endDate = Date(timeIntervalSince1970: endDate)
}
return recurringItem
}

internal class func mapToIntervalUnit(intervalString: String?) throws -> NSCalendar.Unit {
switch intervalString {
case "minute":
return NSCalendar.Unit.minute
case "hour":
return NSCalendar.Unit.hour
case "day":
return NSCalendar.Unit.day
case "month":
return NSCalendar.Unit.month
case "year":
return NSCalendar.Unit.year
default:
throw ApplePayUtilsError.invalidTimeInterval(intervalString ?? "null")
}
}

internal class func createImmediatePaymentSummaryItem(item: [String : Any]) -> PKPaymentSummaryItem {
let label = item["label"] as? String ?? ""
let amount = NSDecimalNumber(string: item["amount"] as? String ?? "")

return PKPaymentSummaryItem(
label: label,
amount: amount,
type: item["isPending"] as? Bool ?? false ?
PKPaymentSummaryItemType.pending : PKPaymentSummaryItemType.final
)
}

public class func buildPaymentSummaryItems(items: [[String : Any]]?) throws -> [PKPaymentSummaryItem] {
var paymentSummaryItems: [PKPaymentSummaryItem] = []
if let items = items {
for item in items {
let paymentSummaryItem = try buildPaymentSummaryItem(item: item)
paymentSummaryItems.append(paymentSummaryItem)
}
}

return paymentSummaryItems
}

internal class func buildPaymentSummaryItem(item: [String : Any]) throws -> PKPaymentSummaryItem {
switch item["paymentType"] as? String {
case "Deferred":
if #available(iOS 15.0, *) {
return try createDeferredPaymentSummaryItem(item: item)
} else {
return createImmediatePaymentSummaryItem(item: item)
}
case "Recurring":
if #available(iOS 15.0, *) {
return try createRecurringPaymentSummaryItem(item: item)
} else {
return createImmediatePaymentSummaryItem(item: item)
}
case "Immediate":
return createImmediatePaymentSummaryItem(item: item)
default:
throw ApplePayUtilsError.invalidCartSummaryItemType(item["paymentType"] as? String ?? "null")
}
}

public class func buildPaymentSheetApplePayConfig(
merchantIdentifier: String?,
merchantCountryCode: String?,
paymentSummaryItems: [[String : Any]]?
) throws -> PaymentSheet.ApplePayConfiguration {
guard let merchantId = merchantIdentifier else {
throw ApplePayUtilsError.missingMerchantId
}
guard let countryCode = merchantCountryCode else {
throw ApplePayUtilsError.missingCountryCode
}
let paymentSummaryItems = try ApplePayUtils.buildPaymentSummaryItems(
items: paymentSummaryItems
)
return PaymentSheet.ApplePayConfiguration.init(
merchantId: merchantId,
merchantCountryCode: countryCode,
paymentSummaryItems:paymentSummaryItems.count > 0 ? paymentSummaryItems : nil
)
}
}

enum ApplePayUtilsError : Error, Equatable {
case invalidCartSummaryItemType(String)
case missingParameter(String, String)
case invalidTimeInterval(String)
case missingMerchantId
case missingCountryCode
}

extension ApplePayUtilsError: LocalizedError {
public var errorDescription: String? {
switch self {
case .invalidCartSummaryItemType(let type):
return "Failed to ceate Apple Pay summary item. Expected `type` to be one of 'Immediate', 'Recurring', or 'Deferred', but received: \(type)"
case .missingParameter(let label, let parameter):
return "Failed to create Apple Pay summary item with label: \(label). The \(parameter) item parameter is required, but none was provided."
case .invalidTimeInterval(let providedInterval):
return "Failed to create Apple Pay summary item. \(providedInterval) is not a valid timeInterval, must be one of: minute, hour, day, month, or year."
case .missingMerchantId:
return "`merchantIdentifier` is required, but none was found. Ensure you are passing this to initStripe your StripeProvider."
case .missingCountryCode:
return "`merchantCountryCode` is a required param, but was not provided."
}
}
}
Expand Up @@ -132,13 +132,16 @@ class CardFieldView: UIView, STPPaymentCardTextFieldDelegate {

func paymentCardTextFieldDidChange(_ textField: STPPaymentCardTextField) {
if onCardChange != nil {
let brand = STPCardValidator.brand(forNumber: textField.cardParams.number ?? "")
let validExpiryDate = STPCardValidator.validationState(forExpirationYear: textField.cardParams.expYear?.stringValue ?? "", inMonth: textField.cardParams.expMonth?.stringValue ?? "")
let validCVC = STPCardValidator.validationState(forCVC: textField.cardParams.cvc ?? "", cardBrand: brand)
let validNumber = STPCardValidator.validationState(forNumber: textField.cardParams.number ?? "", validatingCardBrand: true)
let brand = STPCardValidator.brand(forNumber: textField.cardNumber ?? "")
let validExpiryDate = STPCardValidator.validationState(
forExpirationYear: textField.formattedExpirationYear ?? "",
inMonth: textField.formattedExpirationMonth ?? ""
)
let validCVC = STPCardValidator.validationState(forCVC: textField.cvc ?? "", cardBrand: brand)
let validNumber = STPCardValidator.validationState(forNumber: textField.cardNumber ?? "", validatingCardBrand: true)
var cardData: [String: Any?] = [
"expiryMonth": textField.cardParams.expMonth ?? NSNull(),
"expiryYear": textField.cardParams.expYear ?? NSNull(),
"expiryMonth": textField.expirationMonth,
"expiryYear": textField.expirationYear,
"complete": textField.isValid,
"brand": Mappers.mapFromCardBrand(brand) ?? NSNull(),
"last4": textField.cardParams.last4 ?? "",
Expand All @@ -150,8 +153,8 @@ class CardFieldView: UIView, STPPaymentCardTextFieldDelegate {
cardData["postalCode"] = textField.postalCode ?? ""
}
if (dangerouslyGetFullCardDetails) {
cardData["number"] = textField.cardParams.number ?? ""
cardData["cvc"] = textField.cardParams.cvc ?? ""
cardData["number"] = textField.cardNumber ?? ""
cardData["cvc"] = textField.cvc ?? ""
}
onCardChange!(cardData as [AnyHashable : Any])
}
Expand Down
Expand Up @@ -75,6 +75,26 @@ class CardFormView: UIView, STPCardFormViewDelegate {
if let backgroundColor = cardStyle["backgroundColor"] as? String {
cardForm?.backgroundColor = UIColor(hexString: backgroundColor)
}
/**
The following reveals a bug in STPCardFormView where there's a extra space in the layer,
and thus must remain commented out for now.

if let borderWidth = cardStyle["borderWidth"] as? Int {
cardForm?.layer.borderWidth = CGFloat(borderWidth)
} else {
cardForm?.layer.borderWidth = CGFloat(0)
}

*/
if let borderColor = cardStyle["borderColor"] as? String {
cardForm?.layer.borderColor = UIColor(hexString: borderColor).cgColor
}
if let borderRadius = cardStyle["borderRadius"] as? Int {
cardForm?.layer.cornerRadius = CGFloat(borderRadius)
}
if let cursorColor = cardStyle["cursorColor"] as? String {
cardForm?.tintColor = UIColor(hexString: cursorColor)
}
// if let disabledBackgroundColor = cardStyle["disabledBackgroundColor"] as? String {
// cardForm?.disabledBackgroundColor = UIColor(hexString: disabledBackgroundColor)
// }
Expand Down
@@ -1,4 +1,5 @@
import Stripe
@_spi(STP) import StripeCore

enum ErrorType {
static let Failed = "Failed"
Expand Down Expand Up @@ -50,7 +51,7 @@ class Errors {
class func createError (_ code: String, _ error: NSError?) -> NSDictionary {
let value: NSDictionary = [
"code": code,
"message": error?.userInfo[STPError.errorMessageKey] ?? NSNull(),
"message": error?.userInfo[STPError.errorMessageKey] ?? error?.localizedDescription ?? NSNull(),
"localizedMessage": error?.localizedDescription ?? NSNull(),
"declineCode": error?.userInfo[STPError.stripeDeclineCodeKey] ?? NSNull(),
"stripeErrorCode": error?.userInfo[STPError.stripeErrorCodeKey] ?? NSNull(),
Expand Down Expand Up @@ -84,5 +85,15 @@ class Errors {

return ["error": value]
}

class func createError(_ code: String, _ error: Error) -> NSDictionary {
if let stripeError = error as? StripeError {
return createError(code, NSError.stp_error(from: stripeError))
}

return createError(code, error as NSError)
}

static let MISSING_INIT_ERROR = Errors.createError(ErrorType.Failed, "Stripe has not been initialized. Initialize Stripe in your app with the StripeProvider component or the initStripe method.")
}