How to get VerificationStatus from a PHP object? - php

How can I obtain the VerificationStatus from this PHP object?
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[VerificationAttributes] => Array
(
[user#gmail.com] => Array
(
[VerificationStatus] => Success
)
)
[ResponseMetadata] => Array
(
[RequestId] => csdgdf62-fdsg-dfgdf-23-bf91f933ab69
)
)
)

I discovered the answer in Amazon SES docs:
When the data is accessed with:
$result = $client->getIdentityVerificationAttributes(array(
// Identities is required
'Identities' => array($email)
));
you can access VerificationStatus at:
$result['VerificationAttributes'][$email]['VerificationStatus']
and therefore check it with:
if($result['VerificationAttributes'][$email]['VerificationStatus']=='Success'){
// verification status was successful
}

Related

Stripe Retrieve PaymentIntents API. How to work with the output?

I am trying to use the Stripe API to retrieve the details of a payment. The below code is what I have copied from their docs.
require './vendor/autoload.php';
$stripe = new \Stripe\StripeClient('SECRET_KEY');
$stripe->paymentIntents->retrieve('pi_1234ABC', []);
I then simply print the output using print_r($stripe);.
When I run this is outputs the following object. Needless to say, this isn't what I was expecting and I can't find any other way of dealing with the output.
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
(
[paymentIntents] => Stripe\Service\PaymentIntentService Object
(
[client:protected] => Stripe\StripeClient Object
*RECURSION*
)
)
)
[config:Stripe\BaseStripeClient:private] => Array
(
[api_key] => SECRET_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] =>
)
)
You need to assign the result of the retrieve operation to a variable. Something like this:
$paymentIntent = $stripe->paymentIntents->retrieve('pi_1234ABC', []);
Then you can do things like this:
echo $paymentIntent->status;
echo PHP_EOL;
echo $paymentIntent;
That will echo the status of the Payment Intent, then a new line, then the entire Payment Intent.

Get sold items from Ebay SDK Selling - getting "Missing required input element" Error

I cant create a tag for EbaySDK, so Ebay API may be misleading. The SDK reference is below.
Why do some requests require "input" and where can they be found? The SDK notes don't seem clear on whats required per "call type".
Following the examples from http://devbay.net/sdk/guides/getting-started/basic-usage.html#working-with-responses I'm attempting to get a list of sold items. Since Ebay only keeps 90 days data, I've put no restrictions on my request.
Their example request is:
// Create the API request object.
$request = new Types\FindItemsByKeywordsRequest();
// Assign the keywords.
$request->keywords = 'Harry Potter';
// Output the response from the API.
if ($response->ack !== 'Success') {
foreach ($response->errorMessage->error as $error) {
printf("Error: %s\n", $error->message);
}
} else {
foreach ($response->searchResult->item as $item) {
printf("(%s) %s:%.2f\n", $item->itemId, $item->title, $item->sellingStatus->currentPrice->value);
}
}
mine is a bit more simple (and apparently incomplete)
$request = new Types\GetItemStatusRequestType;
$response = $service->getItemStatus();
if ($response->Ack !== 'Success') {
if (isset($response->Errors)) {
foreach ($response->Errors as $error) {
printf("Error: %s\n", $error->ShortMessage);
}
}
} else {
print_r($response->getItemStatus); //should return all avail values (works with other types of requests)
}
Here is the nasty error
DTS\eBaySDK\Shopping\Types\GetItemStatusResponseType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[Timestamp] => DateTime Object
(
[date] => 2016-03-23 00:28:28.391000
[timezone_type] => 2
[timezone] => Z
)
[Ack] => Failure
[Errors] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Shopping\Types\ErrorType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ShortMessage] => Missing required input element.
[LongMessage] => Required input element is missing from the request.
[ErrorCode] => 1.19
[SeverityCode] => Error
[ErrorParameters] => DTS\eBaySDK\Types\UnboundType Object
(
[data:DTS\eBaySDK\Types\UnboundType:private] => Array
(
[0] => DTS\eBaySDK\Shopping\Types\ErrorParameterType Object
(
[values:DTS\eBaySDK\Types\BaseType:private] => Array
(
[ParamID] => 0
[Value] => ItemID
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorType
[property:DTS\eBaySDK\Types\UnboundType:private] => ErrorParameters
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorParameterType
)
[ErrorClassification] => RequestError
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
)
[position:DTS\eBaySDK\Types\UnboundType:private] => 0
[class:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\GetItemStatusResponseType
[property:DTS\eBaySDK\Types\UnboundType:private] => Errors
[expectedType:DTS\eBaySDK\Types\UnboundType:private] => DTS\eBaySDK\Shopping\Types\ErrorType
)
[Build] => E949_CORE_APILW_17769283_R1
[Version] => 949
)
[attachment:DTS\eBaySDK\Types\BaseType:private] => Array
(
[data] =>
[mimeType] =>
)
)
Error: Missing required input element.
It seems I'm not asking the request for something, but I have no idea.
The GetItemStatus call requires you provide an ItemID. See the following API reference: GetItemStatus
You state you are looking for a sales history. I don't believe this is the call you should be using. This is a function call that appears to be in the shopping API, which is more of a product search tool.
You probably want to be using 'GetOrders' API call if you are looking to get a particular accounts sales history. See the following: GetOrders

Codeception check several elements with same locator

I have several elements on my page with same locator.
Example:
<div.test-info><a>Test1</a></div>
<div.test-info><a>Test2</a></div>
<div.test-info><a>Test3</a></div>
<div.test-info><a>Test4</a></div>
There maybe 20 or more elements on the page.
In python, I tested this with FOR loop, which run through array of elements, grabbed by 'findElemenets' method.
My problem is that i don't know how to do this with Codeception.
I found method '_findElements' but it returns Facebook\WebDriver\Remote\RemoteWebElement instances.
Like :
Array
(
[0] => Facebook\WebDriver\Remote\RemoteWebElement Object
(
[executor:protected] => Facebook\WebDriver\Remote\RemoteExecuteMethod Object
(
[driver:Facebook\WebDriver\Remote\RemoteExecuteMethod:private] => Facebook\WebDriver\Remote\RemoteWebDriver Object
(
[executor:protected] => Facebook\WebDriver\Remote\HttpCommandExecutor Object
(
[url:protected] => http://127.0.0.1:4444/wd/hub
[curl:protected] => Resource id #326
)
[sessionID:protected] => 109595b5-f094-4824-ac10-fc7d6353b799
[mouse:protected] =>
[keyboard:protected] =>
[touch:protected] =>
[executeMethod:protected] => Facebook\WebDriver\Remote\RemoteExecuteMethod Object
*RECURSION*
)
)
[id:protected] => 0
[fileDetector:protected] => Facebook\WebDriver\Remote\UselessFileDetector Object
(
)
)
[1] => Facebook\WebDriver\Remote\RemoteWebElement Object
(
[executor:protected] => Facebook\WebDriver\Remote\RemoteExecuteMethod Object
(
[driver:Facebook\WebDriver\Remote\RemoteExecuteMethod:private] => Facebook\WebDriver\Remote\RemoteWebDriver Object
(
[executor:protected] => Facebook\WebDriver\Remote\HttpCommandExecutor Object
(
[url:protected] => http://127.0.0.1:4444/wd/hub
[curl:protected] => Resource id #326
)
[sessionID:protected] => 109595b5-f094-4824-ac10-fc7d6353b799
[mouse:protected] =>
[keyboard:protected] =>
[touch:protected] =>
[executeMethod:protected] => Facebook\WebDriver\Remote\RemoteExecuteMethod Object
*RECURSION*
)
)
[id:protected] => 1
[fileDetector:protected] => Facebook\WebDriver\Remote\UselessFileDetector Object
(
)
)
)
How can I operate with this data, or is there another good way to resolve my problem ?
If you want to get content of divs, use grabMultiple method, it returns array of strings.
$I->grabMultiple('div.test-info a')
$elements = $I->_findElements('div.test-info a');
foreach($elements as $element)
{
*do some testing* for example $element->click();
}
the methods you can use for the RemoteWebElement, see http://facebook.github.io/php-webdriver/classes/RemoteWebElement.html
Here is working solution:
$allLinks = $I->grabMultiple('.readmore'); //grab all clickable links
for( $i = 0; $i<sizeof($allLinks); $i++ ) { //iterate through a loop
$I->click($allLinks[$i]); //click each link
}

UNKNOWN_ENVELOPE_RECIPIENT error

I'm getting this error when trying to do embedded signing, but I have no clue where to follow as I'm re-using the data from the previous calls. The calls I'm doing are the following, with data and responses:
--------------------------------------add envelope data sent--------------------------------------
POST https://demo.docusign.net/restapi/v2/accounts/467376/envelopes
{"accountId":"467376","templateId":"54E1223E-BE28-4216-B692-EB5D229063C0","templateRoles":[{"email":"natxo+1395913609#kodify.io","name":"natxo1395913609","roleName":"Signer1","clientUserId":1395913609}],"status":"sent","messageLock":true,"ActivateEnvelope":true}
--------------------------------------add envelope response--------------------------------------
Array
(
[envelopeId] => 60683ae6-4934-4613-a7ff-5caf6e9145ec
[uri] => /envelopes/60683ae6-4934-4613-a7ff-5caf6e9145ec
[statusDateTime] => 2014-03-27T09:46:55.8047277Z
[status] => sent
)
--------------------------------------get envelope recipients call--------------------------------------
GET https://demo.docusign.net/restapi/v2/accounts/467376/envelopes/60683ae6-4934-4613-a7ff-5caf6e9145ec/recipients
--------------------------------------get envelope recipients data response--------------------------------------
Array
(
[signers] => Array
(
[0] => Array
(
[name] => natxo1395913609
[email] => natxo+1395913609#kodify.io
[recipientId] => 1
[recipientIdGuid] => 68e46f96-a745-493f-b160-7c3882e7081d
[requireIdLookup] => false
[userId] => 4d33efb3-4f6e-4d8a-ae42-8c4af58c2230
[clientUserId] => 1395913609
[routingOrder] => 1
[note] =>
[roleName] => Signer1
[status] => sent
[templateLocked] => false
[templateRequired] => false
)
)
[agents] => Array
(
)
[editors] => Array
(
)
[intermediaries] => Array
(
)
[carbonCopies] => Array
(
)
[certifiedDeliveries] => Array
(
)
[inPersonSigners] => Array
(
)
[recipientCount] => 1
[currentRoutingOrder] => 1
)
--------------------------------------get recipients view data--------------------------------------
POST https://demo.docusign.net/restapi/v2/accounts/467376/envelopes/54E1223E-BE28-4216-B692-EB5D229063C0/views/recipient
{"returnUrl":"http:\/\/www.fux.com","authenticationMethod":"None","email":"natxo+1395913609#kodify.io","userName":"natxo1395913609","clientUserId":"1395913609"}
--------------------------------------get recipients view response--------------------------------------
Looks like you're using the TemplateID in your POST Recipient View request URL:
POST https://demo.docusign.net/restapi/v2/accounts/467376/envelopes/54E1223E-BE28-4216-B692-EB5D229063C0/views/recipient
You should be using the EnvelopeID instead:
POST https://demo.docusign.net/restapi/v2/accounts/467376/envelopes/60683ae6-4934-4613-a7ff-5caf6e9145ec/views/recipient
I'd also recommend changing the value of the returnUrl property and the authenticationMethod property in the POST Recipient View request, so that the full request looks like this:
POST https://demo.docusign.net/restapi/v2/accounts/467376/envelopes/60683ae6-4934-4613-a7ff-5caf6e9145ec/views/recipient
{
"returnUrl":"http://www.fux.com",
"authenticationMethod":"Email",
"email":"natxo+1395913609#kodify.io",
"userName":"natxo1395913609",
"clientUserId":"1395913609"
}

Convert Stripe API response to JSON using stripe-php library

I'm accessing customer data from the Stripe API, which I'd like to convert to JSON. Usually I'd convert an object to an array and use json_encode() but I don't seem able to in this case, even when trying to access the nested arrays.
This is the response I'm trying to convert to json:
Stripe_Customer Object
(
[_apiKey:protected] => MY_KEY_IS_HERE
[_values:protected] => Array
(
[id] => cus_2dVcTSc6ZtHQcv
[object] => customer
[created] => 1380101320
[livemode] =>
[description] => Bristol : John Doe
[email] => someone6#gmail.com
[delinquent] =>
[metadata] => Array
(
)
[subscription] =>
[discount] =>
[account_balance] => 0
[cards] => Stripe_List Object
(
[_apiKey:protected] => MY_KEY_IS_HERE
[_values:protected] => Array
(
[object] => list
[count] => 1
[url] => /v1/customers/cus_2dVcTSc6ZtHQcv/cards
[data] => Array
(
[0] => Stripe_Object Object
(
[_apiKey:protected] => MY_KEY_IS_HERE
[_values:protected] => Array
(
[id] => card_2dVcLabLlKkOys
[object] => card
[last4] => 4242
[type] => Visa
[exp_month] => 5
[exp_year] => 2014
[fingerprint] => NzDd6OkHnfElGUif
[customer] => cus_2dVcTSc6ZtHQcv
[country] => US
[name] => John Doe
[address_line1] =>
[address_line2] =>
[address_city] =>
[address_state] =>
[address_zip] =>
[address_country] =>
[cvc_check] => pass
[address_line1_check] =>
[address_zip_check] =>
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
)
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
[default_card] => card_2dVcLabLlKkOys
)
[_unsavedValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_transientValues:protected] => Stripe_Util_Set Object
(
[_elts:Stripe_Util_Set:private] => Array
(
)
)
[_retrieveOptions:protected] => Array
(
)
)
Any help greatly appreciated!
PHP has reserved all method names with a double underscore prefix for future use. See https://www.php.net/manual/en/language.oop5.magic.php
Currently, in the latest php-stripe library, you can convert the Stripe Object to JSON by simpl calling **->toJSON().
[PREVIOUSLY]
All objects created by the Stripe PHP API library can be converted to JSON with their __toJSON() methods.
Stripe::setApiKey("sk_xxxxxxxxxxxxxxxxxxxxxxxxx");
$customer = Stripe_Customer::create(array(
"card" => $token,
"plan" => $plan,
));
$customer_json = $customer->__toJSON();
There is also a __toArray($recursive=false) method. Remember to set true as argument otherwise you will get an array filled with stripe objects.
Stripe::setApiKey("sk_xxxxxxxxxxxxxxxxxxxxxxxxx");
$customer = Stripe_Customer::create(array(
"card" => $token,
"plan" => $plan,
));
$customer_array = $customer->__toArray(true);
The attributes of Stripe_Objects can be accessed like this:
$customer->attribute;
So to get the customer's card's last4, you can do this:
$customer->default_card->last4;
However, you'll need to make sure you have the default_card attribute populated. You can retrieve the default_card object at the same time as the rest of the customer by passing the expand argument:
$customer = Stripe_Customer::retrieve(array(
"id" => "cus_2dVcTSc6ZtHQcv",
"expand" => array("default_card")
));
On the latest version, You can use echo $customer->toJSON(); to get the output as JSON.
I have done this way
`Stripe::setApiKey("sk_xxxxxxxxxxxxxxxxxxxxxxxxx");
$stripe_response= Stripe_Customer::create(array(
"card" => $token,
"plan" => $plan,
));
//Encoding stripe response to json
$resposnse_json_ecoded= json_encode($stripe_response);
//decoding ecoded respose
$response_decoded = json_decode($resposnse_json_ecoded, true);
//get data in first level
$account_id=$response_decoded['id'];
$individual = $response_decoded['individual'];
//get data in second level
$person_id=$individual['id'];`
If, like me, you arrived here looking for the python 2.7 solution, simply cast the stripe_object to str(). This triggers the object's inner __str__() function which converts the object into a JSON string.
E.g.
charge = stripe.Charge....
print str(charge)
Your top level object contains other object instances - the cast to (array) affects only the top level element. You might need to recursively walk down - but I'd do it differently here given that the classes are serializable:
$transfer = serialize($myobject);
What are you going to do with the otherwise JSONified data?
If you're going to transfer an object without the class information you might try to use Reflection:
abstract class Object {
/**
* initialize an object from matching properties of another object
*/
protected function cloneInstance($obj) {
if (is_object($obj)) {
$srfl = new ReflectionObject($obj);
$drfl = new ReflectionObject($this);
$sprops = $srfl->getProperties();
foreach ($sprops as $sprop) {
$sprop->setAccessible(true);
$name = $sprop->getName();
if ($drfl->hasProperty($name)) {
$value = $sprop->getValue($obj);
$propDest = $drfl->getProperty($name);
$propDest->setAccessible(true);
$propDest->setValue($this,$value);
}
}
}
else
Log::error('Request to clone instance %s failed - parameter is not an object', array(get_class($this)));
return $this;
}
public function stdClass() {
$trg = (object)array();
$srfl = new ReflectionObject($this);
$sprops = $srfl->getProperties();
foreach ($sprops as $sprop) {
if (!$sprop->isStatic()) {
$sprop->setAccessible(true);
$name = $sprop->getName();
$value = $sprop->getValue($this);
$trg->$name = $value;
}
}
return $trg;
}
}
This is the base class of most of my transferrable classes. It creates a stdClass object from a class, or initializes a class from a stdClass object. You might easily adopt this to your own needs (e.g. create an array).
This is already in a JSON format so you do need to convert it again into json_encode()
just pass it into your script

Categories