Coinbase api returning mostly empty arrey - php

I am trying to test coinbase api. Api authorized fine but most functions are returning empty arrey, bellow is my code sample
<?php
require_once('vendor/autoload.php');
use Coinbase\Wallet\Resource\Account;
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
use Coinbase\Wallet\Resource\Address;
$apiKey='********';
$apiSecret='********;';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$accounts = $client->getAccounts();
$account = $client->getPrimaryAccount();
$auth = $client->getCurrentAuthorization();
$user = $client->getCurrentUser();
$paymentMethods = $client->getPaymentMethods();
echo "accounts arrey". json_encode($accounts)."<hr/>";//empty arrey
echo "primary account arrey".json_encode($account)." <hr/>";//empty arrey
echo "current auth arrey".json_encode($auth)."<hr/>";//printing data perfectly
echo "current user arrey".json_encode($user)."<hr/>";//empty array
echo "payment methods arrey".json_encode($paymentMethods)."<hr/>";//empty array
?>
All of echo printing empty array except $authbellow is output screenshot

This problem was solved by using $response=$client->decodeLastResponse(); and echo $response

Related

Coinbase API send money transaction hash

I am trying to send payment using coinbase.com wallet API. I found a code on GitHub, using it I successfully sent payment to LTC address. Here's the code:
<?php
include 'vendor/autoload.php';
$apiKey = 'MY_API_HERE';
$apiSecret = 'MY_SECRET_HERE';
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Resource\Transaction;
use Coinbase\Wallet\Value\Money;
$accountId = "MY_LTC_ACCOUNT_ID_HERE";
$account = $client->getAccount($accountId);
$transaction = Transaction::send([
'toBitcoinAddress' => 'PAYMENT_ADDRESS',
'amount' => new Money(AMOUNT_OF_LTC_HERE, CurrencyCode::LTC)
]);
try {
$client->createAccountTransaction($account, $transaction);
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
My included files are here https://darkchannel.info/coinbase/vendor.zip
But I don't know how to get the transaction hash (coin transaction id).
You still have initial transaction as $transaction, so after creating the transaction in the network, you can access the hash using this code $transaction->getNetwork()-> getHash().

Authorize.net web hook Invalid JSON sent in the Webhook notification

I am trying to implement Authorize.net webhook on a Laravel project. From merchant interface, I added a webhook endpoint. But when I try to retrieve events it throws invalid JSON error. What am I doing wrong in the code below?
namespace App\Http\Controllers\Api\Anet;
use Illuminate\Http\Request;
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
use App\Http\Controllers\Controller;
use JohnConde\Authnet\AuthnetWebhook;
class xxxController extends Controller
{
public function webhook(){
$headers = getallheaders();
$payload = file_get_contents("php://input");
$webhook = new AuthnetWebhook(hex2bin('XXXXXD4FF0A6060E23DBCD9AE507E20XXXXX'), $payload, $headers);
if ($webhook->isValid()) {
// Get the transaction ID
$transactionId = $webhook->payload->id;
// Here you can get more information about the transaction
$request = AuthnetApiFactory::getJsonApiHandler('services.authorize.login', 'services.authorize.key');
$response = $request->getTransactionDetailsRequest(array(
'transId' => $transactionId
));
/* You can put these response values in the database or whatever your business logic dictates.
$response->transaction->transactionType
$response->transaction->transactionStatus
$response->transaction->authCode
$response->transaction->AVSResponse
*/
}
}
}
Error:
"message": "Invalid JSON sent in the Webhook notification",
"exception": "JohnConde\\Authnet\\AuthnetInvalidJsonException",
"file": "/var/www/html/staging/vendor/stymiee/authnetjson/src/authnet/AuthnetWebhook.php",
"line": 67,
Your problem is that you are not getting a webhook notification. The code you are using is purposed for validating a webhook notification, rather than making a webhooks request. You have to make a request to get a webhook.
When you set up your endpoint, you can use that code (although I don't think the hex2bin() is required) to validate webhooks and then extract information from them.
To create a webhooks request, you can use code like this-
$webhooksArray = array(' net.authorize.payment.authorization.created','
net.authorize.payment.authcapture.created','
net.authorize.payment.capture.created');
$webhooksUrl = 'https://{yourserver.com}/{your path}/{your endpoint}';
$webhook = new AuthnetAPIFactory();
$handler = $webhook->getWebhooksHandler($login,$transId);
$createWebhooks = $handler->createWebhooks($webhooksArray,$webhooksUrl);
This will enroll you in events, which will automatically be sent to your endpoint
i.e https://{yourserver.com}/{your path}/{your endpoint}.
Then you can use your code above to validate the webhooks when they hit your endpoint. Once you are enrolled in events and webhooks are being sent to your endpoint, you can retrieve the history using code like this-
$webhook = new AuthnetAPIFactory();
$handler = $webhook->getWebhooksHandler($login,$transId);
$history = $handler->getNotificationHistory();
print_r($history);
You can retrieve a specific webhook like this-
$webhook = new AuthnetAPIFactory();
$handler = $webhook->getWebhooksHandler($login,$transId);
$webhook = $handler->getWebhook($webhookId);
Where $webhookId is the id tied to the webhook you wish to retrieve. You can search through the namespace to see the other method calls for specific webhook actions.
I know, the reply to this question is too late. But I recently faced this issue. I resolved it for one of my projects.
The controller method must have the Request $request parameter and the route should be POST not GET.
The Controller:
class AuthnetWebhookController extends Controller
{
public function webhookListener(Request $request)
{
.....
}
// other methods
}
The route:
Route::post('authnet-webhook-listener', 'AuthnetWebhookController#webhookListener');

Unable to fetch any adset Fields from Facebook Ads API (PHP v2.8.1)

I am getting AdAccount fields just fine. But all my attempts to fetch the adsets are failure. I am trying to get insights of all the campaigns running under the adaccount. But firstly I was testing whether I could fetch only the campaign names but it's not working. Some points to be noted.
*I have used id n secret from an app(did nothing for white listing) registered using the same account that has admin access to another ad account(that is the main adAcount against which all ads are created).
*I have used temporary access token generated using graph explorer with ads_read & ads_management permission.
*Get->v2.8->me?fields=adaccounts{campaigns{adsets{name}}} fetching the names perfectly fine on the explorer.
include 'vendor/autoload.php';
use FacebookAds\Api;
Api::init(APP_ID, APP_SECRET, ACCESS_TOKEN);
$api = Api::instance();
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;
use FacebookAds\Object\Fields\AdSetFields;
$fields = array(
AdAccountFields::ID,
AdAccountFields::NAME
);
$account = new AdAccount('act_XXX');
$u=$account->read($fields);
echo $u->name.'<br>';
$adsets = $account->getAdSets(array(
AdSetFields::NAME
));
foreach ($adsets as $adset) {
echo $adset->name;
}
Try This !
use FacebookAds\Api;
Api::init($app_id, $app_secret, $access_token);
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\AdSetFields;
$account = new Campaign($campaign_id);
$objects = $account->getAdSets(array(
AdSetFields::NAME,
AdSetFields::ID,
AdSetFields::STATUS,
));
$objects->setUseImplicitFetch(true); // set this before loop
foreach ($objects as $object) {
if($object->{AdSetFields::STATUS}=='ACTIVE'){
$adset_id= $object->{AdSetFields::ID};
$name= $object->{AdSetFields::NAME};
$status = $object->{AdSetFields::STATUS};
$values[] = array(
'adset_id' => $adset_id,
'name' => $name,
'status' => $status,
);
}
}
echo json_encode($values);

unable to access google spreedsheets values using php

I'm installed
google api for OAuth2 php lib; here: https://code.google.com/p/google-api-php-client/
google spreadsheet api php lib; here: https://github.com/asimlqt/php-google-spreadsheet-client
created the credentials on the API Console using service account https://console.developers.google.com/
Here is the php script I used in combination with the above:
require_once('vendor/autoload.php');
require_once('vendor/composer/autoload_classmap.php');
require_once('vendor/composer/autoload_real.php');
require_once __DIR__.'/vendor/google/apiclient/src/Google/Auth/AssertionCredentials.php';
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
use Google\Spreadsheet\SpreadsheetService;
const G_CLIENT_ID = 'my_client_id';
const G_CLIENT_EMAIL = 'email address';
const G_CLIENT_KEY_PATH = 'key.p12';
const G_CLIENT_KEY_PW = 'notasecret';
$obj_client_auth = new Google_Client ();
$obj_client_auth -> setApplicationName ('newproject');
$obj_client_auth -> setClientId (G_CLIENT_ID);
$obj_client_auth -> setAssertionCredentials (new Google_Auth_AssertionCredentials (
G_CLIENT_EMAIL,
array('https://spreadsheets.google.com/feeds','https://docs.google.com/feeds'),
file_get_contents (G_CLIENT_KEY_PATH),
G_CLIENT_KEY_PW
));
$obj_client_auth -> getAuth () -> refreshTokenWithAssertion ();
$obj_token = json_decode ($obj_client_auth -> getAccessToken ());
$accessToken = $obj_token->access_token;
$serviceRequest = new DefaultServiceRequest($accessToken);
ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle('NewSpreadSheet');
$worksheetFeed = $spreadsheet->getWorksheets();
$worksheet = $worksheetFeed->getByTitle('sssNew Worksheet');
$listFeed = $worksheet->getListFeed();
$row = array('name'=>'John', 'age'=>25);
I receive the following error:
Call to a member function getWorksheets() on a non-object...
I'm not getting how correct it...
Any help n suggestions
I got it... the issue is about i didn't share my spreadsheet... when i shared my spreadsheet with client email then i'm able to insert records into the desired sheets... now i'm able to access every sheet,insert,delete everything...
So, when ever anyone got this problem just share your sheet with your client email.

Aweber authorization code not working

Here is weird problem: when I authorize my Aweber app, the authorization code works the first time.
However when I refresh the page I get an error:
AWeberAPIException:
Type: UnauthorizedError
Msg : RequestToken key is invalid. https://labs.aweber.com/docs/troubleshooting#unauthorized
Docs: https://labs.aweber.com/docs/troubleshooting#unauthorized
Please help this is really frustrating. Here is the code I'm using:
require_once('aweber_api/aweber_api.php');
try {
# set $authorization_code to the code that is given to you from
# https://auth.aweber.com/1.0/oauth/authorize_app/YOUR_APP_ID
$authorization_code="Azh...";
$auth = AWeberAPI::getDataFromAweberID($authorization_code);
list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $auth;
# Store the Consumer key/secret, as well as the AccessToken key/secret
# in your app, these are the credentials you need to access the API.
//$account = $aweber->getAccount($accessKey, $accessSecret);
}
catch(AWeberAPIException $exc) {
print "<h3>AWeberAPIException:</h3>";
print " <li> Type: $exc->type <br>";
print " <li> Msg : $exc->message <br>";
print " <li> Docs: $exc->documentation_url <br>";
print "<hr>";
}
OK, I solved it!
The authorization token contains $consumerKey, $consumetSecret, $accessKey, and $accessSecret
The following line returns an Array
$auth = AWeberAPI::getDataFromAweberID($authorization_code);
So,
$consumerKey = $auth[0];
$consumerSecret = $auth[1];
$accessKey = $auth[2];
$accessSecret = $auth[3];
And then you simply use those values to authorize the application! Of course, if it's used by multiple users you need to store these values for each of them.

Categories