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

Double Purchase Event with ApplePay Fix #1402

Merged
merged 2 commits into from
Jun 10, 2024

Conversation

NidhiDixit09
Copy link
Collaborator

@NidhiDixit09 NidhiDixit09 commented Jun 4, 2024

Reference

INTENG-20410 - [Multiple] Purchase event being triggered twice in iOS
https://branch.atlassian.net/browse/INTENG-20410

Summary

In Event queue, dequeue function is replaced with - (void)remove:(BNCServerRequest *)request function.
This fix will, instead of removing first event in the queue, will remove current event from the queue.

Detailed Description

When In-App-Purchase sheet or Apple Pay sheet appears branch goes to inactive state. After payment is done, logEvent API is called inside the Apple/Stripe payment API callback. And then sheet is closed and app comes back to active state again. This creates two events -

* Standard Purchase Event
* Open Event

Following is order of events happened inside SDK:

  • Standard Purchase Event Inserted in Queue and processing of Next Event in Queue is triggered by calling function processNextQueueItem
  • Open Event Created and inserted in beginning of Queue and processing of Next Event in Queue is triggered again by calling function processNextQueueItem. (Note: Branch Open/Install events are inserted in begining og queue)
  • At the same time, Purchase Event Processing finishes and request is made to remove it from Queue. For removing dequeue function is called which removes the first Event in Queue. So instead of removing PurchaseEvent, OpenEvent is removed.

Queue State(s)
PurchaseEvent (Waiting)
PurchaseEvent (In Processing) —> OpenEvent (Waiting)
PurchaseEvent (Finished) —> OpenEvent (Waiting)
PurchaseEvent (Finished)
PurchaseEvent (In Processing)

Fix: Instead of removing first event in the queue, current event (whose processing finished) should be removed.

Type Of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing Instructions

Use following sample app for testing.
https://github.com/BranchMetrics/InAppPurchaseAPITest

This app uses sandbox envirnoment for testing.
- Steps for creating sandbox test user account - https://developer.apple.com/help/app-store-connect/test-in-app-purchases/create-sandbox-apple-ids.
- Use above account for purchase.

Validate Following :

After you close Apple Pay Purchase Sheet,

Without Fix
--> You you will see double purchase events in logs and No open event.
With Fix
--> You you will see one purchase event and one open event in logs.

cc @BranchMetrics/saas-sdk-devs for visibility.

@gdeluna-branch gdeluna-branch changed the title [ WIP ] Double Purchase Event with ApplePay Fix Double Purchase Event with ApplePay Fix Jun 7, 2024
@nsingh-branch
Copy link
Contributor

I was able to repo the issue in the testbed by using the "In-App Purchase Event" button and changing the updatedTransactions delegate method to this. It doesn't reproduce 100% of the time, but I am frequently able to see the logEvent callback being hit twice and two identical Purchase events going out.

case SKPaymentTransactionStatePurchased: {
    NSLog(@"Transaction succesfully purchased");

    BranchEvent *event  = [BranchEvent standardEvent:BranchStandardEventPurchase];
    
    [event logEventWithCompletion:^(BOOL success, NSError * _Nullable error) {
        [[SKPaymentQueue defaultQueue] finishTransaction:(SKPaymentTransaction *)transaction];
        NSLog(@"Logged Test Event!");
    }];
    
    break;
}

With fix in this PR, I successfully see only one proper Purchase event going out each time now.

@nsingh-branch nsingh-branch merged commit 6103eab into master Jun 10, 2024
12 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.

2 participants