HotcakesCommerce / hotcakes-commerce-core

The core of the e-commerce part of the overall solution. This is an ecommerce shopping cart solution built on top of the DNN (DotNetNuke) CMS. Anyone can do commerce online now!
https://mmmcommerce.com
MIT License
68 stars 55 forks source link

Custom gateway class -- Transaction.Items is null first time ProcessTransaction is called #345

Closed mindcross closed 3 years ago

mindcross commented 3 years ago

Describe the bug

When processing a purchase via a custom gateway class (a class inheriting from PaymentGateway), the overridden method ProcessTransaction will receive a parameter of type Transaction, which has a property called Items. For the very first purchase the Items property is null, which of course means the purchase is unable to complete successfully since no item information is available. Subsequent purchase attempts succeed (the Transaction.Items is populated correctly).

Software Versions

To Reproduce

  1. Perform an iisreset
  2. Purchase a product
  3. Purchase fails (if your code relies on the Items list not being null).
  4. Try to purchase the product again, with the same user and type in the exact same payment information.
  5. This time the Items list is present and populated and the purchase succeeds.
  6. Perform another iisreset and you can reproduce the problem again.

Example code:

public override void ProcessTransaction(Transaction t) { //t.Items is null (FIRST purchase attempt only)

foreach(var item in t.Items) //blows up here when t.Items is null { //do something } }

Expected behavior

The Items list should always contain the items being purchased by the user.

joshgk00 commented 3 years ago

I experienced the same issue. I think I found the cause. What I found was that in the ReceiveCreditCards.ProcessTransaction method the order number that was supposed to be supplied to the Transaction object being created, was always an empty string. This was the case for my custom payment provider and also the providers that come out of the box. If the OrderNumber is blank, the Order Repository will return the first item it finds or it'll return null. I think that's why the items list is coming back null. I believe I have a fix for this bug.