Adding a custom WooCommerce payment gateway connection - wordpress

Our payment gateway and CRM and not supported by WooCommerce by default as a plugin, so I need to add custom code that sends data to our CRM and payment gateway whenever a customer places an order, then reject or accept the order depending on the payment gateway API response.
Where and how in the Woo code should I be intercepting the order submission?

You should try woocommerce_checkout_process action hook where the billing provider's API response, should return an error notice to reject and stop the checkout process…
This hook is located in WC_Checkout process_checkout() method and it's before the order creation. The data is accessible through $_POST or through $posted_data = WC()->checkout->get_posted_data(); WC_Checkout method.
Or woocommerce_checkout_order_processed action hook where the order is already created (meaning that the order data is accessible through 3 arguments: $order_id, $posted_data and $order) but before payment… To stop the process the billing provider's API response should: throw new Exception()…
So anyway the solution is one of the WC_Checkout available hooks…

Related

wordpress order key generate after return on payment gateway

hi I have a question I developed a custom payment gateway that is redirected to the payment portal after proceeding to check out when they return after payment is complete how can I create a URL link order id and order key link this order-received/785/?key=wc_order_5b909f1966e92

Trap attempt to send Woocommerce mail without To:

My Woocommerce shop allows to buy for anonymous customers without email address.
One of allowed payment method is online card payment.
I added blind copy to notification mail to allow admin know about payment:
add_filter('woocommerce_email_headers', function ($header, $email_id, $order) {
if ('customer_processing_order' === $email_id) {
$header .= "BCC: MyShopAdmin <myshopadmin#domain.net>";
}
return $header;
}, 10, 3);
Works great when customer entered email during checkout process.
None of email when customer not entered email address. Yes, it's reasonable - no email address = no email.
But I want to inform shop admin about successful payment even no customer email address entered. How to do it?
Guess exists some point in Woocommerce where I can analyze email headers early before mail send init. I did not find any hooks / filters for that.
Does anybody can help me?
instead of adding filter at woocommerce_email_headers why dont you try woocommerce_payment_complete hook
This would facilitate shop admin about successful payment event
add_action( 'woocommerce_payment_complete', 'payment_complete' );

Woocommerce custom online payment gateway

I'm trying to create my own custom online payment gateway plugin to allow clients to make payments through our bank payment gateway API.
So when the client clicks on "proceed to checkout" button, a RESTful exchange happens between our Woocommerce website and the bank payment gateway API to redirect the client to the payment page hosted in the bank platform to make the payment.
I've read most of the tutorials but they were not helpful and I'm getting lost:
https://www.sitepoint.com/building-a-woocommerce-payment-extension/
https://docs.woocommerce.com/document/payment-gateway-api/
My question is How can manage to make Woocommerce work with the payment API ?
In your function process_payment at the end you have that :
return array(
'result' => 'success',
'redirect' => $payment_url
);
$payment_url is the way where your order was redirected, so set it with your API response url, to redirect the client to the payment page hosted in the bank platform to make the payment.

PayPal asynchronous notification

Now information about the successful transaction I get with a redirect the user back to my site from paypal. And then I make additional requests to api paypal.
But if the user cancels the redirect to my site, for some reason, I do not get the information about the transaction.
Is there an asynchronous notification from Paypal for Website Payments Standard or Express Checkout?
Instant Payment Notification (IPN) works for all payment methods through PayPal. The Developer.PayPal.com document you linked is a list of variables for the Express Checkout feature and it is telling you that you can only pass the NOTIFYURL variable successfully in the DoExpressCheckoutPayment API call.
In Payments Standard transactions you'll use the notify_url variable.
You can also just enable IPN within your account to have an IPN post sent to your notification page when any payment completes - regardless of whether or not you define a URL in the button code or API request (the URL you define in the code will always override what is set in your account).

Paypal integration without IPN

I want to integrate paypal buy now button and get feedback from paypal in a school project, but i don't want to use IPN because the computer running the website will not be accessible from outside.
Are there any options for doing this?
You don't have to enable IPN to have buy now buttons on Paypal, it's completely optional. The buy now button will still take you to the correct page on Paypal so the purchase can be made. IPN only allows you to get feedback from Paypal when this happens.
Well, I need to get some information
when a successful payment is made.
Paypal can notify you by mail when something has happened.
Apologies for the bump. Just adding this in case anyone else needs it:
Use "rm=2". (input type hidden, name=rm, value=2)
https://merchant.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables
Return method. The FORM METHOD used to send data to the URL specified by the return variable after payment completion. Allowable values:
0 – all shopping cart transactions use the GET method
1 – the payer’s browser is redirected to the return URL by the GET method, and no transaction variables are sent
2 – the payer’s browser is redirected to the return URL by the POST method, and all transaction variables are also posted

Resources