If a payment gateway with payment instructions was used to place an order, those instructions are shown at checkout complete. We should also include them in the order receipt email.

Issue fork commerce-2884497

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bojanz created an issue. See original summary.

bojanz’s picture

Might also make sense in the user's order view, at least if the payment is not complete yet.

vasike’s picture

Status: Active » Needs review
StatusFileSize
new2.72 KB

Here is patch for this.
For this I added extra "payment_instructions" variable the commerce_order_receipt theme.

iki_cz’s picture

Dunno, how to display payment instructions on user's order view, but @vasike's patch for payment instructions is working fine (in order to show payment info at order receipt). RBTC

iki_cz’s picture

Status: Needs review » Reviewed & tested by the community

Tested on clean D8 + Commerce installation.

iki_cz’s picture

Here is updated version of patch #3, that reflects current 8.x-2.x-dev version.

There was an error with #3 patch after 8.x-2.x update:
Recoverable fatal error: Argument 1 passed to Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\Manual::buildPaymentInstructions() must implement interface Drupal\commerce_payment\Entity\PaymentInterface, none given, called in /var/www/clients/client1/web155/web/web/modules/contrib/commerce/modules/payment/commerce_payment.module on line 179 and defined ve funkci Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\Manual->buildPaymentInstructions() (řádek 72 souboru /var/www/clients/client1/web155/web/web/modules/contrib/commerce/modules/payment/src/Plugin/Commerce/PaymentGateway/Manual.php) #0 /var/www/clients/client1/web155/web/web/core/includes/bootstrap.inc(566): _drupal_error_handler_real(4096, 'Argument 1 pass...', '/var/www/client...', 72, Array) #1 /var/www/clients/client1/web155/web/web/modules/contrib/commerce/modules/payment/src/Plugin/Commerce/PaymentGateway/Manual.php(72): _drupal_error_handler(4096, 'Argument 1 pass...', '/var/www/client...', 72, Array) #2

mglaman’s picture

Status: Reviewed & tested by the community » Needs work

We have OrderReceiptTest. We should mimic one in Payment which verifies the information is added to the receipt. Without a test we have no idea if this works or not.

+++ b/modules/payment/commerce_payment.module
@@ -163,9 +163,31 @@
+  	return;
...
+  ¶
...
+  	$payment_storage = \Drupal::entityTypeManager()->getStorage('commerce_payment');
+  	$payments = $payment_storage->loadMultipleByOrder($order);
+  	$payments = array_filter($payments, function ($payment) use ($payment_gateway) {
+  		return $payment->getPaymentGatewayId() == $payment_gateway->id();
+  	});
+  	
+  	$payment = reset($payments);
+  	if ($payment) {
+  		$variables['payment_instructions'] = $payment_gateway_plugin->buildPaymentInstructions($payment);
+  	}

Looks like whitespace and tab errors.

bbuchert’s picture

Just tested the patch in #6 and it works well.

finex’s picture

I will try the patch, it's exactly what I'm looking for.

P.S The payment should also be visible on the order page for the backend users without needing to click on "payments" tab. :-)

finex’s picture

Hi, I've updated the patch adding the payment gateway. What do you think?

netzkombuese’s picture

#10 was exactly what we needed. Works fine so thanks for that.

finex’s picture

Status: Needs work » Needs review

Hi, does the patch need more work or can it be applied?

The last submitted patch, 3: order_receipt_payment_instructions-2884497-3.patch, failed testing. View results

The last submitted patch, 3: order_receipt_payment_instructions-2884497-3.patch, failed testing. View results

fenstrat’s picture

StatusFileSize
new7.24 KB
new7.84 KB

Attached adds a kernel test as requested in #7.

It also removes the payment gateway from #10 as I'm not sure of the value of that? This also brings it into line with what is displayed on the checkout completion message (i.e. just the payment instructions).

hockey2112’s picture

#10 worked for me. Thanks!

introfini’s picture

#15 worked perfectly, thanks!

jon pollard’s picture

HI, it looks like this patch is no longer applying to the latest 8.x-2.x-dev version as of 21/02/2020

fenstrat’s picture

StatusFileSize
new7.16 KB

Here's a re-roll for 8.x-2.x-dev.

Status: Needs review » Needs work

The last submitted patch, 19: 2884497-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

fenstrat’s picture

Status: Needs work » Needs review
StatusFileSize
new7.16 KB

Re-roll of #19, and also to kick the tests off again as the fails look unrelated.

Status: Needs review » Needs work

The last submitted patch, 21: 2884497-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

filipetakanap’s picture

I need a patch of this for drupal 9 =(

jsacksick’s picture

What if the order is already paid? What's the point of showing payment instructions in this case?

paulo.faria’s picture

Any updates for Drupal 9?

petiar’s picture

Correct me if I am wrong, but if there is no payment for the order at all, then the

$payments = $payment_storage->loadMultipleByOrder($order);

in patch #15 results in an empty array, so no payment instructions will be displayed. And no payment is exactly the case when we want payment instructions to be displayed, right?

I am on Drupal 9.

cYu made their first commit to this issue’s fork.

agoradesign’s picture

@petiar: no, a payment gateway can implement a certain interface (I think it's called HasPaymentInstructionsInterface) in order to be able to show payment instructions to the user. A classic example is the Manual payment, where you display the instructions to pay to bank account XY. In this case, we do have a payment entity, but it's state is that it's not paid at that moment

jglynn’s picture

Any patch for Drupal 9?

nchase’s picture

I tested the patch #21 in Drupal 10 and it is working. Thank you!

nchase’s picture

I'd like to add that this feature is really important. When using manual payments like a bank transfer, where you provide the bank account details and the reference-number, it is important that all those payment details are within the mail and not just once on the website. I consider it a must-have.

newaytech’s picture

Upgrading from - drupal/commerce (3.2.0 => 3.3.2): - and noticed all the new hook syntax coming into play.

The patch we have here has therefore failed to apply. Could we perhaps ask for a re-roll if still relevant?

Think it's just 2 x; order & payment module files effected.

fenstrat’s picture

Version: 8.x-2.x-dev » 3.x-dev

Also his this not applying to commerce 3.3.2.

Re #24 "What if the order is already paid? What's the point of showing payment instructions in this case?" - probably a fair point. However the approach here adds the payment instructions in exactly the same way as is done for the checkout completion message. And when it's done there it doesn't have any check for the order being paid.

fenstrat’s picture

StatusFileSize
new7.27 KB

Odd, when I try and create a new branch from 3.x in the issue for UI at the top of the issue, I get Failed to create branch '2884497-payment-instructions': invalid reference name '3.x'.

Attached is a patch version of what I'd planned to put into a MR based on 3.x. If someone else has more luck with that then this is probably ready for NR.

newaytech’s picture

Thanks @fenstrat - but I think I may have been a little premature in my reporting... I see that your logic already appears in CommercePaymentThemeHooks ? I've removed the patch I used historically - and the functionality remains. Has it found it's way into the commerce module?

fenstrat’s picture

@newaytech right, that's been there for a long time and is what displays this same payment instructions at checkout completion, i.e. #[Hook('preprocess_commerce_checkout_completion_message')]. What this issue is about is adding the same thing to the order receipt emails, i.e. #[Hook('preprocess_commerce_order')].

newaytech’s picture

@fentstrat - OK, good stuff. We re-use the hooks and duplicate an exact same receipt include for both browser page and email. I've removed the patch - but thank you for the help regardless...

idebr made their first commit to this issue’s fork.

idebr changed the visibility of the branch 2884497-show-payment-instructions to hidden.

idebr’s picture

Status: Needs work » Needs review

Patch #35 is now available as merge request: https://git.drupalcode.org/project/commerce/-/merge_requests/663