Stripe success page trying to get details from session_id - php

I'm trying to just retrieve the details from a successful transaction from Stripe in php. The official documentation tells me to install and use Slim, something I can't do in my current situation.
So far I've got the following code which throws me a report of some kind, but i don't fully understand what i'm looking at and I'm not sure where to go from here, or even if I'm getting the right information back in the first place!
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require_once('../../stripe/init.php');
$stripe = new \Stripe\StripeClient(
'[my test key]'
);
$stripe->checkout->sessions->retrieve(
$_GET['session_id'],
[]
);
echo "<pre>";
print_r($stripe);
echo "</pre>";
?>
this give me the following:
Stripe\Service\Checkout\SessionService Object
(
[client:protected] => Stripe\StripeClient Object
(
[coreServiceFactory:Stripe\StripeClient:private] => Stripe\Service\CoreServiceFactory Object
(
[client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
*RECURSION*
[services:Stripe\Service\AbstractServiceFactory:private] => Array
(
[checkout] => Stripe\Service\Checkout\CheckoutServiceFactory Object
(
[client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
*RECURSION*
[services:Stripe\Service\AbstractServiceFactory:private] => Array
(
[sessions] => Stripe\Service\Checkout\SessionService Object
*RECURSION*
)
)
)
)
[config:Stripe\BaseStripeClient:private] => Array
(
[api_key] => [my_api_key]
[client_id] =>
[stripe_account] =>
[stripe_version] =>
[api_base] => https://api.stripe.com
[connect_base] => https://connect.stripe.com
[files_base] => https://files.stripe.com
)
[defaultOpts:Stripe\BaseStripeClient:private] => Stripe\Util\RequestOptions Object
(
[apiKey] =>
[headers] => Array
(
[Stripe-Account] =>
[Stripe-Version] =>
)
[apiBase] =>
)
)
[streamingClient:protected] => Stripe\StripeClient Object
(
[coreServiceFactory:Stripe\StripeClient:private] => Stripe\Service\CoreServiceFactory Object
(
[client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
*RECURSION*
[services:Stripe\Service\AbstractServiceFactory:private] => Array
(
[checkout] => Stripe\Service\Checkout\CheckoutServiceFactory Object
(
[client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
*RECURSION*
[services:Stripe\Service\AbstractServiceFactory:private] => Array
(
[sessions] => Stripe\Service\Checkout\SessionService Object
*RECURSION*
)
)
)
)
[config:Stripe\BaseStripeClient:private] => Array
(
[api_key] => [my_api_key]
[client_id] =>
[stripe_account] =>
[stripe_version] =>
[api_base] => https://api.stripe.com
[connect_base] => https://connect.stripe.com
[files_base] => https://files.stripe.com
)
[defaultOpts:Stripe\BaseStripeClient:private] => Stripe\Util\RequestOptions Object
(
[apiKey] =>
[headers] => Array
(
[Stripe-Account] =>
[Stripe-Version] =>
)
[apiBase] =>
)
)
)

I worked it out based on the code I originally had. Here it is so other people don't have to go through the frustration I had:
require_once('../../stripe/init.php');
$stripe = new \Stripe\StripeClient(
'{{my api key}}'
);
$line_items = $stripe->checkout->sessions->retrieve(
$_GET['session_id'],
[]
);
echo "<pre>";
print_r($line_items);
echo "</pre>";
I just needed to put the retrieve into an object, then I can output that object in the form of a json. Or something like that anyway. You'll know what I mean when you try it.

There you go
require 'vendor/autoload.php';
\Stripe\Stripe::setApiKey('sk_test_Your_Test_Key');
$session = \Stripe\Checkout\Session::retrieve($_GET['session_id']);
$customer = \Stripe\Customer::retrieve($session->customer);
print_r($customer);

Related

Unable to get or display received sms using plivo token and auth id in php

I'm working on the PHP script where I want to get and display all message which is received on the plivo number?
I have already tried two different methods which are not working
Please guide how do I get the your_message_uuid which is necessary in Method 1?
Method 1
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("auth id", "auth_token");
$response = $client->messages->get('your_message_uuid');
print_r($response);
Method 2
require 'vendor/autoload.php';
use Plivo\RestClient;
$client = new RestClient("auth id", "auth_token");
$response = $client->messages->list(
[
'limit' => 5,
'offset' => 0,
'subaccount' =>'subaccount_auth_id'
]
);
print_r($response);
// Prints only the message_uuid
print_r($response->getmessageUuid(0));
Result Using Method 1
Plivo\Resources\Message\Message Object ( [client:protected] => Plivo\BaseClient Object ( [timeout:protected] => [httpClientHandler:protected] => Plivo\HttpClients\PlivoGuzzleHttpClient Object ( [guzzleClient:protected] => GuzzleHttp\Client Object ( [config:GuzzleHttp\Client:private] => Array ( [handler] => GuzzleHttp\HandlerStack Object ( [handler:GuzzleHttp\HandlerStack:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttp\Handler\CurlMultiHandler Object ( [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50 ) [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1 [active:GuzzleHttp\Handler\CurlMultiHandler:private] => [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttp\Handler\CurlHandler Object ( [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) [stack:GuzzleHttp\HandlerStack:private] => Array ( [0] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => http_errors ) [1] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => allow_redirects ) [2] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => cookies ) [3] => Array ( [0] => Closure Object ( [parameter] => Array ( [$handler] => ) ) [1] => prepare_body ) ) [cached:GuzzleHttp\HandlerStack:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttp\RedirectMiddleware Object ( [nextHandler:GuzzleHttp\RedirectMiddleware:private] => Closure Object ( [static] => Array ( [handler] => GuzzleHttp\PrepareBodyMiddleware Object ( [nextHandler:GuzzleHttp\PrepareBodyMiddleware:private] => Closure Object ( [static] => Array ( [default] => GuzzleHttp\Handler\CurlMultiHandler Object ( [factory:GuzzleHttp\Handler\CurlMultiHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 50 ) [selectTimeout:GuzzleHttp\Handler\CurlMultiHandler:private] => 1 [active:GuzzleHttp\Handler\CurlMultiHandler:private] => [handles:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [delays:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) [options:GuzzleHttp\Handler\CurlMultiHandler:private] => Array ( ) ) [sync] => GuzzleHttp\Handler\CurlHandler Object ( [factory:GuzzleHttp\Handler\CurlHandler:private] => GuzzleHttp\Handler\CurlFactory Object ( [handles:GuzzleHttp\Handler\CurlFactory:private] => Array ( [0] => Resource id #55 ) [maxHandles:GuzzleHttp\Handler\CurlFactory:private] => 3 ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) ) [parameter] => Array ( [$request] => [$options] => ) ) ) [allow_redirects] => Array ( [max] => 5 [protocols] => Array ( [0] => http [1] => https ) [strict] => [referer] => [track_redirects] => ) [http_errors] => 1 [decode_content] => 1 [verify] => 1 [cookies] => [idn_conversion] => 1 [headers] => Array ( [User-Agent] => GuzzleHttp/6.5.5 curl/7.75.0 PHP/7.2.34 ) ) ) [authId:protected] => [authToken:protected] => ) [basicAuth:protected] => Plivo\Authentication\BasicAuth Object ( [authId:protected] => [authToken:protected] => ) ) [interface:protected] => [id:protected] => [pathParams:protected] => Array ( [authId] => [messageUuid] => ) [properties] => Array ( [from] => [to] => [messageDirection] => [messageState] => [messageTime] => [messageType] => [messageUuid] => [resourceUri] => [totalAmount] => [totalRate] => [units] => ) )
Empty Result Using Method 2
Check out Plivo's use case guide to receiving SMS messages. It explains how to
create a PHP app to read the message content
create a Plivo SMS app and assign the PHP app to it
assign the Plivo SMS app to a Plivo number (that will receive the
incoming SMS messages)
whenever an incoming SMS message is received on that Plivo number, Plivo
will send the details to his app server configured in the Plivo SMS
app (message URL)

Display Part of the output in Browser

Background :
I am calling Soap Url & getting messages in browser based on ShipmentNumber
Case 1 : When i ran code in browsers , For some ShipmentNumber i got below result as output:
stdClass Object
(
[Transaction] => stdClass Object
(
[Reference1] => 10000128254545
[Reference2] =>
[Reference3] =>
[Reference4] =>
[Reference5] =>
)
[Notifications] => stdClass Object
(
)
[HasErrors] => 1
[ProcessedShipmentHolds] => stdClass Object
(
[ProcessedShipmentHold] => stdClass Object
(
[ID] => 42863418581
[HasErrors] => 1
[Notifications] => stdClass Object
(
[Notification] => stdClass Object
(
[Code] => ERR65
[Message] => Hold of the same type already exists
)
)
)
)
)
Case 2 : For some other ShipmentNumber , i got below result :
stdClass Object
(
[Transaction] => stdClass Object
(
[Reference1] => 10000128254545
[Reference2] =>
[Reference3] =>
[Reference4] =>
[Reference5] =>
)
[Notifications] => stdClass Object
(
)
[HasErrors] =>
[ProcessedShipmentHolds] => stdClass Object
(
[ProcessedShipmentHold] => stdClass Object
(
[ID] => 42863421156
[HasErrors] =>
[Notifications] => stdClass Object
(
)
)
)
)
Requirement :
But I want to display only [Message] Value in Browser. Means, in Case 1, i want to display "Hold of the same type already exists" , in Case 2 , i want to display "No Message" in browser....
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$soapClient = new SoapClient('https://ws.aramex.net/ShippingAPI.V2/Shipping/Service_1_0.svc?wsdl');
$params = array(
'ClientInfo' => array('AccountNumber' => 'IN',
'Version' => 'v1.0'
),
'Transaction' => array(
'Reference1' => '',
'Reference5' => ''
),
'ShipmentHolds'=> array(
'ShipmentHoldDetails' => array(
'ShipmentNumber' =>'42863421156',
'Comment' =>'test Order'
)
)
);
try {
$auth_call = $soapClient->HoldShipments($params);
echo '<pre>';
print_r($auth_call);
die();
} catch (SoapFault $fault) {
die('Error : ' . $fault->faultstring);
}
?>
try this code. You need to access the right field to display the message.
your message is in:
$auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message
But based on your second question sometimes you don't have it there so go for something like:
if(isset($auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message)){
echo $auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message;
}
else{
echo "No Message";
}
You can make it more "elegant" and use ternary operators like
isset($auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message)?$Message=$auth_call->ProcessedShipmentHolds->ProcessedShipmentHold->Notifications->Notification->Message:$Message='No Message';
echo $Message;

Converting an nested xAPI JSON output into PHP Array

Array
(
[0] => TinCan\Statement Object
(
[id:protected] => 0a53e06c-64a7-4902-930e-993bb228cd49
[stored:protected] => 2018-02-24T04:21:22.456Z
[authority:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => sabarish
[mbox:protected] =>
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] => TinCan\AgentAccount Object
(
[name:protected] => 248a06f20aa62f
[homePage:protected] => https://sandbox.watershedlrs.com
)
)
[version:protected] => 1.0.0
[attachments:protected] => Array
(
)
[actor:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => Akshaya Manikandan
[mbox:protected] => mailto:aksh.m14#gmail.com
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
[verb:protected] => TinCan\Verb Object
(
[id:protected] => http://adlnet.gov/expapi/verbs/skipped
[display:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
[en] => skipped
)
)
)
[target:protected] => TinCan\Activity Object
(
[objectType:TinCan\Activity:private] => Activity
[id:protected] => https://app.acuizen.com/populate_form/965/1573/4690
[definition:protected] =>
)
[result:protected] =>
[context:protected] => TinCan\Context Object
(
[registration:protected] =>
[instructor:protected] =>
[team:protected] =>
[contextActivities:protected] => TinCan\ContextActivities Object
(
[category:protected] => Array
(
[0] => TinCan\Activity Object
(
[objectType:TinCan\Activity:private] => Activity
[id:protected] => http://acuizen.com/ActivitySkipped
[definition:protected] => TinCan\ActivityDefinition Object
(
[type:protected] => http://id.tincanapi.com/activitytype/Assignment
[name:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
)
)
[description:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
)
)
[moreInfo:protected] =>
[extensions:protected] => TinCan\Extensions Object
(
[_map:protected] => Array
(
)
)
[interactionType:protected] =>
[correctResponsesPattern:protected] =>
[choices:protected] =>
[scale:protected] =>
[source:protected] =>
[target:protected] =>
[steps:protected] =>
)
)
)
[parent:protected] => Array
(
)
[grouping:protected] => Array
(
)
[other:protected] => Array
(
)
)
[revision:protected] =>
[platform:protected] =>
[language:protected] =>
[statement:protected] =>
[extensions:protected] => TinCan\Extensions Object
(
[_map:protected] => Array
(
)
)
)
[timestamp:protected] => 2018-02-24T04:21:22.456Z
)
...
+ 100 more like these.
I get this output after running my php code to retrive all information from the LRS. How to change this into PHP ARRAY?
You need to learn how to use their API documentation, There is no simple "get all the data" that I can see because everything is wrapped in a class with private/protected properties....
Using your provided sample, here is an example of how to "get the actors"
$Statements = getAllActivity()->content->getStatements();
foreach( $Statements as $Statement )
{
print_r( $Statement->getActor() );
print_r( $Statement->getActor()->getName() );
print_r( $Statement->getActor()->getMbox() );
}
Review the script \src\StatementBase.php, this is where I found the getAcator() method
Without your php code I can only assume you are using json_decode($response) instead of json_decode($response, true). Second parameter in this function decides whether to decode into a class as you have or simple array.

HubSpot api json decode

I am trying to parse some data out of the Hubspot API response. The response looks like this json_decoded:
stdClass Object(
[addedAt] => 1411052909604
[vid] => 24
[canonical-vid] => 24
[merged-vids] => Array
(
)
[portal-id] => XXXXX
[is-contact] => 1
[profile-token] => AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[profile-url] => https://app.hubspot.com/contacts/XXXXX/lists/public/contact/_AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[properties] => stdClass Object
(
[lastname] => stdClass Object
(
[value] => testtt
)
[firstname] => stdClass Object
(
[value] => test
)
[lastmodifieddate] => stdClass Object
(
[value] => 1411052906670
)
)
[form-submissions] => Array
(
[0] => stdClass Object
(
[conversion-id] => 85d24dd2-9ee9-4d47-b8f3-3035acbd8f3b
[timestamp] => 1411052834097
[form-id] => fb16efd9-23cc-4511-889c-204fc8b41dba
[portal-id] => 401824
[page-url] => http://wbl-1.hs-sites.com/test
[canonical-url] => http://wbl-1.hs-sites.com/test
[content-type] => landing-page
[page-title] => test
[page-id] => 1570433242
[title] => Default Form (Sample)
[first-visit-url] => http://wbl-1.hs-sites.com/test
[first-visit-timestamp] => 1411052722970
[meta-data] => Array
(
)
)
)
[list-memberships] => Array
(
)
[identity-profiles] => Array
(
[0] => stdClass Object
(
[vid] => 24
[identities] => Array
(
[0] => stdClass Object
(
[type] => EMAIL
[value] => test#user.com
[timestamp] => 1411052834097
)
[1] => stdClass Object
(
[type] => LEAD_GUID
[value] => 0b6acf21-6cee-4c7b-b664-e65c11ee2d8e
[timestamp] => 1411052834201
)
)
)
)
[merge-audits] => Array
(
)
)
I'm looking specifically to try to dig out an email inside the indentities-profile area.
I've tried to do the following:
echo $results->contacts[0]->identity-profiles;
But it just gives me a value of 0
Then I try to go further into the array by doing:
echo $results->contacts[0]->identity-profiles[0];
But at that point - I get a parse error:
Parse error: syntax error, unexpected '['
What am I doing wrong? And how can I dig all the way down to
identity-profiles[0]->identities->[0]->value
which should equal: test#user.com
What am I missing?
As mentioned in the comment I would suggest to decode the JSON to an associative array by passing true as second parameter to json_decode. Example: json_decode($data, true) Than you could access your identity profiles by:
$results['contacts'][0]['identitiy-profiles']
If you still want to get the results as an object you have to access the properties the following way because they contain a -:
$results->contacts[0]->{'identity-profiles'}

Extracting data from this object/array? How to do it

Here is a snippet of the print off of $wp_scripts
WP_Scripts Object
(
[base_url] => http://*****
[content_url] => http://*****
[default_version] => 3.5.1
[in_footer] => Array
(
)
[concat] =>
[concat_version] =>
[do_concat] =>
[print_html] =>
[print_code] =>
[ext_handles] =>
[ext_version] =>
[default_dirs] => Array
(
[0] => /wp-admin/js/
[1] => /wp-includes/js/
)
[registered] => Array
(
[utils] => _WP_Dependency Object
(
[handle] => utils
[src] => /wp-includes/js/utils.min.js
[deps] => Array
(
)
How would i Extract some data, for example "/wp-includes/js/utils.min.js"??
Thanks
$wp_scripts->registered['utils']->src
Accessing object properties via ->
Accessing array elements via [/* String or integer here*/]
$object = new WP_Scripts;
$src = $object->registered['utils']->src;

Categories