Jump to content

Check which payment option used at checkout success


alexm
 Share

Recommended Posts

Hi @alexm,

3 hours ago, alexm said:

order-complete.php

This template file will receive $order as well as $orderLineItems, $orderCustomer and a bunch of other variables shown below:

<?php

namespace ProcessWire;

/** @var WireData $order */
/** @var WireArray $orderLineItems */
/** @var float $orderSubtotal */
/** @var bool $isOrderGrandTotalComplete */
/** @var bool $isOrderConfirmed */

Payment info is in $order. We save the title of the payment method. You can use that by itself or use it to grab the payment gateway/method page itself (e.g. if you want the ID for some reason. Here's an example:

<?php

namespace ProcessWire;

// COMPLETED ORDER
/** @var WireData $order */
bd($order, __METHOD__ . ': $order at line #' . __LINE__);
// PAYMENT GATEWAY/METHOD TITLE
/** @var string $order->paymentMethod */
bd($order->paymentMethod, __METHOD__ . ': $order->paymentMethod at line #' . __LINE__);
# OR ALIAS
/** @var string $order->payment */
bd($order->payment, __METHOD__ . ': $order->payment at line #' . __LINE__);
/** @var string $paymentGatewayTitle */
$paymentGatewayTitle = $order->payment;
/// GET ID OF PAYMENT GATEWAY/METHOD
/** @var int $paymentGatewayPageID */
$paymentGatewayPageID = (int)$padloper->getRaw("template=payment-provider,title={$paymentGatewayTitle}", 'id');
bd($paymentGatewayTitle, __METHOD__ . ': $paymentGatewayTitle at line #' . __LINE__);
bd($paymentGatewayPageID, __METHOD__ . ': $paymentGatewayPageID at line #' . __LINE__);
// IN CASE YOU WANT THE PAGE ITSELF FOR SOME REASON
/** @var Page $paymentGatewayPage */
$paymentGatewayPage = $padloper->get("template=payment-provider,title={$paymentGatewayTitle}");
bd($paymentGatewayPage, __METHOD__ . ': $paymentGatewayPage at line #' . __LINE__);

Hope this helps.

  • Like 1
Link to comment
Share on other sites

1 hour ago, alexm said:

So I can check with for instance: 

if ($order->paymentMethod == Invoice)

Or no?

Defo!

<?php

if ($order->paymentMethod == Invoice){
echo 'Mate, clock is ticking! :-)';
}

Sorry I wasn't clear. 

  • Haha 1
Link to comment
Share on other sites

  • 2 months later...
On 7/6/2022 at 11:10 PM, kongondo said:
On 7/6/2022 at 9:47 PM, alexm said:

So I can check with for instance: 

if ($order->paymentMethod == Invoice)

Or no?

Defo!

So, it's just been brought to my attention that this isn't working. Should it in fact be

if ($order->payment == Invoice)

to get the actual title?

Link to comment
Share on other sites

Hi @alexm,

1 hour ago, alexm said:

So, it's just been brought to my attention that this isn't working. Should it in fact be

Strange. It works here. Both $order->payment and $order->paymentMethod should work (see TracyDebugger grab below).

Screenshot

padloper-2-demo-order-complete-variables.thumb.jpg.c0e3a28a972358c66abff91230970d14.jpg

Just confirming that you have a custom order-complete.php at /site/templates/padloper/order-complete.php ?

  • Like 1
Link to comment
Share on other sites

Hmm, I added logs between the if statement and they aren't being written so I assume that it's failing before this. Could if be that I'm trying to get the product ID incorrectly? Sorry about this mate.

// forach product in the order
foreach ($orderLineItems as $p) {
  // check to see if it is a membership product and if the user is logged in
  if (in_array($p->product_id, [8473, 8474]) && $user->isLoggedin()) {
    // if the order is not of payment type PaymentInvoice (bank transfer)

    wire()->log->save('wes-checkout', 'There is a membership product in the order.');

    if ($order->payment != 'Invoice') {
      wire()->log->save('wes-checkout', 'Member should automatically be made active.');

 

Link to comment
Share on other sites

2 hours ago, alexm said:

Could if be that I'm trying to get the product ID incorrectly?

Yep. That's exactly it. My bad, docs are still lagging.

2 hours ago, alexm said:
$p->product_id

This should be one of the following:

<?php

namespace ProcessWire;

$p->productID;
// aliases
$p->lineItemProductID;
$p->orderItemProductID;

Let me know if it works.

  • Like 1
Link to comment
Share on other sites

8 minutes ago, kongondo said:

Yep. That's exactly it. My bad, docs are still lagging.

2 hours ago, alexm said:

Nah, not at all. I could have done better digging. I thank you sir! I'll report back. Thank you as always!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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