Skip to content

Commit

Permalink
Code Updated for status also as Andriod
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-gadagoju committed Aug 29, 2023
1 parent 8c4494e commit d41234e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions Chargebee/Classes/Purchase/CBPurchaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CBPurchase: NSObject {
public static let shared = CBPurchase()
private var productIDs: [String] = []
public var receiveProductsHandler: ((_ result: Result<[CBProduct], CBPurchaseError>) -> Void)?
private var buyProductHandler: ((Result<CBValidateReceipt, Error>) -> Void)?
private var buyProductHandler: ((Result<PurchaseSubscription, Error>) -> Void)?
private var buyNonSubscriptionProductHandler: ((Result<NonSubscription, Error>) -> Void)?

private var authenticationManager = CBAuthenticationManager()
Expand Down Expand Up @@ -119,14 +119,14 @@ public extension CBPurchase {
}

@available(*, deprecated, message: "This will be removed in upcoming versions, Please use this API func purchaseProduct(product: CBProduct, customer : CBCustomer? = nil, completion)")
func purchaseProduct(product: CBProduct, customerId: String? = "", completion handler: @escaping ((_ result: Result<CBValidateReceipt, Error>) -> Void)) {
func purchaseProduct(product: CBProduct, customerId: String? = "", completion handler: @escaping ((_ result: Result<PurchaseSubscription, Error>) -> Void)) {
buyProductHandler = handler
activeProduct = product
self.customer = CBCustomer(customerID: customerId ?? "")
self.purchaseProductHandler(product: product, completion: handler)
}

func purchaseProduct(product: CBProduct, customer: CBCustomer? = nil, completion handler: @escaping ((_ result: Result<CBValidateReceipt, Error>) -> Void)) {
func purchaseProduct(product: CBProduct, customer: CBCustomer? = nil, completion handler: @escaping ((_ result: Result<PurchaseSubscription, Error>) -> Void)) {
buyProductHandler = handler
activeProduct = product
self.customer = customer
Expand Down Expand Up @@ -308,7 +308,7 @@ public extension CBPurchase {
}
}

func validateReceipt(_ product: CBProduct?, customer: CBCustomer? = nil, completion: ((Result<CBValidateReceipt, Error>) -> Void)?) {
func validateReceipt(_ product: CBProduct?, customer: CBCustomer? = nil, completion: ((Result<PurchaseSubscription, Error>) -> Void)?) {

guard let receipt = getReceipt(product: product?.product, customer: customer) else {
debugPrint("Couldn't read receipt data with error")
Expand All @@ -325,7 +325,7 @@ public extension CBPurchase {
return
}
self.activeProduct = nil
completion?(.success(result))
completion?(.success(PurchaseSubscription(status: true, subscriptionDetails: result)))
case .error(let error):
debugPrint(" Chargebee - Receipt Upload - Failure")
completion?(.failure(error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ struct CBValidateReceiptWrapper: Decodable {
case inAppSubscription = "in_app_subscription"
}
}
// MARK: - Subscription
public struct PurchaseSubscription: Decodable {
public let status: Bool
public let subscriptionDetails: CBValidateReceipt
}

public struct CBValidateReceipt: Decodable {
public let subscriptionId: String
Expand Down
15 changes: 6 additions & 9 deletions Example/Chargebee/CBSDKProductsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ final class CBSDKProductsTableViewController: UITableViewController, UITextField
CBPurchase.shared.validateReceipt(product,customer: nil) { result in
switch result {
case .success(let result):
print(result.subscriptionId )
print(result.planId)
print(result.customerId)
print(result.status)
print(result.subscriptionDetails)

if CBDemoPersistance.isPurchaseProductIDAvailable(){
CBDemoPersistance.clearPurchaseIDFromCache()
Expand Down Expand Up @@ -283,9 +282,8 @@ extension CBSDKProductsTableViewController: ProductTableViewCellDelegate {
print(result)
switch result {
case .success(let result):
print(result.subscriptionId)
print(result.planId)
print(result.customerId)
print(result.status)
print(result.subscriptionDetails)

DispatchQueue.main.async {
self.view.activityStopAnimating()
Expand Down Expand Up @@ -361,9 +359,8 @@ extension CBSDKProductsTableViewController: ProductTableViewCellDelegate {
print(result)
switch result {
case .success(let result):
print(result.subscriptionId)
print(result.planId)
print(result.customerId)
print(result.status)
print(result.subscriptionDetails)


DispatchQueue.main.async {
Expand Down

0 comments on commit d41234e

Please sign in to comment.