@@ -11,7 +11,8 @@ class CardFormView: UIView, STPCardFormViewDelegate {
11
11
@objc var onFormComplete : RCTDirectEventBlock ?
12
12
@objc var autofocus : Bool = false
13
13
@objc var isUserInteractionEnabledValue : Bool = true
14
-
14
+ @objc var defaultValues : NSDictionary ?
15
+
15
16
override func didSetProps( _ changedProps: [ String ] ! ) {
16
17
if let cardForm = self . cardForm {
17
18
cardForm. removeFromSuperview ( )
@@ -29,14 +30,15 @@ class CardFormView: UIView, STPCardFormViewDelegate {
29
30
self . cardForm = _cardForm
30
31
self . addSubview ( _cardForm)
31
32
setStyles ( )
33
+ setDefaultValues ( )
32
34
}
33
35
34
36
@objc var cardStyle : NSDictionary = NSDictionary ( ) {
35
37
didSet {
36
38
setStyles ( )
37
39
}
38
40
}
39
-
41
+
40
42
func cardFormView( _ form: STPCardFormView , didChangeToStateComplete complete: Bool ) {
41
43
if onFormComplete != nil {
42
44
let brand = STPCardValidator . brand ( forNumber: cardForm? . cardParams? . card? . number ?? " " )
@@ -100,6 +102,20 @@ class CardFormView: UIView, STPCardFormViewDelegate {
100
102
// }
101
103
}
102
104
105
+ func setDefaultValues( ) {
106
+ guard let cardForm = cardForm else { return }
107
+
108
+ let card = Mappers . mapToCardParams ( defaultValues)
109
+
110
+ let address = STPPaymentMethodAddress ( )
111
+ address. postalCode = defaultValues ? [ " postalCode " ] as? String
112
+
113
+ let billingDetails = STPPaymentMethodBillingDetails ( )
114
+ billingDetails. address = address
115
+
116
+ cardForm. cardParams = STPPaymentMethodParams . init ( card: card, billingDetails: billingDetails, metadata: nil )
117
+ }
118
+
103
119
override init ( frame: CGRect ) {
104
120
super. init ( frame: frame)
105
121
}
0 commit comments