Hi, I am working on synching payments with our bank’s API. I have a server where I store all incoming payments with a variable symbol which represents TXN_ID. So far, I have been submiting payments through cUrl. I have used an URL which is the same as if you submit a form in „Apply payment“ modal.
The url looks like this:
I am using authentication through cookie that I get prior the cUrl request and then I send it in header. This worked so far, but after updating EE plugins and WordPress to latest version, it requires Nonce. When I run the cUrl, I get back „Nonce fail“ error.
The reason I am doing it this way, is because it’s all in one request. What is crucial for me is:
$txnId, $regStatusChange, $value, $bankTypeID
Is there a way to perform this request without sending nonce? Or a way to send all of those properties though API?
I’m Event Espresso’s lead developer.
The nonce is essentially a one time use pass code that helps to verify that the incoming request is legitimate (nonce is short for “number used once“). This helps to prevent man in the middle attacks where someone intercepts a request and then tries to mess with your system by changing parameters around and resubmitting. Since they can’t reuse the previous nonce, and there would be no way for them to generate a new nonce for their request, it’s easy to identify their request as being invalid.
I can see that your cURL request already includes a parameter for the nonce
You can easily add one by adding the following in your PHP code prior to sending your request (i’m assuming your requests are being sent from the same server your WP site is on):
and then use its value for the espresso_apply_payment_nonce URL parameter.
IF however, your requests are not originating from the same server your WP site is on, then you will need to do things a little differently. You could try something like:
create a secret endpoint you can send your requests to instead of directly trying to hit the espresso_apply_payment admin route, THEN create another request to hit the espresso_apply_payment admin route but add the nonce value (not ideal)
OR create a secret endpoint that simply generates a nonce value for espresso_apply_payment_nonce and returns that to your other server so you can include it in your cURL request that submits the payment (also not ideal)
OR (this might be the best option) hook into the incoming requests really early on and try to detect your cURL requests. When you find one, generate the nonce and add it to the request paramters. You could use the FHEE___EventEspresso_core_services_bootstrap_BootstrapRequestResponseObjects__buildRequestResponse__request filter from EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects::buildRequestResponse() which would allow you to add your nonce directly to our Request object.
Maybe something like:
add_filter(
'FHEE___EventEspresso_core_services_bootstrap_BootstrapRequestResponseObjects__buildRequestResponse__request',
function (Request $request, array $request_params, array $server_params) {
if (/* logic to detect your request params within $request_params and/or $server_params */ ) {
$request->setRequestParam(
'espresso_apply_payment_nonce',
wp_create_nonce('espresso_apply_payment_nonce')
);
}
return $request;
},
10,
3
);
then when that request hits the espresso_apply_payment admin route, it will have the appropriate nonce
please note that the above code snippets are just off the top of my head and have not been verified to work correctly. If you know how to make cURL requests though then you shouldn’t have any issues figuring things out from there.
As well, you’ll want to set up some kind of additional security if you are going to do any of the above so that your requests can not be highjacked by bad actors. This could include something like setting up private and public keys on the servers and using that to validate some kind of signature first before proceeding, or you could use JWTs to send your requests between servers, which would handle that for you (this would be my aproach). Bottom line is just don’t leave an open door on your system for others to use.
Let me know how it goes and please don’t hesitate to ask any follow up questions.
Good luck, Brent
Viewing 1 reply thread
The support post ‘Payment sync’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.