Why do I get NULL response when I request AuthToken? - php

I'm building bigcommerce APP. But I cannot get "AuthToken". Please help. See full code below. Also attached image with NULL response.
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php');
use Bigcommerce\Api\Client as Bigcommerce;
$object = new \stdClass();
$object->client_id = BC_CLIENT_ID;
$object->client_secret = BC_CLIENT_SECRET;
$object->redirect_uri = 'https://yourwebsiteurl.com/oauth.php';
$object->code = $_GET['code'];
$object->context = $_GET['context'];
$object->scope = $_GET['scope'];
$authTokenResponse = Bigcommerce::getAuthToken($object);

Related

Paytm php sdk integration PaymentDetailBuilder Class not found

Fatal error: Uncaught Error: Class 'PaymentDetailBuilder' not found
initial code is like this:
require_once('vendor/autoload.php');
use paytmpg\merchant\models\PaymentDetail\PaymentDetailBuilder;
use paytmpg\merchant\models\PaymentStatusDetail\PaymentStatusDetailBuilder;
use paytmpg\merchant\models\RefundDetail\RefundDetailBuilder;
use paytmpg\merchant\models\RefundStatusDetail\RefundStatusDetailBuilder;
// For Staging
$environment = LibraryConstants::STAGING_ENVIRONMENT;
// For Production
// $environment = LibraryConstants::PRODUCTION_ENVIRONMENT;
// Find your mid, key, website in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys
$mid = MERCHANT_MID;
$key = MERCHANT_KEY;
$website = MERCHANT_WEBSITE;
$client_id = MERCHANT_CLIENT_ID;
$callbackUrl = MERCHANT_CALLBACK_URL;
MerchantProperties::setCallbackUrl($callbackUrl);
MerchantProperties::initialize($environment, $mid, $key, $client_id, $website);
// If you want to add log file to your project, use below code
// Config::$monologName = '[PAYTM]';
// Config::$monologLevel = MonologLogger::INFO;
// Config::$monologLogfile = 'file.log';
$channelId = EChannelId::WEB;
$orderId = "ORDER_ID".rand(0,99); // post order id
$txnAmount = Money::constructWithCurrencyAndValue(EnumCurrency::INR, "11.00"); // post amount to be paid
$userInfo = new UserInfo("CUSTID_002");
$userInfo->setAddress("CUSTOMER_ADDRESS");
$userInfo->setEmail("CUSTOMER_EMAIL_ID");
$userInfo->setFirstName("CUSTOMER_FIRST_NAME");
$userInfo->setLastName("CUSTOMER_LAST_NAME");
$userInfo->setMobile("CUSTOMER_MOBILE_NO");
$userInfo->setPincode("CUSTOMER_PINCODE");
$paymentDetailBuilder = new PaymentDetailBuilder($channelId, $orderId, $txnAmount, $userInfo);
$paymentDetail = $paymentDetailBuilder->build();
$response = Payment::createTxnToken($paymentDetail);
print_r($response);
I have copied from => https://developer.paytm.com/docs/server-sdk/php/?ref=serverSdk#SDKCode;

Strava Api issue

I'm using this composer package https://github.com/basvandorst/StravaPHP
The OAUTH is working fine and its generating me the JSON with the access token and user id, etc..
But whenever I try to use other function it returns me 404 not found.
Output is this :
{"token_type":"Bearer","access_token":"077058e0c800881c72a4b10a04a520d5898d4e3e","athlete":{"id":35670467,"username":"amir_do","resource_state":2,"firstname":"Amir","lastname":"Do","city":null,"state":null,"country":null,"sex":"M","premium":false,"summit":false,"created_at":"2018-10-13T13:55:41Z","updated_at":"2018-10-13T13:56:25Z","badge_type_id":0,"profile_medium":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","profile":"https://lh5.googleusercontent.com/-ku6v9lKNgYY/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbASj8KhClhwnVYVqRrEG2oiYzWPbA/mo/photo.jpg","friend":null,"follower":null,"email":"goncalomaia97#gmail.com"}}
35670467
Client error: `GET https://www.strava.com/api/athletes/35670467/stats?access_token=077058e0c800881c72a4b10a04a520d5898d4e3e` resulted in a `404 Not Found` response: {"message":"Record Not Found","errors":[{"resource":"resource","field":"path","code":"invalid"}]}
And this is my current callback.php page code:
<?php
include 'vendor/autoload.php';
use Strava\API\Client;
use Strava\API\Exception;
use Strava\API\Service\REST;
session_start();
$client = new GuzzleHttp\Client();
global $connect;
require_once("configs/database.php");
$connect = new mysqli($config['database']['host'],$config['database']['user'],$config['database']['pass'],$config['database']['db']);
$code = $_GET['code'];
$state = $_GET['state'];
$scope = $_GET['scope'];
$user = $_SESSION['username'];
$check = $connect->query("SELECT * FROM users WHERE email = '$user'");
$fetch = $check->fetch_array(MYSQLI_ASSOC);
$apix = $fetch['api'];
$api_secretx = $fetch['api_secret'];
$client = new GuzzleHttp\Client();
$data = [
"client_id" => $apix,
"client_secret" => $api_secretx,
"code" => $code
];
$result = $client->post('https://www.strava.com/oauth/token', ['json' => $data]);
print "<pre>";
print_r( $result->getBody()->getContents() );
print "</pre>";
$bodyb = $result->getBody();
$varx = json_decode((string) $bodyb, true);
$token = $varx['access_token'];
$id = $varx['athlete']['id'];
$_SESSION['token'] = $token;
printf($id);
try {
// REST adapter (We use `Guzzle` in this project)
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
// Service to use (Service\Stub is also available for test purposes)
$service = new \Strava\API\Service\REST($token, $adapter);
// Receive the athlete!
$client = new Client($service);
$athlete = $client->getAthleteStats($id);
print_r($athlete);
} catch(Exception $e) {
print $e->getMessage();
}
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']);
Change that to this (It should be trailing) :
$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3/']);

Guzzle Sends HTTP request to Google API, server 500 error

I use Guzzle to send HTTP request to Gmail API.
This part keeps causing a server 500 error, why is that ?
$data = new stdClass;
$data-> 'topicName' ='projects/sample.com:sample/topics/topic';
$data-> 'labelIds' = ["INBOX"];
$data-> 'labelFilterAction' = 'include';
Full code:
require_once __DIR__.'/vendor/autoload.php';
$client = new Google_Client();
$client->setScopes("https://www.googleapis.com/auth/gmail.readonly");
putenv('GOOGLE_APPLICATION_CREDENTIALS=sample.json');
$client->useApplicationDefaultCredentials();
// returns a Guzzle HTTP Client
$httpClient = $client->authorize();
$data = new stdClass;
$data->'topicName' ='projects/sample.com:sample/topics/topic';
$data-> 'labelIds' = ["INBOX"];
$data-> 'labelFilterAction' = 'include';
$request = new GuzzleHttp\Psr7\Request('POST', 'https://www.googleapis.com/gmail/v1/users/post#sample.com/watch',['Content-type'=>'application/json'],$data);
$response = $httpClient->send($request);
var_dump($response);
You should not have single quotes around you $data object's properties.
It should be:
$data->topicName ='projects/sample.com:sample/topics/topic';
$data->labelIds = ["INBOX"];
$data->labelFilterAction = 'include';

PHP consume a .net service

So i have the following web service that is found on
http://screencast.com/t/y8qM8hRDu
These are my trials and results:
Try 1:
$api_target = "http://www.xyz.co/service1.svc?wsdl"
$soap_options["location"] = $api_target;
$soap_options['trace'] = TRUE;
$soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
$soap_options['style'] = SOAP_RPC;
$soap_options['use'] = SOAP_ENCODED;
$soap_options['soap_version'] = SOAP_1_2;
$client = new SoapClient($api_target,$soap_options);
$result = $client->Login(array("parameters" => $user));
Response 1:
The SOAP action specified on the message, '', does not match the HTTP SOAP Action, 'http://tempuri.org/IService1/Login'.
Try 2: added SOAPaction header
$actionHeader = new SoapHeader($api_target,'SOAPAction','http://tempuri.org/IService1/Login');
$client->__setSoapHeaders($actionHeader);
$client = new SoapClient($api_target,$soap_options);
$result = $client->Login(array("parameters" => $user));
Response 2::
Bad Request
What am i doing wrong here?
By some unexplained miracle i got it working, if it helps anyone here is the revises code
$api_target = "http://www.xyz.co/service1.svc";
$api_url = $api_target."?wsdl";
$action = "http://tempuri.org/IService1/Login";
$soap_options["location"] = $api_target;
$soap_options["uri"] = $api_url;
$soap_options['trace'] = TRUE;
$soap_options['cache_wsdl'] = WSDL_CACHE_NONE;
$soap_options['style'] = SOAP_DOCUMENT;
$soap_options['use'] = SOAP_LITERAL;
$soap_options['soap_version'] = SOAP_1_2;
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing','Action',$action , true);
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing','To',$api_target ,true);
$client = new SoapClient($api_url,$soap_options);
$client->__setSoapHeaders($actionHeader);
$result = $client->__soapCall('Login',array($user));;

Trying to use Adaptive Simple Payments but get blank screen

I'm trying to figure out how to use Adaptive Simple Payments with Paypal API and trying to test their default code:
$payRequest = new PayRequest();
$receiver = array();
$receiver[0] = new Receiver();
$receiver[0]->amount = "1.00";
$receiver[0]->email = "platfo_1255170694_biz#gmail.com";
$receiverList = new ReceiverList($receiver);
$payRequest->receiverList = $receiverList;
$requestEnvelope = new RequestEnvelope("en_US");
$payRequest->requestEnvelope = $requestEnvelope;
$payRequest->actionType = "PAY";
$payRequest->cancelUrl = "https://devtools-paypal.com/guide/ap_simple_payment/php?cancel=true";
$payRequest->returnUrl = "https://devtools-paypal.com/guide/ap_simple_payment/php?success=true";
$payRequest->currencyCode = "USD";
$payRequest->ipnNotificationUrl = "http://replaceIpnUrl.com";
$sdkConfig = array(
"mode" => "sandbox",
"acct1.UserName" => "reznik.demarket-facilitator_api1.gmail.com",
"acct1.Password" => "BV5GBSV7QBPXJUNR",
"acct1.Signature" => "AcK.GqlanslGMma1L2TIOPx.t0xQApMepP-Rt7jundLbNOzkwOhrqbJ4",
"acct1.AppId" => "APP-80W284485P519543T"
);
$adaptivePaymentsService = new AdaptivePaymentsService($sdkConfig);
$payResponse = $adaptivePaymentsService->Pay($payRequest);
it should give me json answer like that:
{"responseEnvelope":{"timestamp":"2015-02-26T17:14:06.242-08:00","ack":"Success","correlationId":"aae1f46492b42","build":"15089777"},"payKey":"AP-0SN13003KN641223K","paymentExecStatus":"CREATED"}
Why can i get a blank screen without any errors or success messages?
Sounds like you're getting a PHP error but you don't have errors being displayed on the server. Try adding this to the top of your script...
error_reporting(E_ALL);
ini_set('display_errors', '1');
That should allow you to see the error that is happening so you can fix it.

Categories