Redirect to custompage.php instead of viewinvoice.php if payment fails in WHMCS Vs 6.2.0 - whmcs

I wish to redirect to a custom page following the failure in payment as returned by payment gateway.
To this end, I am using the ShoppingCartCheckoutCompletePage hook to check this using the variable $vars['ispaid'].
When payment is successful, $vars['ispaid'] is true and the redirect to the thankyou page works.
add_hook('ShoppingCartCheckoutCompletePage', 1, function ($vars)
{
# Will be true if the order has been paid
if($vars['ispaid'] == true)
{
#redirect to thank you page
header('location:'.thankYouPage);
die;
}
else
{
header('location:'.transactionFailedPage);
die;
}
}
However the else statement is not executing when payment obviously fails,
rather the viewinvoice.php page is loaded and payment status set to 'unpaid'
Am I missing something?
How can I redirect to the transaction failed page?
Thanks.

WHMCS doesn't provide an intuitive way to get to where you are wanting to go, that's for sure. You may need to add a file to execute in the hooks directory to run without a hook - any php you add into the hooks directory gets executed as soon as the system starts up and security checks are done. So this means you can see if you are a) on the viewinvoice.php file, b) if there is an error message indicating a failed payment and c) redirect from there if these are true.
The ShoppingCartCheckoutCompletePage I believe is only called after the order is complete and payment is made, that's what I recall though, and again, it's not intuitive.
Hope that is of help.

Related

Twilio mobile number verification - VerificationCheck was not found on Express

The requested resource /Services/serviceSSID/VerificationCheck was not found is the eroor showing in the console
my code is
otpLogin:async (req,res)=>{
console.log(req.body.otp);
try {
const isOTP = await client.verify.services(serviceSSID).verificationChecks.create({
to:`+91${req.body.phone}`,
code:req.body.otp
})
if(isOTP)console.log(isOTP);
return res.status(200).json({message:" mobile number verified"})
} catch (error) {
console.log(error.message)
return res.status(500).json({message:"something went wrong"})
}
}
Twilio developer evangelist here.
From the documentation:
Twilio deletes the verification SID once it’s:
expired (10 minutes)
approved
when the max attempts to check a code have been reached
If any of these occur, verification checks will return a 404 not found error like this:
Unable to create record: The requested resource /Services/VAXXXXXXXXXXXXX/VerificationCheck was not found
If you’d like to double check what happened with a given verification - please use the logs found in the Twilio Console under your Verification Service:
I've found that if you submit a form twice by clicking a submit button twice quickly, that the verification is successfully checked and then because it was a success deleted, then the second check fails with a 404 like this and that is the error result you see. To avoid this, you should stop users from being able to submit the form twice by disabling the submit button after the first attempt.
I can confirm that philnash 2nd statement is correct. However wouldn't it have been handled way better if instead we just get a response from client.verify.services(serviceSSID).verificationChecks that the 2nd (and so on checks) failed??

intermittent error from rally 'Not authorized to perform action: Invalid key' for POST request in chrome extension

I developed a chrome extension using Rally's WSAPI v2.0, and it basically does the following things:
get user and project, and store them
get current iteration everytime
send a post request to create a workitem
For the THIRD step, I sometimes get error ["Not authorized to perform action: Invalid key"] since end of last month.
[updated]Error can be reproduced everytime if I log in Rally website via SSO before using the extension to send requests via apikey.
What's the best practice to send subsequent requests via apikey in my extension since I can't control end users' habits?
I did see some similar posts but none of them is helpful... and in case it helps:
I'm adding ZSESSIONID:apikey in my request header, instead of user /
password to authenticate, so I believe no security token is needed
(https://comm.support.ca.com/kb/api-key-and-oauth-client-faq/kb000011568)
url starts with https://rally1.rallydev.com/slm/webservice/v2.0/
issue is fixed after clearing cookies for
https://rally1.rallydev.com/, but somehow it appears again some time
later
I checked the cookie when the issue was reproduced, and found one with name of ZSESSIONID and its value became something else rather than the apikey. Not sure if that matters though...
code for request:
function initXHR(method, url, apikey, cbFunc) {
let httpRequest = new XMLHttpRequest();
...
httpRequest.open(method, url);
httpRequest.setRequestHeader('Content-Type', ' application\/json');
httpRequest.setRequestHeader('Accept', ' application\/json');
httpRequest.setRequestHeader('ZSESSIONID', apikey);
httpRequest.onreadystatechange = function() {
...
};
return httpRequest;
}
...
usReq = initXHR ('POST', baseURL+'hierarchicalrequirement/create', apikey, function(){...});
Anyone has any idea / suggestion? Thanks a million!
I've seen this error when the API key had both read-only and full-access grants configured. I would start by making sure your key only has the full-access grant.

Kraken API AddOrder passes successfully but order is not placed on Kraken

I'm trying Kraken APIs via C# and I managed to call public APIs as well as private APIs for getting the balance and getting open orders. But when I wanted to try an AddOrder API I encountered a problem, the API is executed successfully, but there is no order on Kraken.
Below is the result I get after calling AddOrder API. It seems normal, no errors and all parameters are as I specified them (sell 0.01 btc at 8100.00 usd)
{"error":[],"result":{"descr":{"order":"sell 0.01000000 XBTUSD # limit 8100.0"}}}
But there is no order on Kraken platform. Any idea what I did wrong?
As #Milos found, validate = False will place the order.
From the documentation https://www.kraken.com/features/api#add-standard-order
validate = validate inputs only. do not submit order (optional)
I figured out that parameter validate has to be false!!
By default I set validate to true (which should be desired I guess),
but it does not work.
With validate == false order is placed correctly.
FYI, even if validate == false, basic input arguments check is performed.
When adding an order setting validate=true is a good means of testing. If you want to execute the order, set validate=false.

Javascript redirects on page->open

Using behat/mink, I'm testing the "remember me" functionality. Functionally, when the user visits the main page, javascript/ajax code verifies if the user is "remembered". If yes, then the javascripts redirects to another page. My LoginPage is defined with $path = '/login.html' - after the redirect, I will end up on /main.html.
In my context, I use $loginPage->open() - however this throws exception Expected to be on "https://example.com/login.html" but found "https://example.com/main.html" instead. Naturally, this aborts the execution and results in the test failing - yet this is exactly the behaviour I want.
How can I tell behat/mink to not verify URL or ignore URL mismatch?
If you check the open() method you will see that the check that fails for you is when is checking the url parameters in verify() method.
If you want to avoid this you can override this method to check only for the response and not the url parameters.
In order to do this you need to extend Page and declare a new method like this:
public function verify(array $urlParameters){
$this->verifyResponse();
}

Docpad : show error/success message on contact form

I added a route in my docpad.coffee file to handle form submissions, that I validate using the express-validator middleware. Now depending on the validation, I want to redirect the users to the same contact page but displaying either a success message when validation is successful (here I'll send an email), or display the error messages.
I didn't manage to pass the validation message to the template to display it. I tried almost all combinations of dynamic: true/false, res.locals = validationMessages, res.sessions = validationMessages, res.templateData = validationMessages with no success.
Furthermore, adding dynamic: true made the changes to the content not appear at all, whatever refresh strategy I use (private mode, cleaning cache, relaunching Docpad, refreshing without cache, etc.). I should probable file a bug about it.
How to ?
I'm using Docpad 6.53.0 (latest to date), node 0.10.15, on OS X 10.8.4
I cheated on this one a bit by appending a hash to the redirect url (eg: "www.mywebsite.com/#messagesent"). I then use client side javascript to read the hash and then show the appropriate message. Something like this:
if (location.hash == "#messagesent") {
$('#message-sent').show();
setTimeout(function () {
$('#message-sent').fadeOut(1000);
}, 1000);
}
Not quite what you were asking though :)