Skip to content

Commit a766971

Browse files
Steffen Lund AndersenSteffen Lund Andersen
Steffen Lund Andersen
authored and
Steffen Lund Andersen
committed
Updated the documentation with the Vipps integration
1 parent 9e06ea0 commit a766971

File tree

4 files changed

+60
-24
lines changed

4 files changed

+60
-24
lines changed

README.md

+57-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ The QuickPay SDK wraps the [QuickPay API](https://learn.quickpay.net/tech-talk/a
55

66
## Installation
77

8-
You can install the QuickPay SDK either by downloading it directly from our GitHub repo or by adding it as a Swift Package. If you want to use Swift Packages simply point to the git repo and check out the master branch.
8+
You can install the QuickPay SDK either by downloading it directly from our GitHub repo or by adding it as a Swift Package.
9+
10+
If you want to use Swift Packages simply point to the git repo https://github.com/QuickPay/ios-sdk and check out the master branch.
911

1012

1113
### API key and permissions
@@ -114,7 +116,7 @@ QuickPay SDK supports MobilePay natively so you can create a great app experienc
114116
It is recommended that you check if the users have the MobilePay App installed and only show the payment option if it is available. The QuickPay class can help you with this.
115117

116118
```swift
117-
QuickPay.isMobilePayAvailable()
119+
QuickPay.isMobilePayAvailableOnDevice()
118120
```
119121

120122

@@ -131,7 +133,7 @@ You can read more about the URL schemes on [https://developers.apple.com](https:
131133

132134
First, you need to create a payment just like with the payment window, but after that, the flow is different since we do not have the payment window to handle a lot of tasks for us.
133135

134-
When you have created your payment you need to start a MobilePay payment session. Create a `MobilePayParameters` object and specify the custom URL scheme that you created earlier. You can also specify the language of MobilePay and add a URL to a logo you want it to be displayed. Add this information to a `QPCreatePaymenSessionParameters` along with the amount of money you want to authorize. Finally, put everything together in a `QPCreatePaymenSessionRequest` and send the request.
136+
When you have created your payment you need to start a MobilePay payment session. Create a `MobilePayParameters` object and specify the custom URL scheme that you created earlier. You can also specify the language of MobilePay and add a URL to a logo you want it to be displayed. Add this information to a `QPCreatePaymentSessionParameters` along with the amount of money you want to authorize. Finally, put everything together in a `QPCreatePaymentSessionRequest` and send the request.
135137

136138
```swift
137139
let mobilePayParameters = MobilePayParameters(returnUrl: "quickpayexampleshop://", language: "dk", shopLogoUrl: "https://SomeUrl/SomeImage.png")
@@ -159,6 +161,58 @@ QuickPay.authorizeWithMobilePay(payment: payment, completion: { (payment) in {
159161
In the completion handler, we need to check the status of the payment. This is done in the same way as with the payment window. Create a `QPGetPaymentRequest` with the payment id and check if the updated payment is accepted.
160162

161163

164+
### Vipps
165+
166+
QuickPay SDK supports Vipps natively so you can create a great app experience. To query the Vipps App you need to make some changes to your project settings and implement the payment as shown later in this guide.
167+
168+
It is recommended that you check if the users have the Vipps App installed and only show the payment option if it is available. The QuickPay class can help you with this.
169+
170+
```swift
171+
QuickPay.isVippsAvailableOnDevice()
172+
```
173+
174+
175+
#### URL Schemes for Vipps
176+
177+
To query the MobilePay App you need to whitelist the `vipps` URL scheme to the `LSApplicationQueriesSchemes` array in your `Info.plist`. With this done your application can now query the Vipps App with the needed information for Vipps to handle the authorization of a payment.
178+
179+
You also need to specify a custom URL scheme for the Vipps App to query back to when it is done doing its job. This is done in the `URL types` array in your `Info.plist`.
180+
181+
You can read more about the URL schemes on [https://developers.apple.com](https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app)
182+
183+
184+
#### Payment flow for Vipps
185+
186+
First, you need to create a payment just like with the payment window, but after that, the flow is different since we do not have the payment window to handle a lot of tasks for us.
187+
188+
When you have created your payment you need to start a Vipps payment session. Create a `VippsParameters` object and specify the custom URL scheme that you created earlier. Add this information to a `QPCreatePaymentSessionParameters` along with the amount of money you want to authorize and remember to set the currency to "NOK". Finally, put everything together in a `QPCreatePaymentSessionRequest` and send the request.
189+
190+
```swift
191+
let vippsParams = VippsParameters(returnUrl: "quickpayexampleshop://")
192+
let sessionParameters = QPCreatePaymentSessionParameters(amount: Int(self.totalBasketValue() * 100), vipps: vippsParams)
193+
194+
let request = QPCreatePaymenSessionRequest(id: payment.id, parameters: sessionParameters)
195+
196+
request.sendRequest(success: { (payment) in
197+
// Handle the payment
198+
}, failure: { (data, response, error) in
199+
// Handle the failure
200+
})
201+
```
202+
203+
With the payment containing a session id, we can now query Vipps to authorize the payment.
204+
205+
```swift
206+
QuickPay.authorizeWithVipps(payment: payment, completion: { (payment) in {
207+
// Handle the payment
208+
}, failure: {
209+
// Handle the failure
210+
}
211+
```
212+
213+
In the completion handler, we need to check the status of the payment. This is done in the same way as with the payment window. Create a `QPGetPaymentRequest` with the payment id and check if the updated payment is accepted.
214+
215+
162216
### Apple Pay
163217

164218
In order to take advantage of Apple Pay, first, you need to do some initial setup to your project and generate a signing certificate. When that is done you also need to implement a bit of code to handle the native Apple Pay flow.

Sources/QuickPaySDK/Core/QuickPay.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class QuickPay: NSObject {
6262
let dispatchGroup = DispatchGroup();
6363

6464
dispatchGroup.enter()
65-
isMobilePayOnlineEnabled { (enabled) in
65+
isMobilePayEnabled { (enabled) in
6666
isMobilePayEnabled = enabled
6767
dispatchGroup.leave()
6868
}
@@ -309,11 +309,8 @@ extension QuickPay {
309309
// MobilePay
310310
extension QuickPay {
311311

312-
static func isMobilePayOnlineEnabled(completion: @escaping (_ enabled: Bool)->Void) {
312+
static func isMobilePayEnabled(completion: @escaping (_ enabled: Bool)->Void) {
313313
QPGetAcquireSettingsMobilePayRequest().sendRequest(success: { (settings) in
314-
print("LOOK HERE: isMobilePayOnlineEnabled: \(settings.active)")
315-
print("LOOK HERE: isMobilePayOnlineEnabled: \(settings)")
316-
317314
completion(settings.active)
318315
}) { (data, response, error) in
319316
completion(false)

Sources/QuickPaySDK/Networking/QuickPay API/QPRequest.swift

-13
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,6 @@ public class QPRequest {
9393
A model representation of the error json returned by QuickPay in case of an error
9494
*/
9595
public struct QPRequestError : Codable {
96-
/*
97-
NOTE: This is not used at the momement, but in the future it will be a part of the request/response cycle
98-
99-
Code snippet:
100-
if (QuickPayHttpStatusCodes(rawValue: httpResponse.statusCode) == QuickPayHttpStatusCodes.badRequest) {
101-
// On bad requests, QuickPay has their own error format, we parse it and return to ease the use
102-
if let data = data, let qpRequstError = try? JSONDecoder().decode(QPRequestError.self, from: data) {
103-
self.errorDelegate?.onError(request: self, qpError: qpRequstError)
104-
return
105-
}
106-
}
107-
*/
108-
10996
public let message: String
11097
public let errors: Dictionary<String, Array<String>>
11198
public let error_code: String

Sources/QuickPaySDK/Networking/QuickPay API/QuickPay Link/Payments/QPCreatePaymentRequest.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public class QPCreatePaymentParameters: Codable {
6464
self.currency = currency
6565
self.order_id = order_id
6666

67-
self.shopSystem = QPShopSystem()
68-
self.shopSystem?.name = "iOS-SDK"
69-
self.shopSystem?.version = "2.0.0"
67+
self.shopSystem = QPShopSystem(name: "iOS-SDK", version: "2.0.0")
7068
}
7169

7270
}

0 commit comments

Comments
 (0)