Jump to content

Bug- Referrers not attributed during Stripe webhook checkout


Go to solution Solved by Marc,

Recommended Posts

Hello, I think I may have identified a situation where referrers are not attributed during checkout.

Prerequisites..

* Nexus set to "Force users to make a purchase when registering?".

* Using Stripe gateway.

* Have referrals configured

Issue (I think?)...

In Core, Referrals are logged and through an "onCreateAccount" MemberSync hook. It looks for the "referred_by" cookie in the request. However when using Stripe, our member accounts are created during the webhook request from Stripe - so the customers cookie is not present in the request, and the referral is not logged for the member.

I have some logging running during the "onCreateAccount" hook for one of my own extensions, so you can see the backtrace of the request that creates the account from Stripe (and therefore doesn't have the referred_by cookie).

image.thumb.png.1ecd85f25d192e04599234aff02ef1c1.png

Going through the checkout code I also see there's some logic to store the "referred_by" in the "guest_data" field on an invoice, but I don't see that stored in our database and I don't see any code that looks at that field to apply the referral via that route anyway (but maybe it worked this way in the past??)

Would really appreciate your help looking in to this!

Thanks!

 

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 2 months later...

@Marc Stridgen this issue is still present for us. I think the idea in your code is to save the "reffered_by" key to the "guest_data" of the invoice, when i test this and check the invoice in the database there's only a "guestTransactionKey" value... no other fields

So i've looked in to why this might be and it's in file /applications/nexus/sources/Invoice/Invoice.php line 1609. Function createAccountForGuest() overwrites this data and doesn't keep the referred_by key - it throws it out and therefore it's not applied later.

I have replaced this code with something like the following and can confirm this fixes the problem. If you can apply this fix/similar upstream that would be greatly appreciated, then we can start using this feature!

Around line 1609, replace...

$this->guest_data = isset( $this->guest_data['guestTransactionKey'] ) ? array( 'guestTransactionKey' => $this->guest_data['guestTransactionKey'] ) : NULL;

with...

$guest_data = array();
if (isset( $this->guest_data['referred_by'] )) {
    $guest_data['referred_by'] = $this->guest_data['referred_by'];
}
if (isset( $this->guest_data['guestTransactionKey'] )) {
    $guest_data['guestTransactionKey'] = $this->guest_data['guestTransactionKey'];
}

$this->guest_data = \count($guest_data) ? $guest_data : NULL;

 

Link to comment
Share on other sites

Thanks, thinking about the fix I posted, this code kinda stinks in general because it's not future proof for other values that might get added, so maybe better to keep the whole array and just remove the items that have been dealt with in that function... but obviously your call :-)

Edited by Convergent Trading
Link to comment
Share on other sites

  • 4 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...