How to Access Transaction Array Value from IPN - php

I am trying to parse an IPN callback from paypal. The type of payment is adaptive, so there is an array of transactions (even though I will only have 1).
Here is a sample IPN with some fields pruned for readability:
array (
'payment_request_date' => 'Fri Jan 30 22:28:54 PST 2015',
'verify_sign' => 'removed',
'transaction[0].id_for_sender_txn' => 'removed',
'transaction[0].receiver' => 'removed',
'cancel_url' => '#pruned',
'transaction[0].is_primary_receiver' => 'false',
'pay_key' => '#removed',
'action_type' => 'PAY',
'transaction[0].id' => 'id is here',
'transaction[0].status' => 'Completed',
'transaction[0].paymentType' => 'SERVICE',
)
I am trying to access the value of 'transaction[0].id' and cannot get it to dump. I have tried basically every possible way I can think of:
$id = $_POST['transaction'][0]['id'];
$id = $_POST['transaction[0].id'];
Also tried asking the array to a var and then using that:
$id = $array->transaction[0].id;

This should give you the info you need.

Related

PayPal Orders V2 payee object in Checkout-PHP-SDK fails with amount error

I am integrating PayPal Checkout which works nicely unless I include a custom payee in the order body. I tried the PayPal PHP example at https://developer.paypal.com/docs/checkout/integration-features/custom-payee/ that looks like this:
return array(
'intent' => 'AUTHORIZE',
'purchase_units' =>
array(
0 =>
array(
'amount' =>
array(
'currency_code' => 'USD',
'value' => '220.00'
)
),
array(
'payee' =>
array(
'email_address' => 'payee#email.com'
)
)
)
);
Trying to create an order will lead to this error message (which seems to be completely wrong as it complaints about fields that are neither there nor needed):
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"65a47f1e8defd","details":[{"field":"/purchase_units/1/amount","value":"","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field / parameter is missing."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MISSING_REQUIRED_PARAMETER","rel":"information_link","encType":"application/json"}]} [/var/www/web15/htdocs/retroplace/vendor/paypal/paypalhttp/lib/PayPalHttp/HttpClient.php:215]
If I remove the portion with the payee, everything works fine. But I need the payee in the order...
Do you have PHP errors/warnings enabled? that looks like it might be bad PHP syntax
Try putting:
'payee' =>
array(
'email_address' => 'payee#email.com'
)
Within the array above (second key, in the same array as 'amount')

Add zeros (00) to array

I got this php code. I am new in php and this is a very simple question.
As you can see in the amount, i am getting post from a before page.
My problem is the following
If the user add 300USD then payment provider understand it as 3USD. If user insert 3000USD payment provider understand it 30USD.
I want to add two extra zeros by default. How can I do it?
$params = array(
'site_id' => '231321',
'amount' => $_POST[amount],
'currency' => $_POST[currency],
'site_login' => $current_user->user_email,
'email' => $current_user->user_email,
'external_id' => $externalid ,
);
Are you able to access the $params array before you use it in the following steps? If so, why don't you just modify the content?
$params['amount'] *= 100;
You should check though that the contents really is a number, etc.
You can multiply the amount by 100 to obtain the result.
Example
$amount = $_POST[amount] * 100;
Code
$params = array(
'site_id' => '231321',
'amount' => $_POST[amount] * 100,
'currency' => $_POST[currency],
'site_login' => $current_user->user_email,
'email' => $current_user->user_email,
'external_id' => $externalid ,
);

How do I loop through an object and display its data within an associative array

First of all this is my code:
Log::create([
'action' => $event->changes[0], //<- This is my problem
'object_id' => $event->id,
'object_type' => "Account",
'ip_address' => Request::ip(),
'user' => ucfirst(Auth::user()->name),
'time' => Carbon::now()->format('H:i:s'),
'date' => Carbon::now()->format('Y-m-d')
]);
$event->changes is an array which contains many items but i only know how to get 1 specific item at a time using the index [0] or [1] etc.
How do I get all the values to display instead of 1 at a time? Obviously I don't want to create a new log for each single action but I cant figure out how to do this.
As always any help is appreciated thank you.
You need to serialize the $event->changes if you want it within one log entry.
It actually depends on the structure of changes array, but it seems to be an array of strings, so you may for example use the implode(', ', $changes), so the snippet would look the following:
Log::create([
'action' => implode(', ', $event->changes), //<- This is my problem
'object_id' => $event->id,
'object_type' => "Account",
'ip_address' => Request::ip(),
'user' => ucfirst(Auth::user()->name),
'time' => Carbon::now()->format('H:i:s'),
'date' => Carbon::now()->format('Y-m-d')
]);

Translate value before sending information

is there a away to translate values in php using either google api translate or any other api...
<?php
// 1.- Query to get information
// 2.- build array with that query
// Example array from query
$data = array(
'0' => array (
'name' => 'Zapatos',
'color' => 'Verde'
),
'1' => array (
'name' => 'Casa',
'color' => 'Rosa'
),
);
// Now that the array has been build, lets make a translation
// Which I have no idea how to do that but the final array should be
$final = array(
'0' => array (
'name' => 'Zapatos',
'color' => 'Verde',
'name_en' => 'Shoes',
'color_en' => 'Green'
),
'1' => array (
'name' => 'Casa',
'color' => 'Rosa',
'name_en' => 'House',
'color_en' => 'Pink'
),
);
is this process possible or am I just dreaming?
I have very little knowledge on how exactly Goolge API works since I only use the Google Translate widget and the translation is after you present the information but in this case we need to make a translation before presenting the information...
Google translate API is a paid service. You need to get a api key from google api services :
google translate API
After that, you can make a curl to google api after getting your results from query :
sample url for curl :
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world&q=My%20name%20is%20Jeff
You will get the results as JSON object,do json_decode and add results to your array.

QUICKBASE PHP SDK add_record returns blank response

I was recently brought on by a company that uses Quickbase. They have limited systems in place to talk to the Quickbase application, so I am trying to incorporate the PHP SDK in order to add/edit records in Quickbase using a front end designed by myself so customers can submit a form from the web into Quickbase.
I'm coming across a problem right away trying to get the SDK to even respond with something other than an error. Currently it doesn't respond with anything when trying to add a record.
I keep reading that a recent (~2-3 years ago) change has caused this to be a bit difficult to use.
below is my codesnippet from a php page called "addnewcustomer.php"
include_once('quickbase.php');
//my PHP SDK Options located inside quickbase.php
var $user_name = 'username'; // QuickBase user who will access the QuickBase
var $passwd = 'pw'; // Password of this user
var $db_id = 'dbid'; // Table/Database ID of the QuickBase being accessed
var $app_token = 'my app token';
var $xml = true;
var $user_id = '';
var $qb_site = "www.mycompany.quickbase.com";
var $qb_ssl = "https://www.mycompany.quickbase.com/db/";
var $ticketHours = 12;
$quickbase = new QuickBase('myusername', 'mypw', true, "dbid", "token", "realm", hour);
$fields = array(
array(
'fid' => '148',
'value' => $agentid), //agentid
array(
'fid' => '15',
'value' => $city), //city
array(
'fid' => '16',
'value' => $state), //state
array(
'fid' => '14',
'value' => $address), //address
array(
'fid' => '524',
'value' => $apt), //apt #
array(
'fid' => '17',
'value' => $zip), //zip code
array(
'fid' => '33',
'value' => $rentown), //rent/own
array(
'fid' => '28',
'value' => $first), //first name
array(
'fid' => '29',
'value' => $last), //last name
array(
'fid' => '21',
'value' => $email), //email
array(
'fid' => '18',
'value' => $phone) //phone
);
$quickbase->add_record($fields);
It currently responds with nothing, ie. blank response. If I change the realm with something inaccurate I get an error of "Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML'", which makes me think I have everything setup correctly.
What should a successful entry return? What am I doing wrong?
The add_record method should be returning an XML object. If you capture that object, you can check it to see if the API call was successful or if an error was returned. So, if you change your code to:
$results = $quickbase->add_record($fields);
print_r($results);
You'll get something you can understand. It's inelegant, but it will show you quickly if you're getting a response and if that response is an error. You should see something like this on success:
SimpleXMLElement Object ( [action] => API_AddRecord [errcode] => 0 [errtext] => No error [rid] => 81 [update_id] => 1436476140453 )

Categories