concretecms-community-store / community_store_paypal_standard

Paypal Standard payments for Community Store for Concrete CMS
MIT License
6 stars 7 forks source link

Multiple emails sent after sale #15

Open craigmarcussen opened 2 years ago

craigmarcussen commented 2 years ago

Hello,

I have been using the PayPal gateway with Community Store on a client's site for over a year. I recently changed the web hosting provider, and now when a transaction goes through, I receive 5 - 10 emails with the sale details. These emails are being sent from the CS site, and they all come within about 20 mins of each other. Is this a possible issue with the PP gateway, or could it be an issue with the hosting mail servers?

I was hoping this may have previously come up, but didn't see anything about it in the Issues.

Thank you, Craig

Mesuva commented 2 years ago

That sounds like the callback to the server is triggering the completion of the order, but it's hitting an error somewhere between sending the notification email, and completing the response to Paypal - so Paypal thinks it failed and sends it again.

I'd expect to see an error in Concrete's logs for something like this, or failing that, there's an IPN page in Paypal you can use to see the response from your site, and see if there's an error message in that: https://developer.paypal.com/docs/api-basics/notifications/ipn/IPNOperations/ (link to the page is the first one 'IPN History Page')

So I doubt this is the mail server, and something different about the new environment that is triggering an error.

craigmarcussen commented 2 years ago

Wow, thanks for the lightning-fast response!

I am getting this error in the c5 logs: Exception Occurred: /home/{serverlogin}/public_html/application/mail/order_receipt.php:182 Call to undefined method Concrete\Package\CommunityStore\Src\CommunityStore\Order\OrderItem::getBarcode() (0)

Is the issue that there is no barcode data? I am not using that attribute on the site, as the client doesn't use barcodes.

Mesuva commented 2 years ago

That looks like you've overridden the order_receipt email template (note how it's in /application). And in that override, it's calling a function that hasn't ever existed, and hasn't been in the receipt emails. There is a way to fetch the barcode for a product and output in the email, but the error here suggests that it's not being done the right way.

You'll need to:

craigmarcussen commented 2 years ago

Ah, right. I should have been able to put that together. I did add that field to a custom template a while ago, because I use it for a Product Number. I completely forgot about doing that. I have removed it from the custom order_receipt.php file, and the emails now seem to go through without issue.

As always, thank you so much for the quick response! If I did want to pull the barcode data into the receipt, can you give me an idea of how I would do that?

Craig

Mesuva commented 2 years ago

No worries, glad we could find the issue!

The barcode isn't stored on the order item, it's just on the product, so it would need to be something like:

$barcode = false;

$variationID = $item->getVariationID();
if ($variationID) {
    $variation = \Concrete\Package\CommunityStore\Src\CommunityStore\Product\ProductVariation\ProductVariation::getByID($variationID);
    if ($variation){
        $barcode = $variation->getVariationBarcode();
    }
} else { 
    $product =  $item->getProductObject();
    if ($product) { 
        $barcode = $product->getBarcode();
    }
}

It's a bit long winded though, there's probably some functions that should be added to Community Store to make this a bit cleaner. I might leave this issue open to remind me to add a few more functions to make this easier to do.

craigmarcussen commented 2 years ago

Great, thank you for putting that together. I will give it a try.