Skip to content

Commit 1cfb33f

Browse files
add external payment notifications
1 parent 7ca1603 commit 1cfb33f

4 files changed

+108
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// InPlayerExternalPaymentFailed.swift
3+
// InPlayerSDK
4+
//
5+
// Created by Kire Jankulovski on 2/22/22.
6+
//
7+
8+
import Foundation
9+
10+
/// External payment failed model
11+
public struct InPlayerExternalPaymentFailed: Codable {
12+
public var message: String?
13+
public var explain: String?
14+
public var code: String?
15+
16+
private enum CodingKeys: String, CodingKey {
17+
case message
18+
case explain
19+
case code
20+
}
21+
22+
/// Decoder method
23+
public init(from decoder: Decoder) throws {
24+
let values = try decoder.container(keyedBy: CodingKeys.self)
25+
message = try values.decodeIfPresent(String.self, forKey: .message)
26+
explain = try values.decodeIfPresent(String.self, forKey: .explain)
27+
code = try values.decodeIfPresent(String.self, forKey: .code)
28+
}
29+
}

Source/Notification/Models/InPlayerNotification.swift

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import Foundation
55
```
66
case accessGranted(resource: INPItemAccessModel)
77
case accessRevoked(resource: INPItemRevokedModel)
8+
case externalPaymentSuccess(resource: INPPaymentSuccessModel)
9+
case externalPaymentFailed(resource: INPExternalPaymentFailedModel)
810
case accountLogout
911
case accountErased
1012
case accountDeactivated
11-
case unknown
13+
case defaultNotification(type: String)
1214
```
1315
*/
1416
public enum NotificationType {
1517
case accessGranted(resource: InPlayerItemAccess)
1618
case accessRevoked(resource: InPlayerItemRevoked)
19+
case externalPaymentSuccess(resource: InPlayerPaymentSuccess)
20+
case externalPaymentFailed(resource: InPlayerExternalPaymentFailed)
1721
case accountLogout
1822
case accountErased
1923
case accountDeactivated
@@ -34,6 +38,8 @@ public struct InPlayerNotification: Codable {
3438
private struct NotificationTypeStrings {
3539
static let accessGranted = "access.granted"
3640
static let accessRevoked = "access.revoked"
41+
static let externalPaymentSuccess = "external.payment.success"
42+
static let externalPaymentFailed = "external.payment.failed"
3743
static let accountLogout = "account.logout"
3844
static let accountErased = "account.erased"
3945
static let accountDeactivated = "account.deactivated"
@@ -53,6 +59,12 @@ public struct InPlayerNotification: Codable {
5359
case NotificationTypeStrings.accessRevoked:
5460
let resource = try values.decode(InPlayerItemRevoked.self, forKey: .resource)
5561
type = .accessRevoked(resource: resource)
62+
case NotificationTypeStrings.externalPaymentSuccess:
63+
let resource = try values.decode(InPlayerPaymentSuccess.self, forKey: .resource)
64+
type = .externalPaymentSuccess(resource: resource)
65+
case NotificationTypeStrings.externalPaymentFailed:
66+
let resource = try values.decode(InPlayerExternalPaymentFailed.self, forKey: .resource)
67+
type = .externalPaymentFailed(resource: resource)
5668
case NotificationTypeStrings.accountLogout:
5769
type = .accountLogout
5870
case NotificationTypeStrings.accountErased:
@@ -75,6 +87,12 @@ public struct InPlayerNotification: Codable {
7587
case .accessRevoked(let resource):
7688
try values.encode(resource, forKey: .resource)
7789
try values.encode(NotificationTypeStrings.accessRevoked, forKey: .typeString)
90+
case .externalPaymentSuccess(let resource):
91+
try values.encode(resource, forKey: .resource)
92+
try values.encode(NotificationTypeStrings.externalPaymentSuccess, forKey: .typeString)
93+
case .externalPaymentFailed(let resource):
94+
try values.encode(resource, forKey: .resource)
95+
try values.encode(NotificationTypeStrings.externalPaymentFailed, forKey: .typeString)
7896
case .accountLogout:
7997
try values.encode(NotificationTypeStrings.accountLogout, forKey: .typeString)
8098
case .accountErased:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// InPlayerPaymentSuccess.swift
3+
// InPlayerSDK
4+
//
5+
// Created by Kire Jankulovski on 2/22/22.
6+
//
7+
8+
import Foundation
9+
10+
/// Payment success model
11+
public struct InPlayerPaymentSuccess: Codable {
12+
public var itemId: Int?
13+
public var previewTitle: String?
14+
public var accessFeeId: Int?
15+
public var transaction: String?
16+
public var decsription: String?
17+
public var email: String?
18+
public var customerId: Int?
19+
public var formattedAmount: String?
20+
public var amount: Double?
21+
public var currency: String?
22+
public var status: String?
23+
public var timestamp: Double?
24+
public var code: Int?
25+
26+
private enum CodingKeys: String, CodingKey {
27+
case itemId = "item_id"
28+
case previewTitle
29+
case accessFeeId = "access_fee_id"
30+
case transaction
31+
case decsription
32+
case email
33+
case customerId = "customer_id"
34+
case formattedAmount = "formatted_amount"
35+
case amount
36+
case currency = "currency_iso"
37+
case status
38+
case timestamp
39+
case code
40+
}
41+
42+
/// Decoder method
43+
public init(from decoder: Decoder) throws {
44+
let values = try decoder.container(keyedBy: CodingKeys.self)
45+
itemId = try values.decodeIfPresent(Int.self, forKey: .itemId)
46+
previewTitle = try values.decodeIfPresent(String.self, forKey: .previewTitle)
47+
accessFeeId = try values.decodeIfPresent(Int.self, forKey: .accessFeeId)
48+
transaction = try values.decodeIfPresent(String.self, forKey: .transaction)
49+
decsription = try values.decodeIfPresent(String.self, forKey: .decsription)
50+
email = try values.decodeIfPresent(String.self, forKey: .email)
51+
customerId = try values.decodeIfPresent(Int.self, forKey: .customerId)
52+
formattedAmount = try values.decodeIfPresent(String.self, forKey: .formattedAmount)
53+
amount = try values.decodeIfPresent(Double.self, forKey: .amount)
54+
currency = try values.decodeIfPresent(String.self, forKey: .currency)
55+
status = try values.decodeIfPresent(String.self, forKey: .status)
56+
timestamp = try values.decodeIfPresent(Double.self, forKey: .timestamp)
57+
code = try values.decodeIfPresent(Int.self, forKey: .code)
58+
}
59+
}

Source/Notification/Notification.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public extension InPlayer {
1414
- onStatusChanged: A closure to be executed everytime when connection status change occurs.
1515
- status: `InPlayerNotificationStatus` enum that shows current connection status
1616
- onMessageReceived: A closure to be executed everytime new notification is sent from the server.
17-
- notification: `InPlayerNotification` struct optionally containing associated values depending on the type enum.
17+
- notification: `InPlayerNotification` struct optionally containing associated values depending on the type enum. Default Notification with type if Notification is undefined
1818
- onError: A closure to be executed when some error occurred.
1919
- error: `InPlayerError` containing info about the error that occurred.
2020
*/

0 commit comments

Comments
 (0)