Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with receipt_page #31

Closed
seldimi opened this issue Feb 7, 2024 · 12 comments
Closed

Example with receipt_page #31

seldimi opened this issue Feb 7, 2024 · 12 comments

Comments

@seldimi
Copy link

seldimi commented Feb 7, 2024

Hello.
Is there anyhow an example to show how receipt_page() is working on a blocks payment gateway? Some payment gateways require a form to be submited upon checkout and not using process_payment direct.

@danielcharrua
Copy link

@seldimi Looking for the same, maybe you can help us here 🙏 @jimjasson

@jimjasson
Copy link
Contributor

Hey there @seldimi and @danielcharrua,

Thank you for getting in touch!

Can you please provide some more details about what you want to achieve here? Which receipt_page function are you referring to? Is it perhaps the receipt template? Is there any code that you have seen perhaps in a different payment gateway that we can use as a reference to better understand what you have in mind?

Thank you!

cc @senadir in case you might have a better clue, since checkout blocks are mentioned here :)

@danielcharrua
Copy link

Hey @jimjasson

We usually use this in an action hook for sending the client to an intermediary page and do some payment procedure.
e.g. showing a QR with payment options.

add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) );

/**
 * Output for the order received page.
 *
 * @param int $order_id The order ID.
 * @return void
 */
public function receipt_page( $order_id ) {

  $order   = wc_get_order( $order_id );
  $invoice = false;
  
  if ( ! $this->order_already_has_invoice( $order_id ) ) {
  
	  try {
		  // create invoice
	  } catch ( Exception $e ) {
		  // Handle the exception.
		  // Display an error message to the user.
	  }
  } else {
	  $invoice = wc_get_order( $order_id )->get_meta( 'some_invoice' );
  }

}

Maybe there's a better approach to achieve this...
Thanks.

@jimjasson
Copy link
Contributor

Hey @danielcharrua,

Thank you for the example!

The woocommerce_receipt_ action is part of this template that is enqueued only in short-code checkout: https://github.com/woocommerce/woocommerce/blob/f437c538e7933e10ebf558d6e023c1dcf8b00bdc/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php#L245

Is there a chance that your snippet doesn't run on the block based checkout?

@danielcharrua
Copy link

Hello @jimjasson

Let me explain our case: we are trying to set a crypto payment on our payment gateway, so our goal is once the order is placed, show the payment instructions to the user and then internally check if the payment has arrived.

We initially thought on using the woocommerce_receipt_ action but maybe there is another approach and show our payment instructions on the “Order received” page.

Our plugin is a fork of this one, so we are using the block based checkout.

@jimjasson
Copy link
Contributor

Hey @danielcharrua,

Thank you for the additional details!

As far as I understand, you would like to display some additional instructions on the order confirmation page to help customers complete their payment. Is that right?

If so, then I recommend using the woocommerce_thankyou_ action -- see: https://github.com/woocommerce/woocommerce/blob/35c50ebdb417d2a15ae22eb65451773919b5607a/plugins/woocommerce/src/Blocks/BlockTypes/OrderConfirmation/AdditionalInformation.php#L32

Here's an example:

add_action( 'woocommerce_thankyou_dummy', 'print_test_content' );

function print_test_content() {
	echo "This is a test";
}

To test this snippet, you may use a plugin like Code Snippets.

Does this help?

@seldimi
Copy link
Author

seldimi commented May 7, 2024

Hello
Let me share our cases. We have created three payment gateways from Greek banks. All need a form which submits some hidden fields. So they expect a form POST action to a given url. One of these three also requires an extra post with curl to get a token which result will be used to that form.
We are using woocommerce_receipt to create a “we are now redirecting you to the bank” where we create the form populated with values needed and submit it
How that could happen ?

woocommerce_thank you is too late to be called there.

@jimjasson
Copy link
Contributor

Hey @seldimi,

Thank you for sharing your use case, as well!

Can you please provide some more details about the issue you noticed? Are you referring to this woocommerce_receipt_ action: https://github.com/woocommerce/woocommerce/blob/42902ef96df752fd85abef3638d028694592280c/plugins/woocommerce/templates/checkout/order-receipt.php#L44 ?

If so, is there a chance that this action runs with the legacy checkout but not with the block-based one? Or does it always run but it doesn't work with the Dummy Payments gateway? Have you tried with a WooCommerce core payment gateway like Cash on Delivery (COD)? Can you share a short snippet of the code you are trying to run?

@seldimi
Copy link
Author

seldimi commented May 9, 2024

Yes, feel free to visit webexpert.company and go through the process of purchase. You will see that after checkout, there is an intermedia page, where form is created and submited via JavaScript and then process continues.
API requires POST from post submit.

@jimjasson
Copy link
Contributor

jimjasson commented May 9, 2024

Hey @seldimi,

Thank you for the additional details!

I had a look at your site and I noticed that you are using the classic/legacy checkout at the moment. I added a product to the cart and selected the "Credit Card" payment gateway. When I clicked to pay for the order, a pop-up window briefly showed up informing me that I am being redirected to a bank's environment.

Is there a chance that you want to port the solution you created for the classic/legacy checkout to the block-based checkout?

If so, then did you try using the woocommerce_receipt_ hook and it didn't work? Can you share a short snippet that I can try locally?

If this is not what you are trying to achieve, could you share some more details about the issue you noticed with your current setup?

@seldimi
Copy link
Author

seldimi commented May 9, 2024

Exactly... we use the reciept page and echo a form.
The popup comes from jQuery.blockUI

and then we submit the form via
jQuery("#submit").click();

you can find a similar approach here
https://github.com/eellak/woocommerce-alphabank-payment-gateway/blob/40f7bc0608b5e802d103448ab2e9a6810b8f538b/woocommerce-alphabank-payment-gateway.php#L353C18-L353C30

This doesnt work on checkout blocks... i have tried and tested your dummy gateway with that approach.

@jimjasson
Copy link
Contributor

Hey @seldimi,

You are right that this action doesn't run in the block-based checkout -- I opened an issue in the WooCommerce core repository: woocommerce/woocommerce#47349.

Feel free to continue the discussion there! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants