Skip to content

Commit c913710

Browse files
committed
Add new validate by product name endpoint.
1 parent 0411e8f commit c913710

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Source/Payment/API/INPPaymentService.swift

+19-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ class INPPaymentService {
3636
route: PaymentAPIRouter.validatePayment(parameters: params),
3737
completion: completion)
3838
}
39+
40+
static func validateByProductName(productName: String,
41+
receipt: String,
42+
completion: @escaping RequestCompletion<Empty>) {
43+
let params: [String: Any] = [
44+
PaymentParameters.receipt: receipt,
45+
PaymentParameters.productName: productName
46+
]
47+
NetworkDataSource.performRequest(session: InPlayerSessionAPIManager.default.session,
48+
route: PaymentAPIRouter.validatePaymentByProductName(parameters: params),
49+
completion: completion)
50+
51+
}
3952

4053
static func getPurchaseHistory(status: PurchaseHistory,
4154
page: Int,
@@ -64,11 +77,12 @@ class INPPaymentService {
6477
private enum PaymentAPIRouter: INPAPIConfiguration {
6578

6679
case validatePayment(parameters: [String: Any])
80+
case validatePaymentByProductName(parameters: [String: Any])
6781
case getPurchaseHistory(parameters: [String: Any])
6882

6983
var method: HTTPMethod {
7084
switch self {
71-
case .validatePayment:
85+
case .validatePayment, .validatePaymentByProductName:
7286
return .post
7387
case .getPurchaseHistory:
7488
return .get
@@ -77,7 +91,7 @@ private enum PaymentAPIRouter: INPAPIConfiguration {
7791

7892
var path: String {
7993
switch self {
80-
case .validatePayment:
94+
case .validatePayment, .validatePaymentByProductName:
8195
return NetworkConstants.Endpoints.Payment.validate
8296
case .getPurchaseHistory:
8397
return NetworkConstants.Endpoints.Payment.purchaseHistory
@@ -88,6 +102,8 @@ private enum PaymentAPIRouter: INPAPIConfiguration {
88102
switch self {
89103
case .validatePayment(let parameters):
90104
return parameters
105+
case .validatePaymentByProductName(let parameters):
106+
return parameters
91107
case .getPurchaseHistory(let parameters):
92108
return parameters
93109
}
@@ -118,4 +134,5 @@ private struct PaymentParameters {
118134
static let limit = "size"
119135
static let type = "type"
120136
static let customerId = "customerID"
137+
static let productName = "product_name"
121138
}

Source/Payment/Payment.swift

+25
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ public extension InPlayer {
3131
}
3232
})
3333
}
34+
35+
/**
36+
Contact InPlayer server and validate if purchase was successfull.
37+
- Parameters:
38+
- productName: Purchased product name
39+
- receipt: Base64EncodedString of the recept data stored on device after successfull in-app purchase.
40+
- success: A closure to be executed once the request has finished successfully.
41+
- failure: A closure to be executed once the request has finished with error.
42+
- error: Containing information about the error that occurred.
43+
*/
44+
45+
public static func validateByProductName(productName: String,
46+
receipt: String,
47+
success: @escaping () -> Void,
48+
failure: @escaping (_ error: InPlayerError) -> Void) {
49+
INPPaymentService.validateByProductName(productName: productName,
50+
receipt: receipt,
51+
completion: { (_, error) in
52+
if let error = error {
53+
failure(error)
54+
} else {
55+
success()
56+
}
57+
})
58+
}
3459

3560
/**
3661
Gets the purchase history

0 commit comments

Comments
 (0)