Closed NidhiDixit09 closed 2 months ago
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.
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 -Following is order of events happened inside SDK:
processNextQueueItem
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
Testing Instructions
Use following sample app for testing. https://github.com/BranchMetrics/InAppPurchaseAPITest
This app uses sandbox envirnoment for testing.
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.