Skip to content

Commit

Permalink
added new properties for subscriptionStatus & minor logic fixes for A…
Browse files Browse the repository at this point in the history
…pplePay
  • Loading branch information
YehorKyrylov committed Oct 14, 2022
1 parent 3ef08da commit 38b2fcb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Sources/PandaSDK/ConfiguredPanda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,21 @@ final public class Panda: PandaProtocol, ObserverSupport {

switch result {
case let .success(result):
self.viewControllers.forEach({ $0.value?.tryAutoDismiss()})
if let transactionStatus = result.transactionStatus,
transactionStatus == .fail {
let error = ApplePayVerificationError.init(message: "Payment transaction failed")
self.send(event: .purchaseError(error: error, source: self.entryPoint))
self.onError?(error)
return
}

self.viewControllers.forEach { $0.value?.tryAutoDismiss() }
self.send(event: .onApplePaySuccessfulPurchase(productID: productID))
case let .failure(error):
self.viewControllers.forEach({ $0.value?.tryAutoDismiss()})

self.viewControllers.forEach { $0.value?.tryAutoDismiss() }
self.onError?(error)
self.send(event: .purchaseError(error: error, source: self.entryPoint))
}

}
}
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/PandaSDK/Networking/NetworkClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,23 @@ public struct ReceiptVerificationResult: Codable {

public struct ApplePayResult: Codable {
let transactionID: String
let transactionStatus: TransactionSolidStatus?

enum CodingKeys: String, CodingKey {
case transactionID = "TransactionID"
case transactionStatus = "transaction_status"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.transactionID = try container.decode(String.self, forKey: .transactionID)
self.transactionStatus = try container.decode(TransactionSolidStatus.self, forKey: .transactionStatus)
}
}

public enum TransactionSolidStatus: String, Codable {
case created
case fail
}

public enum SubscriptionAPIStatus: String, Codable {
Expand Down
10 changes: 10 additions & 0 deletions Sources/PandaSDK/SubsriptionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public struct SubscriptionInfo: Codable {
public let price: Double?
public let state: SubscriptionAPIStatus
public let paymentType: PaymentType
public let paymentStatus: PaymentStatus

public var stateDescription: String {
state.rawValue
Expand All @@ -66,6 +67,7 @@ public struct SubscriptionInfo: Codable {
case price
case state
case paymentType = "payment_type"
case paymentStatus = "payment_status"
}

public init(from decoder: Decoder) throws {
Expand All @@ -76,6 +78,7 @@ public struct SubscriptionInfo: Codable {
self.price = try container.decodeIfPresent(Double.self, forKey: .price)
self.state = try container.decode(SubscriptionAPIStatus.self, forKey: .state)
self.paymentType = try container.decodeIfPresent(PaymentType.self, forKey: .paymentType) ?? .unknown
self.paymentStatus = try container.decodeIfPresent(PaymentStatus.self, forKey: .paymentStatus) ?? .unknown
}
}

Expand All @@ -85,3 +88,10 @@ public enum PaymentType: String, Codable {
case onetime
case unknown
}

public enum PaymentStatus: String, Codable {
case fail
case processing
case success
case unknown
}

0 comments on commit 38b2fcb

Please sign in to comment.