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

Update stripe bindings to last version #7

Merged
merged 1 commit into from
Apr 4, 2021
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
39 changes: 12 additions & 27 deletions stripe_ios/ios/Classes/ApplePayButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ApplePayButtonView: NSObject, FlutterPlatformView {
) {
channel = FlutterMethodChannel(name: "flutter.stripe/apple_pay/\(viewId)",
binaryMessenger: messenger)
_view = FLEmbedView()
_view = UIView()
super.init()
if let arguments = args as? Dictionary<String, AnyObject> {
type = arguments["type"] as? NSNumber
Expand Down Expand Up @@ -97,32 +97,17 @@ class ApplePayButtonView: NSObject, FlutterPlatformView {
let paymentButtonStyle = PKPaymentButtonStyle(rawValue: self.style as? Int ?? 2) ?? .black
self.applePayButton = PKPaymentButton(paymentButtonType: paymentButtonType, paymentButtonStyle: paymentButtonStyle)

if let applePayButton = self.applePayButton {
applePayButton.frame = _view.frame
applePayButton.addTarget(self, action: #selector(handleApplePayButtonTapped), for: .touchUpInside)
_view.addSubview(applePayButton)
}
}



}
if let applePayButton = self.applePayButton {
applePayButton.translatesAutoresizingMaskIntoConstraints = false
applePayButton.addTarget(self, action: #selector(handleApplePayButtonTapped), for: .touchUpInside)
_view.addSubview(applePayButton)

applePayButton.topAnchor.constraint(equalTo: _view.topAnchor).isActive = true
applePayButton.bottomAnchor.constraint(equalTo: _view.bottomAnchor).isActive = true
applePayButton.leftAnchor.constraint(equalTo: _view.leftAnchor).isActive = true
applePayButton.rightAnchor.constraint(equalTo: _view.rightAnchor).isActive = true


class FLEmbedView : UIView {

override init(frame: CGRect) {
super.init(frame: frame)
}

required init?(coder: NSCoder) {
super.init(coder: coder)
}

override func layoutSubviews() {
for view in subviews {
view.frame = self.frame
}
}
super.layoutSubviews()
}

}
7 changes: 6 additions & 1 deletion stripe_ios/ios/Classes/CardFieldView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FlutterCardFieldView: NSObject, FlutterPlatformView {
) {
channel = FlutterMethodChannel(name: "flutter.stripe/card_field/\(viewId)",
binaryMessenger: messenger)
_view = FLEmbedView()
_view = UIView()
super.init()


Expand Down Expand Up @@ -103,7 +103,12 @@ class FlutterCardFieldView: NSObject, FlutterPlatformView {
self.cardFieldView = CardFieldView(frame: CGRect.zero, delegate: self)

if let cardFieldView = self.cardFieldView {
cardFieldView.translatesAutoresizingMaskIntoConstraints = false
_view.addSubview(cardFieldView)
cardFieldView.topAnchor.constraint(equalTo: _view.topAnchor).isActive = true
cardFieldView.bottomAnchor.constraint(equalTo: _view.bottomAnchor).isActive = true
cardFieldView.leftAnchor.constraint(equalTo: _view.leftAnchor).isActive = true
cardFieldView.rightAnchor.constraint(equalTo: _view.rightAnchor).isActive = true
}
}

Expand Down
6 changes: 0 additions & 6 deletions stripe_ios/ios/Classes/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ enum RetrievePaymentIntentErrorType: String {
case Unknown
}

enum PaymentSheetErrorType: String {
case Failed, Canceled
}


class Errors {
class func createError (code: String, message: String) -> NSDictionary {
let error: NSDictionary = [
Expand All @@ -32,5 +27,4 @@ class Errors {

return error
}

}
106 changes: 64 additions & 42 deletions stripe_ios/ios/Classes/Mappers.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Stripe

class Mappers {
class func mapToPKContactField(field: String) -> PKContactField {
switch field {
Expand Down Expand Up @@ -46,7 +47,7 @@ class Mappers {
let method: NSDictionary = [
"detail": shippingMethod.detail ?? "",
"identifier": shippingMethod.identifier ?? "",
"amount": shippingMethod.amount.stringValue,
"amount": shippingMethod.amount.stringValue,
"type": shippingMethod.type,
"label": shippingMethod.label
]
Expand Down Expand Up @@ -122,18 +123,41 @@ class Mappers {
}
}

class func mapCardParamsToPaymentMethodParams(params: NSDictionary, billingDetails: STPPaymentMethodBillingDetails?) -> STPPaymentMethodParams {
class func mapToPaymentMethodType(type: String?) -> STPPaymentMethodType? {
if let type = type {
switch type {
case "Card": return STPPaymentMethodType.card
case "Alipay": return STPPaymentMethodType.alipay
case "GrabPay": return STPPaymentMethodType.grabPay
case "Ideal": return STPPaymentMethodType.iDEAL
case "Fpx": return STPPaymentMethodType.FPX
case "CardPresent": return STPPaymentMethodType.cardPresent
case "SepaDebit": return STPPaymentMethodType.SEPADebit
case "AuBecsDebit": return STPPaymentMethodType.AUBECSDebit
case "BacsDebit": return STPPaymentMethodType.bacsDebit
case "Giropay": return STPPaymentMethodType.giropay
case "P24": return STPPaymentMethodType.przelewy24
case "Eps": return STPPaymentMethodType.EPS
case "Bancontact": return STPPaymentMethodType.bancontact
case "Oxxo": return STPPaymentMethodType.OXXO
case "Sofort": return STPPaymentMethodType.sofort
case "Upi": return STPPaymentMethodType.UPI
default: return STPPaymentMethodType.unknown
}
}
return nil
}

class func mapToPaymentMethodCardParams(params: NSDictionary) -> STPPaymentMethodCardParams {
let cardSourceParams = STPCardParams()
cardSourceParams.number = params["number"] as? String
cardSourceParams.cvc = params["cvc"] as? String
cardSourceParams.expMonth = params["expiryMonth"] as! UInt
cardSourceParams.expYear = params["expiryYear"] as! UInt
cardSourceParams.number = RCTConvert.nsString(params["number"])
cardSourceParams.cvc = RCTConvert.nsString(params["cvc"])
cardSourceParams.expMonth = RCTConvert.nsuInteger(params["expiryMonth"])
cardSourceParams.expYear = RCTConvert.nsuInteger(params["expiryYear"])

let cardParams = STPPaymentMethodCardParams(cardSourceParams: cardSourceParams)
return STPPaymentMethodParams(card: cardParams, billingDetails: billingDetails, metadata: nil)
return STPPaymentMethodCardParams(cardSourceParams: cardSourceParams)
}


class func mapCaptureMethod(_ captureMethod: STPPaymentIntentCaptureMethod?) -> String {
if let captureMethod = captureMethod {
switch captureMethod {
Expand Down Expand Up @@ -237,20 +261,23 @@ class Mappers {
return "Unknown"
}

class func mapToBillingDetails(billingDetails: NSDictionary) -> STPPaymentMethodBillingDetails {
class func mapToBillingDetails(billingDetails: NSDictionary?) -> STPPaymentMethodBillingDetails? {
guard let billingDetails = billingDetails else {
return nil
}
let billing = STPPaymentMethodBillingDetails()
billing.email = billingDetails["email"] as? String
billing.phone = billingDetails["phone"] as? String
billing.name = billingDetails["name"] as? String
billing.email = RCTConvert.nsString(billingDetails["email"])
billing.phone = RCTConvert.nsString(billingDetails["phone"])
billing.name = RCTConvert.nsString(billingDetails["name"])

let billingAddres = STPPaymentMethodAddress()

billingAddres.city = billingDetails["addressCity"] as? String
billingAddres.postalCode = billingDetails["addressPostalCode"] as? String
billingAddres.country = billingDetails["addressCountry"] as? String
billingAddres.line1 = billingDetails["addressLine1"] as? String
billingAddres.line2 = billingDetails["addressLine2"] as? String
billingAddres.state = billingDetails["addressState"] as? String
billingAddres.city = RCTConvert.nsString(billingDetails["addressCity"])
billingAddres.postalCode = RCTConvert.nsString(billingDetails["addressPostalCode"])
billingAddres.country = RCTConvert.nsString(billingDetails["addressCountry"])
billingAddres.line1 = RCTConvert.nsString(billingDetails["addressLine1"])
billingAddres.line2 = RCTConvert.nsString(billingDetails["addressLine2"])
billingAddres.state = RCTConvert.nsString(billingDetails["addressState"])

billing.address = billingAddres

Expand Down Expand Up @@ -278,18 +305,18 @@ class Mappers {
class func mapCardBrand(_ brand: STPCardBrand?) -> String {
if let brand = brand {
switch brand {
case STPCardBrand.visa: return "visa"
case STPCardBrand.amex: return "americanExpress"
case STPCardBrand.mastercard: return "masterCard"
case STPCardBrand.discover: return "discover"
case STPCardBrand.JCB: return "jCB"
case STPCardBrand.dinersClub: return "dinersClub"
case STPCardBrand.unionPay: return "unionPay"
case STPCardBrand.unknown: return "unknown"
default: return "unknown"
case STPCardBrand.visa: return "Visa"
case STPCardBrand.amex: return "AmericanExpress"
case STPCardBrand.mastercard: return "MasterCard"
case STPCardBrand.discover: return "Discover"
case STPCardBrand.JCB: return "JCB"
case STPCardBrand.dinersClub: return "DinersClub"
case STPCardBrand.unionPay: return "UnionPay"
case STPCardBrand.unknown: return "Unknown"
default: return "Unknown"
}
}
return "unknown"
return "Unknown"
}

class func mapFromPaymentMethod(_ paymentMethod: STPPaymentMethod) -> NSDictionary {
Expand Down Expand Up @@ -347,10 +374,10 @@ class Mappers {

class func mapCardParams(params: NSDictionary) -> STPPaymentMethodCardParams {
let cardSourceParams = STPCardParams()
cardSourceParams.number = params["number"] as? String
cardSourceParams.cvc = params["cvc"] as? String
cardSourceParams.expMonth = params["expiryMonth"] as! UInt
cardSourceParams.expYear = params["expiryYear"] as! UInt
cardSourceParams.number = RCTConvert.nsString(params["number"])
cardSourceParams.cvc = RCTConvert.nsString(params["cvc"])
cardSourceParams.expMonth = RCTConvert.nsuInteger(params["expiryMonth"])
cardSourceParams.expYear = RCTConvert.nsuInteger(params["expiryYear"])

return STPPaymentMethodCardParams(cardSourceParams: cardSourceParams)
}
Expand Down Expand Up @@ -434,6 +461,10 @@ class Mappers {
return intent
}

class func mapToReturnURL(urlScheme: String, paymentType: STPPaymentMethodType) -> String {
return urlScheme + "://safepay"
}

class func mapUICustomization(_ params: NSDictionary) -> STPThreeDSUICustomization {
let uiCustomization = STPThreeDSUICustomization()
if let labelSettings = params["label"] as? Dictionary<String, Any?> {
Expand Down Expand Up @@ -535,13 +566,4 @@ class Mappers {
class func convertDateToUnixTimestamp(date: Date) -> UInt64 {
return UInt64(date.timeIntervalSince1970 * 1000.0)
}

@available(iOS 13.0, *)
class func mapToUserInterfaceStyle(_ style: String) -> PaymentSheet.UserInterfaceStyle {
switch style {
case "alwaysDark": return PaymentSheet.UserInterfaceStyle.alwaysDark
case "alwaysLight": return PaymentSheet.UserInterfaceStyle.alwaysLight
default: return PaymentSheet.UserInterfaceStyle.automatic
}
}
}
Loading