Jazzcash Payment Integration V2.0 - react-native

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);

Related

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.

Ebay Unsupported API call error upon using GuzzleHttp client v6

I am trying to get sessionid by using ebay Trading API . I am able to get session id successfully by using Curl but as soon as i try to fetch session id via Guzzle Http client, get below error in response from ebay
FailureUnsupported API call.The API call "GeteBayOfficialTime" is
invalid or not supported in this release.2ErrorRequestError18131002
I suppose there's some issues with the way i am using GuzzleHttp client . I am currently using GuzzleHttp v6 and new to this . Below is the code i am using to get session id by calling actionTest function
public function actionTest(){
$requestBody1 = '<?xml version="1.0" encoding="utf-8" ?>';
$requestBody1 .= '<GetSessionIDRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
$requestBody1 .= '<Version>989</Version>';
$requestBody1 .= '<RuName>test_user-TestAs-Geforc-ldlnmtua</RuName>';
$requestBody1 .= '</GetSessionIDRequest>';
$headers = $this->getHeader();
$client = new Client();
$request = new Request('POST','https://api.sandbox.ebay.com/ws/api.dll',$headers,$requestBody1);
$response = $client->send($request);
/*$response = $client->post('https://api.sandbox.ebay.com/ws/api.dll', [
'headers' => $headers,
'body' => $requestBody1
]);*/
echo $response->getBody();die;
}
public function getHeader()
{
$header = array(
'Content-Type: text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL: 989',
'X-EBAY-API-DEV-NAME: a4d749e7-9b22-441e-8406-d3b65d95d41a',
'X-EBAY-API-APP-NAME: TestUs-GeforceI-SBX-345ed4578-10122cfa',
'X-EBAY-API-CERT-NAME: PRD-120145f62955-96aa-4d748-b1df-6bf4',
'X-EBAY-API-CALL-NAME: GetSessionID',
'X-EBAY-API-SITEID: 203',
);
return $header;
}
Plz suggest the possible shortcoming in the way i am making request . I already tried/modified the guzzle request call by referring various reference site and guzzle official doc but error remained same .
You need to pass an associative array of headers as explained in the documentation.
public function getHeader()
{
return [
'Content-Type' => 'text/xml',
'X-EBAY-API-COMPATIBILITY-LEVEL' => '989',
'X-EBAY-API-DEV-NAME' => '...',
'X-EBAY-API-APP-NAME' => '...',
'X-EBAY-API-CERT-NAME' => '...',
'X-EBAY-API-CALL-NAME' => '...',
'X-EBAY-API-SITEID' => '203',
];
}
In case you are interested there is an SDK available that simplifies the code. An example of how to call GetSessionID is shown below.
<?php
require __DIR__.'/vendor/autoload.php';
use \DTS\eBaySDK\Trading\Services\TradingService;
use \DTS\eBaySDK\Trading\Types\GetSessionIDRequestType;
$service = new TradingService([
'credentials' => [
'appId' => 'your-sandbox-app-id',
'certId' => 'your-sandbox-cert-id',
'devId' => 'your-sandbox-dev-id'
],
'siteId' => '203',
'apiVersion' => '989',
'sandbox' => true
]);
$request = new GetSessionIDRequestType();
$request->RuName = '...';
$response = $service->getSessionID($request);
echo $response->SessionID;

create product rule using bigcommerce API

I'm trying to create a product rule using bigcommerce api but i get the error :
"array(1) { [0]=> object(stdClass)#1352 (2) { ["status"]=> int(400) ["message"]=> string(55) "The field 'adjustor' is not supported by this resource." } } "
this is my code :
$adjustor = new stdClass() ;
$adjustor->adjustor="absolute";
$adjustor->adjustor_value=14.25;
$rule = array(
"sort_order" => 0,
"is_enabled" => true,
"is_stop" => false,
"price_adjuster" => $adjustor,
"weight_adjuster" => null,
"is_purchasing_disabled" => false,
"purchasing_disabled_message" => "",
"is_purchasing_hidden" => false,
'conditions' => array($x, $y)
);
$result = Bigcommerce::createProductRule($productId, $rule);
echo '<pre>';
var_dump($result);
echo '</pre>';
if (!$result) {
$error = Bigcommerce::getLastError();
var_dump($error);
}
This just looks like a typo. You spelled adjustor instead of adjuster.
It should be:
$adjustor->adjuster="absolute";
$adjustor->adjuster_value=14.25;

Get the CSRF token in test

I'm writing functional test and i need to make ajax post request. "The CSRF token is invalid. Please try to resubmit the form". How can i get the token in my functional test ?
$crawler = $this->client->request(
'POST',
$url,
array(
'element_add' => array(
'_token' => '????',
'name' => 'bla',
)
),
array(),
array('HTTP_X-Requested-With' => 'XMLHttpRequest')
);
CSRF token generator is normal symfony 2 service. You can get service and generate token yourself. For example:
$csrfToken = $client->getContainer()->get('form.csrf_provider')->generateCsrfToken('registration');
$crawler = $client->request('POST', '/ajax/register', array(
'fos_user_registration_form' => array(
'_token' => $csrfToken,
'username' => 'samplelogin',
'email' => 'sample#fake.pl',
'plainPassword' => array(
'first' => 'somepass',
'second' => 'somepass',
),
'name' => 'sampleuser',
'type' => 'DSWP',
),
));
The generateCsrfToken gets one important parameter intention which should be the same in the test and in the form otherwise it fails.
After a long search (i've found nothing in doc and on the net about how to retrieve csrf token) i found a way:
$extract = $this->crawler->filter('input[name="element_add[_token]"]')
->extract(array('value'));
$csrf_token = $extract[0];
Extract the token from response before make the request.
In symfony 3, in your WebTestCase, you need to get the CSRF token:
$csrfToken = $client->getContainer()->get('security.csrf.token_manager')->getToken($csrfTokenId);
To get the $csrfTokenId, the best way would be to force it in the options of your FormType ():
class TaskType extends AbstractType
{
// ...
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'csrf_token_id' => 'task_item',
));
}
// ...
}
So in this case: $csrfTokenId = "task_item";. Or you you can try to use the default value, that would be the name of your form.
Then use it as a post parameter:
$client->request(
'POST',
'/url',
[
'formName' => [
'field' => 'value',
'field2' => 'value2',
'_token' => $csrfToken
]
]
);
Just in case someone stumble on this, in symfony 5 you get the token this way:
$client->getContainer()->get('security.csrf.token_manager')->getToken('token-id')->getValue();
where 'token-id' is the id that you used in the configureOptions method in your form type, which would look something like this:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
"data_class" => Foo::class,
"csrf_protection" => true,
"csrf_field_name" => "field_name", //form field name where token will be placed. If left empty, this will default to _token
"csrf_token_id" => "token-id", //This is the token id you must use to get the token value in your test
]);
}
Then you just put the token in the request as a normal field.