Skip to content

Commit 26f3d34

Browse files
committed
Merge branch 'feature/SP-58-Stöd-för-nytt-betalkort' into 'feature/native-payments'
Resolve SP-58 "Feature/ stöd för nytt betalkort" See merge request swedbank-pay/swedbank-pay-example-app-ios!8
2 parents 147c5fc + 5b4ba16 commit 26f3d34

File tree

5 files changed

+71
-18
lines changed

5 files changed

+71
-18
lines changed

Example-app/Base.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
"stand_alone_url_payment_swish_device" = "Swish using this device";
2222
"stand_alone_url_payment_swish_prefill %@" = "Swish: %@";
2323
"stand_alone_url_payment_credit_card_prefill %@" = "Credit Card: %@";
24+
"stand_alone_url_payment_new_credit_card" = "New Credit Card";
2425
"stand_alone_url_payment_abort" = "Abort";
2526
"stand_alone_client_app_launch_failed" = "Failed to launch external app";
2627
"stand_alone_url_payment_session_end_state_reached" = "Something went wrong with the payment";
2728
"stand_alone_internal_inconsistency_error" = "Something was called it the wrong order";
2829
"stand_alone_generic_error_title" = "Something went wrong";
2930
"stand_alone_url_seamless_title" = "Seamless View";
3031
"stand_alone_url_payment_web" = "Get payment menu";
32+
"stand_alone_url_payment_apple_pay" = "ApplePay";

Example-app/Example-app.entitlements

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
<string>applinks:pp-dot-payex-merchant-samples.ey.r.appspot.com</string>
1010
<string>applinks:payex-merchant-samples-prod.appspot.com</string>
1111
</array>
12+
<key>com.apple.developer.in-app-payments</key>
13+
<array>
14+
<string>merchant.com.swedbankpay.exampleapp</string>
15+
</array>
1216
</dict>
1317
</plist>

Example-app/ViewModels/StandaloneUrlViewModel.swift

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,25 @@ extension StandaloneUrlView {
119119

120120
isLoadingNativePayment = false
121121
}
122-
122+
123+
private func showAlertOnPaymentSession3DSecureViewController(error: Error, retry: (()->Void)?) {
124+
let alert = UIAlertController(title: nil,
125+
message: "\((error as NSError).code): \(error.localizedDescription)\n\n\((error as NSError).domain)",
126+
preferredStyle: .alert)
127+
alert.addAction(UIAlertAction(title: "general_ok".localize, style: .cancel, handler: { _ in
128+
self.show3DSecureViewController = false
129+
self.paymentSession3DSecureViewController = nil
130+
}))
131+
132+
if let retry = retry {
133+
alert.addAction(UIAlertAction(title: "general_retry".localize, style: .default, handler: { _ in
134+
retry()
135+
}))
136+
}
137+
138+
self.paymentSession3DSecureViewController?.present(alert, animated: true, completion: nil)
139+
}
140+
123141
func paymentComplete() {
124142
setPaymentResult(success: true, resultText: "stand_alone_url_payment_successful".localize)
125143
}
@@ -158,6 +176,10 @@ extension StandaloneUrlView {
158176
errorMessage: "stand_alone_client_app_launch_failed".localize)
159177
case .paymentSessionAPIRequestFailed(let error, let retry):
160178
showAlert(error: error, retry: retry)
179+
case .paymentControllerPaymentFailed(error: let error, retry: let retry):
180+
showAlert(error: error, retry: retry)
181+
case .paymentSession3DSecureViewControllerLoadFailed(error: let error, retry: let retry):
182+
showAlertOnPaymentSession3DSecureViewController(error: error, retry: retry)
161183
case .paymentSessionEndStateReached:
162184
setPaymentResult(success: false, resultText: "stand_alone_url_payment_session_end_state_reached".localize)
163185
case .internalInconsistencyError:
@@ -186,20 +208,11 @@ extension StandaloneUrlView {
186208
self.paymentSession3DSecureViewController = nil
187209
}
188210

189-
func paymentSession3DSecureViewControllerLoadFailed(error: Error, retry: @escaping ()->Void) {
190-
let alert = UIAlertController(title: nil,
191-
message: "\((error as NSError).code): \(error.localizedDescription)\n\n\((error as NSError).domain)",
192-
preferredStyle: .alert)
193-
alert.addAction(UIAlertAction(title: "general_ok".localize, style: .cancel, handler: { _ in
194-
self.show3DSecureViewController = false
195-
self.paymentSession3DSecureViewController = nil
196-
}))
197-
198-
alert.addAction(UIAlertAction(title: "general_retry".localize, style: .default, handler: { _ in
199-
retry()
200-
}))
201-
202-
self.paymentSession3DSecureViewController?.present(alert, animated: true, completion: nil)
211+
func showSwedbankPaySDKController(viewController: SwedbankPaySDKController) {
212+
paymentSessionSwedbankPayController = viewController
213+
paymentSessionSwedbankPayController?.delegate = self
214+
displayPaymentSessionSwedbankPayController = true
215+
isLoadingNativePayment = false
203216
}
204217
}
205218
}

Example-app/Views/StandaloneUrlView.swift

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,40 @@ struct StandaloneUrlView: View {
404404
.padding(.top, 10)
405405
}
406406
}
407+
408+
Button {
409+
isFocused = false
410+
411+
viewModel.isLoadingNativePayment = true
412+
viewModel.nativePayment?.makeNativePaymentAttempt(instrument: .newCreditCard(enabledPaymentDetailsConsentCheckbox: true))
413+
} label: {
414+
Text("stand_alone_url_payment_new_credit_card")
415+
.smallFont()
416+
.frame(maxWidth: .infinity)
417+
.frame(height: 48)
418+
.accessibilityIdentifier("newCreditCardButton")
419+
}
420+
.foregroundColor(.white)
421+
.background(.black)
422+
.cornerRadius(30)
423+
.padding(.top, 10)
424+
case .applePay:
425+
Button {
426+
isFocused = false
427+
428+
viewModel.isLoadingNativePayment = true
429+
viewModel.nativePayment?.makeNativePaymentAttempt(instrument: .applePay(merchantIdentifier: "merchant.com.swedbankpay.exampleapp"))
430+
} label: {
431+
Text("stand_alone_url_payment_apple_pay")
432+
.smallFont()
433+
.frame(maxWidth: .infinity)
434+
.frame(height: 48)
435+
.accessibilityIdentifier("applePayButton")
436+
}
437+
.foregroundColor(.white)
438+
.background(.black)
439+
.cornerRadius(30)
440+
.padding(.top, 10)
407441
case .webBased(identifier: let identifier):
408442
EmptyView()
409443
}
@@ -412,9 +446,7 @@ struct StandaloneUrlView: View {
412446
Button {
413447
isFocused = false
414448

415-
viewModel.paymentSessionSwedbankPayController = viewModel.nativePayment?.createSwedbankPaySDKController()
416-
viewModel.paymentSessionSwedbankPayController?.delegate = viewModel
417-
viewModel.displayPaymentSessionSwedbankPayController = true
449+
viewModel.nativePayment?.createSwedbankPaySDKController()
418450
} label: {
419451
Text("stand_alone_url_payment_web")
420452
.smallFont()

Example-app/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
"stand_alone_url_payment_swish_device" = "Swish using this device";
2222
"stand_alone_url_payment_swish_prefill %@" = "Swish: %@";
2323
"stand_alone_url_payment_credit_card_prefill %@" = "Credit Card: %@";
24+
"stand_alone_url_payment_new_credit_card" = "New Credit Card";
2425
"stand_alone_url_payment_abort" = "Abort";
2526
"stand_alone_client_app_launch_failed" = "Failed to launch external app";
2627
"stand_alone_url_payment_session_end_state_reached" = "Something went wrong with the payment";
2728
"stand_alone_internal_inconsistency_error" = "Something was called it the wrong order";
2829
"stand_alone_generic_error_title" = "Something went wrong";
2930
"stand_alone_url_seamless_title" = "Seamless View";
3031
"stand_alone_url_payment_web" = "Get payment menu";
32+
"stand_alone_url_payment_apple_pay" = "ApplePay";

0 commit comments

Comments
 (0)