Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customer Object Added to Restore API #81

Merged

Conversation

cb-gadagoju
Copy link
Contributor

@cb-gadagoju cb-gadagoju commented Aug 16, 2023

Issues :

  1. When customer sync validate receipt with Chargebee on restorePurchase API. The subscription gets created with new customerId instead of associating with the existing customer ID.

Fixes:
1.Introduced new param(CBCustomer object) in restorePurchases API which it helps to pass customer info while restoring the purchases and associate with the same customerId.

1. Passing customer_id for restore purchases
2. Handled customer_id in return handler for purchases.
@cb-gadagoju cb-gadagoju changed the title Feature/restore customer id fix Customer Object Added to Restore API Aug 16, 2023
@@ -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)?
public var buyProductHandler: ((Result<(status:Bool, subscriptionId:String?, planId:String?), Error>) -> Void)?
public var buyProductHandler: ((Result<(status:Bool, subscriptionId:String?, planId:String?, customerId:String?), Error>) -> Void)?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a breaking change for the SDK. If its not related to this PR, can we revert and take it up separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a breaking change for the SDK. If its not related to this PR, can we revert and take it up separately?

ok Its reverted

self.validateReceipt(product, completion: nil)
if let customer = self.restoreCustomer {
self.validateReceipt(product,customer: customer, completion: nil)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the customer without having to unwrap? The validateReceipt takes in an optional param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done Updated

CBPurchase.shared.restorePurchases(includeInActiveProducts: true) { result in
//Ex: customer_id is mandatory field for restoring purchases so please pass customer object as shown example below
let customer = CBCustomer(customerID: "Test123",firstName: "CB",lastName: "Test",email: "cbTest@chargebee.com")
CBPurchase.shared.restorePurchases(includeInActiveProducts: true, customer: customer) { result in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the README as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

…separate PR

2. Passing  'restoreCustomer' as optional for validateReceipt() since its expecting a optional parameter
@@ -135,10 +136,11 @@ public extension CBPurchase {
self.purchaseProductHandler(product: product, completion: handler)
}

func restorePurchases(includeInActiveProducts:Bool = false ,completion handler: @escaping ((_ result: Result<[InAppSubscription], RestoreError>) -> Void)) {
func restorePurchases(includeInActiveProducts:Bool = false, customer: CBCustomer, completion handler: @escaping ((_ result: Result<[InAppSubscription], RestoreError>) -> Void)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the customer as optional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the versions in corresponding places as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the customer as optional?

Now customerId is mandatory know then why it should be optional ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the versions in corresponding places as well.

ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cb-gadagoju During the purchase flow, the customer object is still optional. And the same goes for validateReceipt as well. Do you think the same can be extended to the restore flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cb-haripriyan yes we can implement optional as purchase flow but when its optional for restore merchant might consider optional and may skip it know any how he will get success after restore even if they didn't pass customer_id ? is't there any hidden problem which customer will know later again if they miss it ? i think we should highlight to customer for passing customerObject ! what you suggest ?

@sonarcloud
Copy link

sonarcloud bot commented Aug 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
10.0% 10.0% Duplication

@cb-amutha cb-amutha merged commit a27cbf1 into chargebee:master Aug 17, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants