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

[final] add should purchase promo product #25

Merged
merged 20 commits into from
Jan 27, 2020

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Jan 23, 2020

Description

https://trello.com/c/emjo2Nlf

Related PR: RevenueCat/react-native-purchases#98

This is still missing cleanup work, but it's functional.

Changes summary:

  • bumped iOS sdk to v3.0.2, updated path to Purchases.framework in script
  • added method makeDeferredPurchase, to be called by client apps when they're ready to make a promotional purchase.
  • added method shouldPurchasePromoProduct, called by the SDK when it detects that a promotional purchase should be made.
  • added addShouldPurchasePromoProductListener and removeShouldPurchasePromoProductListener, to be called by client apps so they can set up listeners. They will get a function that they call to trigger the purchase on our side, which they can call whenever the app is ready to make the purchase.

Code flow:

  • client calls set up purchases.
  • this sets up a callback id, to be used later when promo purchases are detected.
  • client registers listeners for when promo purchases are ready to be made. listeners are functions, and they should internally call makeDeferredPurchase();. listeners won't be executed until promo purchases are detected.
  • we store the listeners (clients can remove them if needed).
  • app is used, time passes
  • promo purchase is detected by app
  • sdk calls shouldPurchasePromoProduct. we store a callback id to identify the exact call.
  • sdk notifies client that it's ready to make a deferred purchase. Listeners are notified, they execute client code and call makeDeferredPurchase()
  • makeDeferredPurchase gets the callback id to identify the exact call, and calls makeDeferredPurchase on the sdk.

@aboedo aboedo self-assigned this Jan 23, 2020
@aboedo aboedo changed the title [wip] add should purchase promo product [final] add should purchase promo product Jan 23, 2020
@aboedo aboedo requested a review from vegaro January 23, 2020 22:34
@@ -28,7 +28,7 @@ curl -sSL $URL > temp.zip
# In some cases the temp folder can not be created by unzip, https://github.com/RevenueCat/react-native-purchases/issues/26
mkdir -p temp
unzip -o temp.zip -d temp
mv temp/Purchases.framework ./Purchases.framework
mv temp/Carthage/Build/iOS/Purchases.framework ./Purchases.framework
Copy link
Member Author

Choose a reason for hiding this comment

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

new path in 3.0.2

@@ -22,6 +22,7 @@
- (void)createAlias:(CDVInvokedUrlCommand *)command;
- (void)identify:(CDVInvokedUrlCommand *)command;
- (void)reset:(CDVInvokedUrlCommand *)command;
- (void)setupShouldPurchasePromoProductCallback:(CDVInvokedUrlCommand *)command;
Copy link
Member Author

Choose a reason for hiding this comment

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

this is so that we get a different callback id, which we can store and use later when notifying javascript

return false;
}

private static setupShouldPurchasePromoProductCallback() {
Copy link
Member Author

Choose a reason for hiding this comment

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

we weren't using private functions here, but I figured it wouldn't hurt

Copy link
Contributor

Choose a reason for hiding this comment

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

I love it

*/
public static addShouldPurchasePromoProductListener(shouldPurchasePromoProductListener: ShouldPurchasePromoProductListener): void {
if (typeof shouldPurchasePromoProductListener !== "function") {
throw new Error("addPurchaserInfoUpdateListener needs a function");
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, fixing

Copy link
Contributor

@vegaro vegaro Jan 24, 2020

Choose a reason for hiding this comment

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

Cool. I commented on my review on this before seeing this

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@vegaro vegaro left a comment

Choose a reason for hiding this comment

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

Why did src/ios/Purchases.framework/Purchases get removed??

}

private static setupShouldPurchasePromoProductCallback() {
window.cordova.exec(
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't Android crash because setupShouldPurchasePromoProductCallback doesn't exist in the Android code?

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch. I'll fix it and update. I forgot to test on android (hides in shame)

return false;
}

private static setupShouldPurchasePromoProductCallback() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I love it

private static setupShouldPurchasePromoProductCallback() {
window.cordova.exec(
(callbackResult: any) => {
const callbackID = callbackResult.callbackID;
Copy link
Contributor

Choose a reason for hiding this comment

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

This two lines could be removed with:
({callbackID}:{callbackID: number}) => {

Copy link
Member Author

Choose a reason for hiding this comment

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

cool! didn't know that! I'll update

@aboedo
Copy link
Member Author

aboedo commented Jan 24, 2020

I'm not sure what's going on with src/ios/Purchases.framework.Purchases on github. I see it locally, and it was modified on this commit:
https://github.com/revenuecat/cordova-plugin-purchases/commits/438fc31d47d7933b53b9c81567aa3ad7f520ea1e
however, git show 438fc31d47d7933b53b9c81567aa3ad7f520ea1e shows it as modified

diff --git a/src/ios/Purchases.framework/Purchases b/src/ios/Purchases.framework/Purchases
index 7899882..e41cb3f 100755
Binary files a/src/ios/Purchases.framework/Purchases and b/src/ios/Purchases.framework/Purchases differ

I tried clean-cloning and checking out the branch and I do get the file, so I'm not sure what's going on. I'll do some further digging, but right now it seems that Github is the only one that sees the file as removed.

@aboedo
Copy link
Member Author

aboedo commented Jan 24, 2020

you can even see the file on the branch: https://github.com/RevenueCat/cordova-plugin-purchases/blob/feature/addShouldPurchasePromoProduct/src/ios/Purchases.framework/Purchases

So I really think this is a github bug. If I try removing the file on my local repo and check git diff, it does show that I'm removing it.

@aboedo
Copy link
Member Author

aboedo commented Jan 24, 2020

@vegaro would you mind doing a sanity check by checking out the branch?

@@ -156,6 +156,11 @@ private void setAutomaticAppleSearchAdsAttributionCollection(boolean enabled, Ca
// NOOP
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setupShouldPurchasePromoProductCallback")
private void setupShouldPurchasePromoProductCallback(CallbackContext callbackContext) {
// NOOP
Copy link
Member Author

Choose a reason for hiding this comment

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

wild violation of Interface Segregation Principle, but I think it's okay? I copied it from line 156.
other ideas would be to have the javascript side decide (which isn't ideal), or to somehow split interfaces, which might be too much work for too little gain.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is better too

@aboedo aboedo requested a review from vegaro January 24, 2020 18:11
@aboedo
Copy link
Member Author

aboedo commented Jan 24, 2020

@vegaro ready for another pass

@aboedo aboedo merged commit 36aa716 into master Jan 27, 2020
@aboedo aboedo deleted the feature/addShouldPurchasePromoProduct branch January 27, 2020 13:41
@aboedo aboedo mentioned this pull request Feb 3, 2020
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.

2 participants