-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for checkout events - Add a new message handler name that will work as the "new" native bridge. - Add delegate for receiving events from the Checkout in the web view. * Mark initializer as public * Revert "Mark initializer as public" This reverts commit 1f3f930. * Set initializer as public * Refactor code for handling url-schemes when not opt:ed in * Add availability check for open URL function * Remove invalid character * Set TrustlyCheckoutDelegate as public * Set all internal structs and protocols to public * Remove the canOpenURL check in case the app did not whitelist the URL * Specify required platform and refactor the parsing of the checkout event. * Update README to reflect SDK changes
- Loading branch information
1 parent
cd08e34
commit d3d66d9
Showing
5 changed files
with
189 additions
and
29 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,51 @@ | ||
# TrustlyIosSdk | ||
# Trustly iOS SDK | ||
|
||
A description of this package. | ||
The Trustly iOS SDK provides an easy way to implement the Trustly Checkout in your iOS app. The SDK handles communication with the Web View and exposes Checkout events that allows you to customize your Checkout flow. | ||
|
||
## Integration | ||
Add the SDK as a Swift Package. [More detailed intructions can be found here.](https://www.trustly.net/site/developer-portal?part=iosandroid) | ||
1. Navigate to File -> Swift Packages -> Add Package Dependency. | ||
2. Paste the Trustly SDK URL: https://github.com/trustly/TrustlyIosSdk | ||
3. Select Up to Next Major version and make sure you have the latest version | ||
4. Press finish. | ||
5. You should now see the swift package in the project navigator. | ||
|
||
## Usage | ||
Pass your Checkout URL when initialising a new TrustlyWKWebView instance. The Checkout will be rendered within the TrustlyWKWebView. | ||
|
||
Example usage: | ||
```swift | ||
let trustlyWebView = TrustlyWKWebView(checkoutUrl: trustlyCheckoutURLString, frame: self.view.frame) | ||
self.view = trustlyWebView | ||
``` | ||
### Receiving Checkout Events | ||
If you want more control of your Checkout flow you can choose to opt-in to receiving and handling Checkout events. | ||
|
||
You can opt-in by setting the delegate of the TrustlyWKWebView | ||
```swift | ||
trustlyWebView?.delegate = self | ||
``` | ||
and conforming to the TrustlyCheckoutDelegate protocol | ||
```swift | ||
class ViewController: UIViewController, TrustlyCheckoutDelegate { | ||
|
||
func onTrustlyCheckoutRequstToOpenURLScheme(urlScheme: String) { | ||
//Requests to open URLs or third party applications. | ||
} | ||
|
||
func onTrustlyCheckoutSuccessfull(urlString: String?) { | ||
|
||
} | ||
|
||
func onTrustlyCheckoutError() { | ||
|
||
} | ||
|
||
func onTrustlyCheckoutAbort(urlString: String?) { | ||
|
||
} | ||
} | ||
``` | ||
|
||
## Notes about URLScheme | ||
Please note that when rendering the Trustly Checkout from a native app you are required to pass your application’s [URLScheme](https://developer.apple.com/documentation/xcode/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app) as an attribute to the order initiation request. By doing so, Trustly can redirect users back to your app after using external identification apps such as Mobile BankID. You can pass your URLScheme by including it in the "URLScheme" attribute when making an API call to Trustly. [You can read more about it here.](https://www.trustly.net/site/developer-portal?part=iosandroid) |
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,44 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2020 Trustly Group AB | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
import Foundation | ||
|
||
public enum TrustlyCheckoutEvent: String { | ||
case openURLScheme = "onTrustlyCheckoutRedirect" | ||
case success = "onTrustlyCheckoutSuccess" | ||
case error = "onTrustlyCheckoutError" | ||
case abort = "onTrustlyCheckoutAbort" | ||
} | ||
|
||
|
||
public protocol TrustlyCheckoutDelegate: class { | ||
/// Called when Checkout receives a request to open a URL Scheme. | ||
func onTrustlyCheckoutRequstToOpenURLScheme(urlScheme: String) | ||
/// Called when Checkout transaction is complete. | ||
func onTrustlyCheckoutSuccessfull(urlString: String?) | ||
/// Called when the users abort the Checkout. | ||
func onTrustlyCheckoutAbort(urlString: String?) | ||
/// Called when an error occurs in the Checkout. | ||
func onTrustlyCheckoutError() | ||
} |
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