Need help in implementing omnipay - omnipay

Hello everyone i need a working example to use stripe and skrill of Omnipay library.
The github code didn't not help me a lot. Thankyou
use Omnipay\Omnipay;
$gateway = Omnipay::create('Stripe'); $gateway->setApiKey('abc123');
$formData = ['number' => '4242424242424242', 'expiryMonth' => '6',
'expiryYear' => '2016', 'cvv' => '123']; $response =
$gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'card'
=> $formData])->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response); } elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect(); } else {
// payment failed: display message to customer
echo $response->getMessage(); }

I think it should be $gateway = GatewayFactory::create('PayPal_Express');
Also what is the exact error that shows up.

Related

Jazzcash Payment Integration V2.0

I'm working on Rest based api version 2.0. It constantly giving me error
Please provide a valid value for pp_SecureHash
It is working fine in case of "Page redirection" so hash key generation method is correct and issue is with parameters (maybe some missing/extra/wrong data). what I'm doing wrong?
{ “uri”: “https://sandbox.jazzcash.com.pk/ApplicationAPI/API/2.0/Purchase/DoMWalletTransaction”, “method”: “POST”, “body”: “pp_Amount=1100&pp_BillReference=billRef&pp_CNIC=345678&pp_Description=jazzcash&pp_Language=EN&pp_MerchantID=xyz&pp_MobileNumber=03123456789&pp_Password=xyz&pp_ReturnURL=https://sandbox.jazzcash.com.pk/ApplicationAPI/API/2.0/Purchase/DoMWalletTransaction&pp_SecureHash=BC3BABD0481A2FA756F2E16CE15FC6F8029D40E23B974065668CCEAC300B80AE&pp_TxnCurrency=PKR&pp_TxnDateTime=20220406132730&pp_TxnExpiryDateTime=20220406142730&pp_TxnRefNo=T20220406142730&ppmpf_1=1&ppmpf_2=2&ppmpf_3=3&ppmpf_4=4&ppmpf_5=5” }
Your pp_SecureHash value needs to be HmacSHA256 encoded.
var sHash = HMACSHA256Encode(hash, jazz.salt);
You can refer this code sample to achieve your requirement.
C#: Generate pp_SecureHash ()
Please check your merchant Id, password and salt key. It's also through the error if your any of info is wrong.
Read the doc carefully. if add version 1.2 and in the doc it's mention 1.1 it's not going to work and through the same error. provide valid secure
If you are sure that other info is correct so you can generate secure ssh by using below method
$post_data = array(
"pp_Version" => Config::get('constants.jazzcash.VERSION'),
"pp_TxnType" => "MWALLET",
"pp_Language" => Config::get('constants.jazzcash.LANGUAGE'),
"pp_MerchantID" => Config::get('constants.jazzcash.MERCHANT_ID'),
"pp_SubMerchantID" => "",
"pp_Password" => Config::get('constants.jazzcash.PASSWORD'),
"pp_BankID" => "TBANK",
"pp_ProductID" => "RETL",
"pp_TxnRefNo" => $pp_TxnRefNo,
"pp_Amount" => $pp_Amount,
"pp_TxnCurrency" => Config::get('constants.jazzcash.CURRENCY_CODE'),
"pp_TxnDateTime" => $pp_TxnDateTime,
"pp_BillReference" => "billRef",
"pp_Description" => "Description of transaction",
"pp_TxnExpiryDateTime" => $pp_TxnExpiryDateTime,
"pp_ReturnURL" => Config::get('constants.jazzcash.RETURN_URL'),
"pp_SecureHash" => "",
"ppmpf_1" => "1",
"ppmpf_2" => "2",
"ppmpf_3" => "3",
"ppmpf_4" => "4",
"ppmpf_5" => "5",
);
private function get_SecureHash($data_array)
{
ksort($data_array);
$str = '';
foreach($data_array as $key => $value){
if(!empty($value)){
$str = $str . '&' . $value;
}
}
$str = Config::get('constants.jazzcash.INTEGERITY_SALT').$str;
$pp_SecureHash = hash_hmac('sha256', $str, Config::get('constants.jazzcash.INTEGERITY_SALT'));
//echo '<pre>';
//print_r($data_array);
//echo '</pre>';
return $pp_SecureHash;
}
And Last by calling this method you can get the secure key
$pp_SecureHash = $this->get_SecureHash($post_data);

Prestashop custom module routing issue after update to 1.7.8.4

I just updated a PrestaShop website from 1.7.8.3 to 1.7.8.4, everything worked fine, but I'm havine 404 errors on custom module routes.
On module install I register routes like:
$this->registerHook('ModuleRoutes')
And my routes are like:
public function hookModuleRoutes() {
$urls = array(
'module-mymodulename-posts' => array(
'controller' => 'posts',
'rule' => 'posts/list',
'keywords' => array(),
'params' => array(
'fc' => 'module',
'module' => 'mymodulename',
)
),
...
);
return $urls;
}
Now www.mywebsite.com/posts/list returns 404.
And www.mywebsite.com/modules/mymodulename/posts works but url is not looking as good.
It all was working fine until this morning update.
Any idea on how I could get this solved ?
I have nothing about routing in the release logs.
Apparently a PrestaShop bug:
https://github.com/PrestaShop/PrestaShop/issues/27854
that just got a fix:
https://github.com/PrestaShop/PrestaShop/pull/27874/files
Fix works fine on my side.
You have to change getHookStatusByName function in classes/Hook.php file :
public static function getHookStatusByName($hook_name): bool
{
$hook_names = [];
if (Cache::isStored('active_hooks')) {
$hook_names = Cache::retrieve('active_hooks');
} else {
$sql = new DbQuery();
$sql->select('lower(name) as name');
$sql->from('hook', 'h');
$sql->where('h.active = 1');
$active_hooks = Db::getInstance()->executeS($sql);
if (!empty($active_hooks)) {
$hook_names = array_column($active_hooks, 'name');
if (is_array($hook_names)) {
Cache::store('active_hooks', $hook_names);
}
}
}
return in_array(strtolower($hook_name), $hook_names);
}

vTiger API Rest - create new lead

I downloaded the vTiger classes from here:
https://blog.crm-now.de/2018/02/26/new-api-description-and-new-example-code-for-crm-rest-operations/?lang=en
But when I try to create a new lead it gives me this in response:
"create failed: lastname does not have a value"
Below is my code:
$params= array(
'email' => 'myemail#libe.test',
'firstname' => 'my_name',
'lastname ' => 'my_surname',
'assigned_user_id' => 'my_user_id'
);
$url = "url_my_site.com/webservice.php";
$wsC = new WS_Curl_Class($url, 'my_username', 'secret_key');
if (!$wsC->login()) {
echo "error";
}
$result = $wsC->operation("create", array("elementType" => "Leads", "element" => json_encode($params)), "POST");
if ($wsC->errorMsg) {
// ERROR handling if describe operation was not successful
echo $wsC->errorMsg;
}
I don't understand why that error returns to me. Can someone help me?
Thank you
Probably because there is a space at the end of 'lastname'

Lumen Google reCAPTCHA validation

I already seen some tuts and example about it and I have implemented it somehow.
Method in controller looks like this:
The logic used is just php and I would like to use more a lumen/laravel logic and not just simple vanilla php. Also I have tried and did not worked anhskohbo / no-captcha
public function create(Request $request)
{
try {
$this->validate($request, [
'reference' => 'required|string',
'first_name' => 'required|string|max:50',
'last_name' => 'required|string|max:50',
'birthdate' => 'required|before:today',
'gender' => 'required|string',
'email' => 'required|email|unique:candidates',
'g-recaptcha-response' => 'required',
]);
//Google recaptcha validation
if ($request->has('g-recaptcha-response')) {
$secretAPIkey = env("RECAPTCHA_KEY");
// reCAPTCHA response verification
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretAPIkey.'&response='.$request->input('captcha-response'));
$response = json_decode($verifyResponse);
if ($response->success) {
//Form submission
//Saving data from request in candidates
$candidate = Candidate::create($request->except('cv_path'));
$response = array(
"status" => "alert-success",
"message" => "Your mail have been sent."
);
} else {
$response = array(
"status" => "alert-danger",
"message" => "Robot verification failed, please try again."
);
}
}
} catch(Exception $e) {
return response()->json($e->getMessage());
}
return response()->json(['id' => $candidate->id, $response]);
}
Okey. Google has an package for this:reCAPTCHA PHP client library
just: composer require google/recaptcha "^1.2"
and in your method inside controller:
$recaptcha = new \ReCaptcha\ReCaptcha(config('app.captcha.secret_key'));
$response = $recaptcha->verify($request->input('g-recaptcha-response'), $_SERVER['REMOTE_ADDR']);
if ($response->isSuccess()) {
//Your logic goes here
} else {
$errors = $response->getErrorCodes();
}
config('app.captcha.site_key') means that I got the key from from config/app.php and there from .env file.
If you have not config folder, you should create it, also create app.php file same as in laravel.

Update API in laravel 5.7

I have create API of update my project details, I test it in POSTMAN app it shows the success message but there no effect in the database.
Here are my code:
ProjectsController.php
public function UpdateProject($id)
{
$data = Input::all();
$q = Project::where('id',$id)->update($data);
return response()->json([
'code' => SUCCESS,
'message' => 'Project data update successfully'
]);
}
api.php
Route::post('UpdateProject/{id}','ProjectsController#UpdateProject');
Postman - see image.
output in postman:
{
"code": "200",
"message": "Project data update successfylly"
}
Can anyone help me out?
Thank you
I think you need to check all input details closely , it also comes with token when you submit the form so you need to save all details except token
Change this
$data = Input::all();
to this
$data = Input::except('_token');
I hope this resolves the issue.
in your model add fillable :
protected $fillable = ['name', 'project_group_id','number','ROM','address','city','state','zip','start_date','end_date','duration','description','timeline_type','project_type_id','project_category_id','office_id'];
You have forgotten to run the ->save() method after updating the data:
public function UpdateProject($id)
{
$data = Input::all();
$q = Project::find($id)
$q = $q->fill($data);
$q->save();
return response()->json([
'code' => SUCCESS,
'message' => 'Project data update successfully'
]);
}
You can use this method it will reduce your code
Route (api)
Route::post('UpdateProject/{project}','ProjectsController#UpdateProject');
ProjectsController.php
public function UpdateProject(Request $request, Project $project)
{
$data = $request->all();
$project->update($data);
return response()->json([
'code' => SUCCESS,
'message' => 'Project data update successfully'
]);
}