Skip to content

Commit

Permalink
Merge pull request #7 from trustly/set_returned_from_app
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsterckx-trustly authored Nov 28, 2023
2 parents 3fa5130 + 81b4072 commit 2ee7e7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [4.0.1] - 2023-11-28
- Add setReturnedFromApp() method to TrustlyWKWebView. Can be called when Merchant-App is opened by urlscheme for a better user experience. This is an optional feature that is not yet rolled out in all Trustly products.

## [4.0.0] - 2023-03-21

### Removed
Expand Down
17 changes: 17 additions & 0 deletions Sources/TrustlyIosSdk/TrustlyWKWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ public class TrustlyWKWebView: UIView, WKNavigationDelegate, WKUIDelegate, Trust

addSubview(webView)
}

static let IS_RETURN_FROM_APP = "isReturnFromApp"

// Only supported from v4.0.1 and up
public func setReturnedFromApp() {
if let checkoutUrl = webView?.url?.absoluteString {

// Append a random number to the hash param to ensure we skip page reloads
let randomString = String(Int.random(in: 0..<Int.max))
let separator = checkoutUrl.contains("#") ? "&" : "#"
let checkoutUrlWithHash = "\(checkoutUrl)\(separator)\(TrustlyWKWebView.IS_RETURN_FROM_APP)=\(randomString)"

if let url = URL(string: checkoutUrlWithHash) {
webView?.load(URLRequest(url: url))
}
}
}

public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
Expand Down

0 comments on commit 2ee7e7d

Please sign in to comment.