How to perform test WHMCS Hook with some trigger URL? - whmcs

how can I test the whmcs hook 'invoicepaid' without paying the invoice each time to test the output of the $vars and function ?
<?php
add_hook('InvoicePaid', 1, function($vars) {
// Perform hook code here...
});
Could it be something like that can trigger the invoicepaid hook ? e.g. ?id=43&hook=invoicepaid?

Related

TestCafe : How can I make TestCafe to run some application code only once before all the fixtures

In my application, I want to set up some test data from the UI before running any Fixture. I want to do this set up only once and don't want to do this before each fixture.
Can someone please help me on how to do this ?
I tried to use approach mentioned on below thread but I cannot use test controller - t inside before.
https://testcafe-discuss.devexpress.com/t/run-the-same-before-and-after-hook-for-all-fixtures-and-configure-a-baseurl/551
I have an idea you can check if you feel it works for you as below, you will still use beforeEach in this case as you wish to access to t:
let didSetup = false;
fixture`yourFixture`
.beforeEach(async t => {
if (!didSetup) {
// You set up things here
await yourSetup();
didSetup = true;
}
// Otherwise won't do anything
})

Filter middleware js

I need to add into my MVC js project a middleware filter which will transfer control to the controller which will do some actions if the filter condition is false and render a special page if a condition is true (but not giving the controll to the controller). It must be a middleware which executes before the controller logic and it SHOULD NOT BE a function in the controller.
Here i have a route which now just executes a download method in the controller.
if (config.common.zoneName === 'main') {
router.get('/book/:itemid', new
DownloadController(ResourceRepo).download);
}
I need to add there some logic, for example
if (itemid > 10){
//render some special page
}
//execute download method on the same controller
}
In the real task condition is preety complex (such as getting the request IP and checking a field in a datadase with the same IP). So the condition is not an inline function but some complex method.
How can i do that using expressjs middleware?
Many thanks :3
I suppose you want to do something like this:
if (config.common.zoneName === 'main') {
router.get('/book/:itemid',
(req, res, next) => {
if (req.params.itemid > 10){
//render some special page
}
//execute download method on the same controller
},
new DownloadController(ResourceRepo).download);
}

Custom Payment Module:How Can i Pass smarty variables with in paymentoptions hook in prestashop 1.7?

I am worried about how can i pass smarty variable in paymentoptions hook in prestashop 1.7 version and get that variables in payment page.
In prestashop 1.7 paymentoptions hooks looks like this,
public function hookPaymentOptions($params)
{
$payment_options = new PaymentOption();
$action_text = $this->l('Pay by Credit Card with Stripe Payment');
/*$payment_options->setLogo(Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/views/img/card.png'));*/
$payment_options->setCallToActionText($action_text);
$payment_options->setAction($this->context->link->getModuleLink($this->name, 'confirmation', array(), true));
$payment_options->setModuleName($this->name);
$payment_options->setAdditionalInformation($this->context->smarty->fetch('module:stripepay/views/templates/hook/checkout.tpl'));
$payments_options[] = $payment_options;
return $payments_options;
}
with in this hook how can i pass this secure_key ="FGDWFGF$#%#%!$" values in checkout.tpl files for making successful payments.
Now i have keep this values as static.
Please anybody knows this please assist with this.
I hope you understand my question.
Maybe try to use $_SESSION if you just only have to preserve it for later.
For checkout.tpl you should use hookPayment($params) instead, it's meant to populate a TPL and it's retrocompatible with older versions :
public function hookPayment($params)
{
$this->context->smarty->assign(array('myvar'=>'thevalue'));
return $this->display(__FILE__, 'checkout.tpl');
}

How do you poll for a condition in Intern / Leadfoot (not browser / client side)?

I'm trying to verify that an account was created successfully, but after clicking the submit button, I need to wait until the next page has loaded and verify that the user ended up at the correct URL.
I'm using pollUntil to check the URL client side, but that results in Detected a page unload event; script execution does not work across page loads. in Safari at least. I can add a sleep, but I was wondering if there is a better way.
Questions:
How can you poll on something like this.remote.getCurrentUrl()? Basically I want to do something like this.remote.waitForCurrentUrlToEqual(...), but I'm also curious how to poll on anything from Selenium commands vs using pollUntil which executes code in the remote browser.
I'm checking to see if the user ended up at a protected URL after logging in here. Is there a better way to check this besides polling?
Best practices: do I need to make an assertion with Chai or is it even possible when I'm polling and waiting for stuff as my test? For example, in this case, I'm just trying to poll to make sure we ended up at the right URL within 30 seconds and I don't have an explicit assertion. I'm just assuming the test will fail, but it won't say why. If the best practice is to make an assertion here, how would I do it here or any time I'm using wait?
Here's an example of my code:
'create new account': function() {
return this.remote
// Hidden: populate all account details
.findByClassName('nextButton')
.click()
.end()
.then(pollUntil('return location.pathname === "/protected-page" ? true : null', [], 30000));
}
The pollUntil helper works by running an asynchronous script in the browser to check a condition, so it's not going to work across page loads (because the script disappears when a page loads). One way to poll the current remote URL would be to write a poller that would run as part of your functional test, something like (untested):
function pollUrl(remote, targetUrl, timeout) {
return function () {
var dfd = new Deferred();
var endTime = Number(new Date()) + timeout;
(function poll() {
remote.getCurrentUrl().then(function (url) {
if (url === targetUrl) {
dfd.resolve();
}
else if (Number(new Date()) < endTime) {
setTimeout(poll, 500);
}
else {
var error = new Error('timed out; final url is ' + url);
dfd.reject(error);
}
});
})();
return dfd.promise;
}
}
You could call it as:
.then(pollUrl(this.remote, '/protected-page', 30000))
When you're using something like pollUntil, there's no need (or place) to make an assertion. However, with your own polling function you could have it reject its promise with an informative error.

Yii Framework Captcha conflict with beforeAction() function

I have app in Yii and i extend all classes from some base controller and i have these code in it :
protected function beforeAction($action)
{
$this->setglobalvariable();
return parent::beforeAction($action);
}
as i just understand , these code prevent the Captcha to show , because when i delete it , the captcha shows up ! the captcha function is :
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'minLength'=>2,
'maxLength'=>3,
'width'=>60,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
So how could i use beforeAction and captcha in same time ?
The confilict is in your structure , Show us more code . put the program in fresh yii and test it.
beforeAction function , Do not have any conflict with other Yii methods or functions.
The probelm is in your code.
Obviously there is some code in your Controller::setglobalvariables() method that conflicts with the captcha's code.
The CCaptachAction::run() method uses $_GET parameters. Are you somehow resetting $_GET ?
Can you show us the code ?