laravel-shopify-API-wrapper: Pass charge to shopify - php

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

Related

Posting data using Guzzle

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'
]
]

PayFort SDK Token: Invalid command

[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.

How to access this array

array (
'_attributes' =>
array (
'name' => 'Rothco Product API - Variations',
),
'item_variations' =>
array (
0 =>
stdclass::__set_state(array(
'item_variation_id' => 2,
'item_index' => 3146,
'rothco_item_no' => '10002',
'upc' => '023063601212',
'inventory' => 99,
'created_date' => '2014-11-28 10:06:45.000',
'weight' => '.4000',
'image_filename' => '10002-A.jpg',
'catalog_page_no' => 183,
'msrp' => '20.9900',
'map' => '.0000',
'diameter' => '',
'price' => '8.100000',
'case_price' => NULL,
'case_quantity' => NULL,
'statuses' => '',
)),
),
)
This is my array $list.
I want to access 'item_variations' value from this array,
but if I try $list['item_variations'], or $list->['item_variations']
it is not working
If you want to reach just item_variations then
echo $list['item_variations'];
is sufficient. Things get more tricky if you would like to i.e. get value if created_date from your sample data as you got mix of arrays and objects so that require different access:
echo $list['item_variations'][0]->created_date;
which would output
2014-11-28 10:06:45.000

Extract value from Stripe object

How do I get the value of 'name'?
I've been trying various methods, including array($charge) and __toArray.
First works, second does not:
$charge_id = $charge->id;
echo $charge_id;
$name=$charge->_values->name;
echo $name;
Here is portion of the object returned by Stripe (up to the name I want to extract):
Stripe\Charge::__set_state(array(
'_opts' =>
Stripe\Util\RequestOptions::__set_state(array(
'headers' =>
array (
),
'apiKey' => 'sk_test_...',
)),
'_values' =>
array (
'id' => 'ch_73JaKii01nmbpZ',
'object' => 'charge',
'created' => 1443251926,
'livemode' => false,
'paid' => true,
'status' => 'succeeded',
'amount' => 1000,
'currency' => 'usd',
'refunded' => false,
'source' =>
Stripe\Card::__set_state(array(
'_opts' =>
Stripe\Util\RequestOptions::__set_state(array(
'headers' =>
array (
),
'apiKey' => 'sk_test_...',
)),
'_values' =>
array (
'id' => 'card_73JZrJCDzl877J',
'object' => 'card',
'last4' => '1111',
'brand' => 'Visa',
'funding' => 'unknown',
'exp_month' => 12,
'exp_year' => 2021,
'fingerprint' => 'hhzQQZIXaAVDNMPP',
'country' => 'US',
'name' => 'Steve Veltkamp',
according to this:
https://github.com/stripe/stripe-php/blob/master/lib/Charge.php
you may try to play with retrieve method:
$charge::retrieve($charge->id);
or ( https://github.com/stripe/stripe-php/blob/master/lib/StripeObject.php ):
$chargeArr = $charge->__toArray(true);
add true as argument for recursion
(Note: you should edit your question to remove your secret key and replace it with e.g. 'sk_test_...'. Even if it's just a test key, secret keys are not meant to be shared.)
The property you're trying to access is the cardholder's name. The source attribute of a charge object is actually a card object:
php > echo get_class($charge);
Stripe\Charge
php > echo get_class($charge->source);
Stripe\Card
So to get the cardholder's name, all you have to do is:
$name = $charge->source->name;
Note that name is an optional attribute for cards, so it's possible that you'll get NULL, an empty string, an email address, etc.

PHP Betfair Free Access API, how to build APIRequestHeader & call any method?

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

Categories