-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
713 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//General | ||
"general_checkout" = "Checkout"; | ||
|
||
// Stand-alone URL View Controller | ||
"stand_alone_url_payment_successful" = "Payment completed"; | ||
"stand_alone_url_payment_cancelled" = "Payment cancelled"; | ||
|
||
"stand_alone_url_payment_view_checkout_url" = "View checkout URL"; | ||
"stand_alone_url_payment_base_url" = "Base URL"; | ||
"stand_alone_url_payment_complete_url" = "Complete URL"; | ||
"stand_alone_url_payment_cancel_url" = "Cancel URL"; | ||
"stand_alone_url_payment_checkout_v3" = "Use Checkout V3"; | ||
"stand_alone_url_payment_payment_url" = "Payment URL"; | ||
"stand_alone_url_payment_payment_url_scheme" = "swedbankexample://"; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
extension String { | ||
var localize: String { | ||
return NSLocalizedString(self, comment: "") | ||
} | ||
|
||
func localize(_ arguments: CVarArg...) -> String { | ||
return String(format: self.localize, arguments: arguments) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Example-app/Images.xcassets/payment_failed_icon.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "download-2.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "original" | ||
} | ||
} |
Binary file added
BIN
+8.49 KB
Example-app/Images.xcassets/payment_failed_icon.imageset/download-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
Example-app/Images.xcassets/payment_success_icon.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "download.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "original" | ||
} | ||
} |
Binary file added
BIN
+7.82 KB
Example-app/Images.xcassets/payment_success_icon.imageset/download.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
enum ScanUrl: String { | ||
case checkout | ||
case base | ||
case complete | ||
case cancel | ||
case payment | ||
case unknown | ||
|
||
func toKey() -> StorageHelper.Key? { | ||
switch self { | ||
case .base: | ||
return .baseUrl | ||
case .complete: | ||
return .completeUrl | ||
case .cancel: | ||
return .cancelUrl | ||
case .payment: | ||
return .paymentUrl | ||
default: | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
struct StorageHelper { | ||
|
||
enum Key: String, CaseIterable { | ||
case baseUrl | ||
case completeUrl | ||
case cancelUrl | ||
case useCheckoutV3 | ||
case paymentUrl | ||
|
||
var storageString: String { | ||
return "Storage\(self.rawValue)" | ||
} | ||
} | ||
|
||
static let shared = StorageHelper() | ||
|
||
private let store = UserDefaults.standard | ||
|
||
// MARK: Generic methods | ||
func save<T>(value: T, forKey key: Key) { | ||
store.set(value, forKey: key.storageString) | ||
} | ||
|
||
func value<T>(for key: Key) -> T? { | ||
return store.value(forKey: key.storageString) as? T | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
import SwedbankPaySDK | ||
|
||
enum SwedbankPayConfigurationError: Error { | ||
case notImplemented | ||
} | ||
|
||
class SwedbankPayConfiguration { | ||
let orderInfo: SwedbankPaySDK.ViewPaymentOrderInfo | ||
|
||
init(isV3: Bool = true, webViewBaseURL: URL?, | ||
viewPaymentLink: URL, completeUrl: URL, cancelUrl: URL?, | ||
paymentUrl: URL? = nil, termsOfServiceUrl: URL? = nil) { | ||
self.orderInfo = SwedbankPaySDK.ViewPaymentOrderInfo( | ||
isV3: isV3, | ||
webViewBaseURL: webViewBaseURL, | ||
viewPaymentLink: viewPaymentLink, | ||
completeUrl: completeUrl, | ||
cancelUrl: cancelUrl, | ||
paymentUrl: paymentUrl, | ||
termsOfServiceUrl: termsOfServiceUrl | ||
) | ||
} | ||
} | ||
|
||
extension SwedbankPayConfiguration: SwedbankPaySDKConfiguration { | ||
|
||
// This delegate method is not used but required | ||
func postConsumers(consumer: SwedbankPaySDK.Consumer?, userData: Any?, completion: @escaping (Result<SwedbankPaySDK.ViewConsumerIdentificationInfo, Error>) -> Void) { | ||
completion(.failure(SwedbankPayConfigurationError.notImplemented)) | ||
} | ||
|
||
func postPaymentorders(paymentOrder: SwedbankPaySDK.PaymentOrder?, userData: Any?, consumerProfileRef: String?, options: SwedbankPaySDK.VersionOptions, completion: @escaping (Result<SwedbankPaySDK.ViewPaymentOrderInfo, Error>) -> Void) { | ||
completion(.success(orderInfo)) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Example-app/ViewControllers/PaymentAlternativesViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
import SwiftUI | ||
import UIKit | ||
|
||
class PaymentAlternativesViewController: UIViewController { | ||
|
||
@IBSegueAction func showStandaloneUrlView(_ coder: NSCoder) -> UIViewController? { | ||
return UIHostingController(coder: coder, rootView: StandaloneUrlView()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import Foundation | ||
import SwedbankPaySDK | ||
|
||
extension StandaloneUrlView { | ||
class StandaloneUrlViewModel: ObservableObject, SwedbankPaySDKDelegate { | ||
@Published var viewCheckoutUrl: String = "" | ||
@Published var baseUrl: String | ||
@Published var completeUrl: String | ||
@Published var cancelUrl: String | ||
@Published var useCheckoutV3: Bool | ||
|
||
@Published var paymentUrlAuthorityAndPath: String | ||
@Published var paymentUrlScheme: String | ||
|
||
@Published var displaySwedbankPayController: Bool = false | ||
@Published var displayScannerSheet: Bool = false | ||
|
||
@Published var paymentResultIcon: String? | ||
@Published var paymentResultMessage: String? | ||
|
||
init() { | ||
baseUrl = String(StorageHelper.shared.value(for: .baseUrl) ?? "") | ||
completeUrl = String(StorageHelper.shared.value(for: .completeUrl) ?? "") | ||
cancelUrl = String(StorageHelper.shared.value(for: .cancelUrl) ?? "") | ||
useCheckoutV3 = Bool(StorageHelper.shared.value(for: .useCheckoutV3) ?? true) | ||
paymentUrlAuthorityAndPath = String(StorageHelper.shared.value(for: .paymentUrl) ?? "") | ||
paymentUrlScheme = "stand_alone_url_payment_payment_url_scheme".localize | ||
} | ||
|
||
var isCheckoutEnabled: Bool { | ||
return !viewCheckoutUrl.isEmpty && !completeUrl.isEmpty | ||
} | ||
|
||
func configurePayment() -> SwedbankPayConfiguration? { | ||
guard let viewCheckoutUrl = URL(string: viewCheckoutUrl), let completeUrl = URL(string: completeUrl) else { | ||
return nil | ||
} | ||
|
||
StorageHelper.shared.save(value: baseUrl, forKey: .baseUrl) | ||
StorageHelper.shared.save(value: self.completeUrl, forKey: .completeUrl) | ||
StorageHelper.shared.save(value: cancelUrl, forKey: .cancelUrl) | ||
StorageHelper.shared.save(value: useCheckoutV3, forKey: .useCheckoutV3) | ||
StorageHelper.shared.save(value: paymentUrlAuthorityAndPath, forKey: .paymentUrl) | ||
|
||
let paymentUrl = paymentUrlScheme+paymentUrlAuthorityAndPath | ||
|
||
let configuration = SwedbankPayConfiguration( | ||
isV3: useCheckoutV3, | ||
webViewBaseURL: URL(string: baseUrl), | ||
viewPaymentLink: viewCheckoutUrl, | ||
completeUrl: completeUrl, | ||
cancelUrl: URL(string: cancelUrl), | ||
paymentUrl: URL(string: paymentUrl) | ||
) | ||
|
||
return configuration | ||
} | ||
|
||
func saveUrl(urlType: ScanUrl, url: String) { | ||
if let key = urlType.toKey() { | ||
StorageHelper.shared.save(value: url, forKey: key) | ||
} | ||
} | ||
|
||
private func setPaymentResult(success: Bool, resultText: String) { | ||
paymentResultIcon = success ? "payment_success_icon" : "payment_failed_icon" | ||
|
||
paymentResultMessage = resultText | ||
|
||
displaySwedbankPayController = false | ||
} | ||
|
||
func paymentComplete() { | ||
setPaymentResult(success: true, resultText: "stand_alone_url_payment_successful".localize) | ||
} | ||
|
||
func paymentFailed(error: Error) { | ||
setPaymentResult(success: false, resultText: error.localizedDescription) | ||
} | ||
|
||
func paymentCanceled() { | ||
setPaymentResult(success: false, resultText: "stand_alone_url_payment_cancelled".localize) | ||
} | ||
} | ||
} |
Oops, something went wrong.