[UPDATE BELOW]
I'm trying to get sdk_token which needed in the native app in this way
$requestParams = array(
'access_code' => $this->PayfortAccessCode ,
'amount' => floatval($amount)*100,
'currency' => strtoupper($currency),
'customer_email' => $email,
'merchant_reference' => $order_id,
'order_description' => $order_description,
'language' => $this->PayfortLanguage,
'merchant_identifier' => $this->PayfortMerchantID,
'payment_option' => $payment_option,
'command' => 'SDK_TOKEN',
'return_url' => $this->PayfortReturnUrl,
'customer_name' => $customer_name,
'customer_ip' => ''//$this->CI->input->ip_address()
);
$filtered_params = array_filter($requestParams);
ksort($filtered_params);
$this->setEncryptionKey($this->PayfortRequestEncryptionKey);
$postData = array();
foreach ($filtered_params as $name => $value) {
$postData[strtolower(htmlentities($name))] = htmlentities($value);
}
$postData['signature'] = $this->generate_signature($filtered_params);
$requestParams=json_encode($parameters['post_data']);
$result = file_get_contents('https://paymentservices.payfort.com/FortAPI/paymentApi', null, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json' . "\r\n"
. 'Content-Length: ' . strlen($requestParams) . "\r\n",
'content' => $requestParams,
),
)
));
$result=json_decode($result);
print_r($result);
Code is divided into multiple files but I view it as one file here. The problem is I get this response with "Invalid command" error
stdClass Object
(
[amount] => 2130
[response_code] => 00004
[signature] => signature_here
[merchant_identifier] => id_here
[access_code] => code_here
[language] => en
[command] => SDK_TOKEN
[response_message] => Invalid command
[merchant_reference] => reference_here
[customer_email] => email_here
[return_url] => url_here
[currency] => currency_symbol_here
[customer_name] => customer_name_here
[status] => 00
)
So how to fix this to get the SDK_TOKEN
[UPDATE]
changed Command to service_command and now I get this error
Channel not configured for selected payment option
To add new services or commands, I have to call the support to do this.
Related
We are using a Woocommerce Webhook to send a JSON request to a client who is using WSO2, but if they switch on authentication I get 401 error.
I have tried setting the consumer key and secret with wp_remote_post() and used the username and password and add it in the header for the request. These are more less the same thing but this is what I tried:
token = array( 'key' => 'MY_KEY','secret' => 'MY_SECRET', 'username' => 'MY_USERNAME', 'password' => 'MY_PASSWORD', 'default');
$response = wp_remote_post('URL', array(
'headers' => array(
'username' => 'MY_USERNAME',
'password' => 'MY_PASWORD',
'Authorization' => 'basic ' . $token,
'key' => 'CONSUMER KEY',
'secret' => 'SECRET',
'username' => 'USERNAME',
'password' => 'PASSWORD',
'www-authenticate' => array( 'key' => 'CONSUMER KEY','secret' => 'CONSUMER KEY', 'username' => 'USERNAME', 'password' => 'PASSWORD', 'default'),));
$basicauth = 'Basic ' . base64_encode( 'USERNAME' . ':' . 'PASSWORD' );
$headers = array(
'Authorization' => $basicauth,
'Content-type' => 'application/json',
'Content-length' => $contentlen
);
$pload = array(
'method' => 'POST',
'timeout' => 30,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => $headers,
'body' => $bdy,
'cookies' => array()
);
$response = wp_remote_post('URL', $pload);
This is the response I receive:
[Response] => Array
(
[Code] => 401
[Message] => Unauthorized
[Headers] => Requests_Utility_CaseInsensitiveDictionary Object
(
[data:protected] => Array
(
[date] => Tue, 23 Oct 2018 06:43:03 GMT
[server] => server
[accept] => */*
[access-control-allow-origin] => *
[access-control-allow-methods] => POST
[www-authenticate] => OAuth2 realm="WSO2 API Manager", error="invalid token", error_description="The access token expired"
[x-wc-webhook-source] => https://site . com/
[referer] => URL
[x-forwarded-host] => host
[x-forwarded-proto] => https
[x-wc-webhook-topic] => order.created
[x-wc-webhook-signature] => SIGNATURE
[accept-encoding] => deflate, gzip
[x-wc-webhook-event] => created
[access-control-allow-headers] => authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction
[x-wc-webhook-delivery-id] => ID
[expect] => 100-continue
[x-wc-webhook-id] => 1
[x-forwarded-for] => Array
(
[0] => test
[1] => test
)
[x-wc-webhook-resource] => order
[x-forwarded-server] => server
[content-type] => application/xml; charset=UTF-8
)
)
I am trying to post data using Guzzle 6,
The request which I am generating dynamically looks as below:
$postRequest = Array(
'headers' => array(
['x-api-key'] => 'srDxd39M2FQxxvfvxxcIohcLfKDcdcRUU'
)
'form_params' => array(
[0] => Array (
['name'] => 'function_key'
['contents'] => 'REGISTER'
)
[1] => Array (
['name'] => 'email'
['contents'] => 'tester#test.com'
)
[2] => Array (
['name'] => 'password'
['contents'] => 'test'
)
[3] => Array (
['name'] => 'name'
['contents'] => 'tester'
)
[4] => Array (
['name'] => 'is_org'
['contents'] => 'N'
)
)
)
// Sending Request using 'POST' Method
$client = new GuzzleHttp\Client();
$response = $client->request('POST','abcdxyz.com',$getRequest);
Now my problem is, The Response which I am receiving after sending the above request says "API 'function_key' is missing".
But I am sending 'function_key' as part of request, then What I am missing here ?? Why it is not able to find 'function_key'
Any help is Appreciated
TIA
Try formating it as follows:
$postRequest = [
'headers' => [
'x-api-key' => 'srDxd39M2FQxxvfvxxcIohcLfKDcdcRUU'
],
'form_params' => [
'function_key' => 'REGISTER',
'email' => 'tester#test.com',
'password' => 'test',
'name' => 'tester',
'is_org' => 'N'
]
]
I'm using this shopify api code. I've managed to get my app to install but now when I try to set up a charge for my app when I make the call I get this error:
Exception in api.php line 512:
ERROR #3: <url> malformed
This is my code:
$charge_params = array (
'recurring_application_charge' => array (
'name' => 'Name Of Charge',
'price' => 10,
'return_url' => 'https://dev.shopify.com/show_products/', // also tried escaping the url so https:\/\/dev.shopify.com\/show_products\/
'test' => true
)
);
$charge = $sh->call(['URL' => '/admin/recurring_application_charges.json', 'METHOD' => 'GET', 'DATA' => ['charge_params' => $charge_params]], false);
Can anyone see what I'm doing wrong? I suspect it might be the way the $charge_params is being passed in. There's no documentation on how to pass the charge data through that I can see.
I am just trying to recall what I did on an old project, here is how I handled it, I am using the following package for this https://github.com/phpish/shopify:
$connection = shopify\client($shop, Config::get('shopify.app_api_key'), $token);
$billing = $connection('POST /admin/recurring_application_charges.json', [
'recurring_application_charge' => [
'name' => 'Standard',
'price' => '5.0',
'return_url' => Config::get('app.url') . '/shopify/billing',
'test' => Config::get('shopify.test_mode')
]]);
Not sure if this is any help to you...
Had to pass the full URL and pass the charge array slightly differently. Also changed the method to "POST".
This code did the trick:
$charge = $sh->call([
'URL' => 'https://mystore.myshopify.com/admin/recurring_application_charges.json',
'METHOD' => 'POST',
'DATA' => array (
'recurring_application_charge' => array (
'name' => 'Name Of Charge',
'price' => 10,
'return_url' => 'https://dev.shopify.com/show_products/',
'test' => true
)
)
], false);
print_r($charge);
exit;
This returned the following:
stdClass Object ( [recurring_application_charge] => stdClass Object ( [id] => 2655692 [name] => Name Of Charge [api_client_id] => 1182423 [price] => 10.00 [status] => pending [return_url] => https://dev.shopify.com/show_products/ [billing_on] => [created_at] => 2016-08-03T13:50:11-04:00 [updated_at] => 2016-08-03T13:50:11-04:00 [test] => 1 [activated_on] => [trial_ends_on] => [cancelled_on] => [trial_days] => 0 [decorated_return_url] => https://dev.shopify.com/show_products/?charge_id=2655692 [confirmation_url] => https://mystore.myshopify.com/admin/charges/2655692/confirm_recurring_application_charge?signature=BAhpA8yFKA%3D%3D--8f87b4bd0d3cb9a588dfcb1566572731c0118776 ) )
I am trying to write a simple PHP client to get some data from Betfair through the Free Access API http://bdp.betfair.com/?option=com_content&task=view&id=33&Itemid=62
I can login & get a session token, this way
$wsdl = 'https://api.betfair.com/global/v3/BFGlobalService.wsdl';
$soapClient = new SoapClient($wsdl);
try {
$ap_param = array(
'request' =>
array(
'username' => 'my_username',
'password' => 'my_password',
'productId' => '82',
'ipAddress' => '',
'locationId' => '',
'vendorSoftwareId' => '',
),
);
$response = $soapClient->__call("login", array($ap_param));
...
$response is an object containing the sessionToken param
But after several tries I am afraid I am sending the APIRequestHeader param (http://bdp.betfair.com/docs/) malformed, cause the response to any call (getAllEventTypes, for instance) is always returning the same: NO_SESSION
One try...
$ap_param = array(
'request' =>
array(
'header' => array(
'session_token' => $response->Result->header->sessionToken,
'clientStamp' => 0,
),
),
);
Another try...
$ap_param = array(
'request' =>
array(
'session_token' => $response->Result->header->sessionToken,
'clientStamp' => 0,
),
);
And lot of other tries... but
$response = $soapClient->__call("getAllEventTypes", array($ap_param));
$response is always the same
stdClass Object
(
[Result] => stdClass Object
(
[header] => stdClass Object
(
[errorCode] => NO_SESSION
[minorErrorCode] =>
[sessionToken] =>
[timestamp] => 2013-11-09T08:41:01.015Z
)
[eventTypeItems] =>
[minorErrorCode] =>
[errorCode] => API_ERROR
)
)
Someone here has faced the same problem?
Stupid typo error there...
session_token should be sessionToken
$ap_param = array(
'request' =>
array(
'header' => array(
'sessionToken' => $response->Result->header->sessionToken,
'clientStamp' => 0,
),
),
);
The script below apparently uses the API documented at http://www.hasoffers.com/wiki/Offer:create. S the question has (at least) two parts: a) How to store more than one data set within an array. b) Does the API accept it....
When i run the script it only stores the last value inside 'data' how can i get it to store more data at once?
The code below has for example 2 values. one is caled LOLO and the other one is caled LELE.
The output shows only the value LELE.
this is the code.
<?php
header('Content-type: application/json');
$base = 'http://api.hasoffers.com/Api?';
$params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '....'
,'data' => array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
,'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
);
$url = $base . http_build_query( $params );
$result = file_get_contents( $url );
print_r( json_decode( $result) );
?>
and this is the output
[request] => stdClass Object
(
[Target] => Offer
[Format] => json
[Service] => HasOffers
[Version] => 2
[Method] => create
[NetworkId] => demo
[NetworkToken] => NETU2nzMw8AYS6EGgjFrjGR88GcSiF
[data] => stdClass Object
(
[name] => LELE
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
)
'data' => array(
array (
'name' => 'LOLO',
'description' => 'test',
'offer_url' => 'http://google.nl',
'preview_url' => 'http://google.nl'
'expiration_date' => '08-08-2013'),
array (
'name' => 'LELE',
'description' => 'test',
'offer_url' => 'http://google.nl',
'preview_url' => 'http://google.nl',
'expiration_date' => '08-08-2013'))
,'data' => array( array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
),
array(
,'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
)
You need to add it as a multi dimensional array or else it will overwrite the elements with same key. Please note the array (....) addd inside your array
array( array(
Or you can store it in this way
$data = array();
$data[0] = array('name' => 'LELE'
, 'description' => 'test'
, 'offer_url' => 'http://google.nl'
, 'preview_url' => 'http://google.nl'
, 'expiration_date' => '08-08-2013'
);
$data[1] = array('name' => 'LOLO'
, 'description' => 'test'
, 'offer_url' => 'http://google.nl'
, 'preview_url' => 'http://google.nl'
, 'expiration_date' => '08-08-2013'
);
$params = array(
'Format' => 'json'
, 'Target' => 'Offer'
, 'Method' => 'create'
, 'Service' => 'HasOffers'
, 'Version' => 2
, 'NetworkId' => 'demo'
, 'NetworkToken' => 'NETU2nzMw8AYS6EGgjFrjGR88GcSiF'
, 'data' => $data
);
print_r($params);
// Output
Array
(
[Format] => json
[Target] => Offer
[Method] => create
[Service] => HasOffers
[Version] => 2
[NetworkId] => demo
[NetworkToken] => NETU2nzMw8AYS6EGgjFrjGR88GcSiF
[data] => Array
(
[0] => Array
(
[name] => LELE
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
[1] => Array
(
[name] => LOLO
[description] => test
[offer_url] => http://google.nl
[preview_url] => http://google.nl
[expiration_date] => 08-08-2013
)
)
)
a) How to store more than one data set within an array.
$fixed_params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '....'
);
$offer_data = array(
array(
'name' => 'LOLO'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
),
array(
'name' => 'LELE'
,'description' => 'test'
,'offer_url' => 'http://google.nl'
,'preview_url' => 'http://google.nl'
,'expiration_date' => '08-08-2013'
)
);
// store all results here
$result = array();
// iterates two times since $offer_data has two elements.
foraech ($offer_data as $offern => $data ){
// store offer's data into fixed_params['data'] element.
$fixed_params['data'] = $data;
$url = $base . http_build_query( $fixed_params );
$result[] = json_decode( file_get_contents( $url ));
}
print_r($result);
b) Does the API accept it....
As I understand the API, it accepts only one create at time. See http://www.hasoffers.com/wiki/Offer:create it says: Creates a new offer.
This is what i did and it works
<?php
// Bestand openen
if (($file = fopen("test2.csv", "r")) !== FALSE) {
// Eerste rij van Excel als value gebruiken
$header = fgetcsv($file, 1000, ";");
// Een loop door Excel file
while (($data = fgetcsv($file, 1000, ";")) !== FALSE) {
// combineer de eerste rij met de gegevens
$combined = array_combine($header,$data);
// Connectie maken met Hasoffers bij elke waarden
$base = 'http://api.hasoffers.com/Api?';
$params = array(
'Format' => 'json'
,'Target' => 'Offer'
,'Method' => 'create'
,'Service' => 'HasOffers'
,'Version' => 2
,'NetworkId' => 'demo'
,'NetworkToken' => '.....'
,'data' => $combined
);
$url = $base . http_build_query( $params );
$result = file_get_contents( $url );
// Tijdelijk printen
print_r( json_encode( $result) );
}
}
?>
I've created a loop including a CSV file.
the problem was that it connected only once with hasoffer and that allowed only one value.