What is $_SERVER['HTTP_CB_SIGNATURE'] in coinbase api notification? - php

Hi I am trying to use coinbase api,api implementation is Working fine but facing problem on notification. Accroding to documentation I have created Notification url and codes are bellow
<?php
require_once('vendor/autoload.php');
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
$apiKey=" xxxx";
$apiSecret="xxxx";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$raw_body = file_get_contents('php://input');
$signature = $_SERVER['HTTP_CB_SIGNATURE'];
$authenticity = $client->verifyCallback($raw_body, $signature); // boolean
if($authenticity){
$data = json_decode($raw_body, true);
mail("sahid4745#gmail.com","Coinbase Payment Notifications",print_r($order, true));
}
$message=$raw_body;
mail('sahid4745#gmail.com', 'My Subject', $message);
?>
But this is producing error as Notice:
Undefined index: HTTP_CB_SIGNATURE in /home/exhakduz/api/webhooks.php
on line 38
I Don't know actually what is server_cb_signature, if some one can explain that will be great help for me.

All entries in $_SERVER that begin with HTTP_ reflect the contents of HTTP request headers. The header name is converted to uppercase and - is converted to _. So if the client sends a header like Foo-Bar: blah, the value of $_SERVER['HTTP_FOO_BAR'] will be "blah".
The Coinbase documentation says that notifications are secured with a CB-SIGNATURE header, so $_SERVER['HTTP_CB_SIGNATURE'] should contain the contents of this header. I'm not sure why you're not getting it. Your code is exactly like the example code in the documentation.
Maybe there's something in your server configuration that's filtering out nonstandard headers?

Related

Google PlayIntegrity API - validate token via PHP

I am no professional Android developer and I'm having problems to get the Google PlayIntegrity token from my app to decode via PHP through my back-end server and couldn't find much help online.
I included the Google PHP API onto my server, integrated the API into my app and activated&linked it on the Play Console. But it seems I am doing something wrong, I am getting the following PHP error messages:
Warning: Attempt to read property "appLicensingVerdict" on null
My code:
<?php
namespace foo;
use Google\Client;
use Google\Service\PlayIntegrity;
use Google\Service\PlayIntegrity\DecodeIntegrityTokenRequest;
require_once __DIR__ . '/google/vendor/autoload.php';
// Google Integrity token, as obtained from Google through my app:
$token = $_POST['IntegrityToken'];
$client = new Client();
$client->setAuthConfig('google/credentials.json');
$client->addScope(PlayIntegrity::PLAYINTEGRITY);
$service = new PlayIntegrity($client);
$tokenRequest = new DecodeIntegrityTokenRequest();
$tokenRequest->setIntegrityToken($token);
$result = $service->v1->decodeIntegrityToken('com.myapp.game', $tokenRequest);
// Read and handle the JSON response:
$appLicensingVerdict = $result->accountDetails->appLicensingVerdict;
// ... more fields are available in the JSON... see Google documentation
// Check/verify the obtained response values.....
?>
Any help would be much appreciated! Many thanks!
Also thanks to hakre's help, I was able to solve the problems I was facing. The code works fine with tokenPayLoadExternal included:
$appLicensingVerdict = $result->tokenPayloadExternal # <-- this
->accountDetails
->appLicensingVerdict
;

How do I code in PHP this instruction provided by a vendor "DELETE /<domain>/unsubscribes/<address>"

I am working with Mailgiun. Their documentation shows a php example for obtaining a list of email addresses (see below), which I have working in my own code.
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = 'YOUR_DOMAIN_NAME';
$recipient = 'bob#example.com';
$tag = '*';
# Issue the call to the client.
$result = $mgClient->suppressions()->unsubscribes()->create($domain, $recipient, $tag);
I want to remove an entry in their list, and their code example for doing so only shows the following line of code:
DELETE /<domain>/unsubscribes/<address>
How do I code the line above using PHP?
Note:
I have tried the following block of code,
$result = $mailgun_client->suppressions()->bounces()->delete('mg.quikkast.com', 'emailaddress#gmail.com');
but get back a the following error:
Mailgun\Exception\HttpClientException: The endpoint you have tried to access does not exist. Check if the domain matches the domain you have configure on Mailgun.
Thus far Mailgun has not responded with a solution to my support ticket. So any help would be greatly appreciated.
Upgraded to latest version of MG library. Posted a new question to specifically get MG to correct error their code is reporting.

What is correct Twilio AddOns syntax for php REST client?

Beginner to both Twilio & php here:
I have: Twilio php helper, Twilio account, Whitepages Pro AddOn enabled for Lookups and have successfully retrieved "basic" lookup data, ie, "Carrier->Type" (the "basic" lookup does not use the AddOn)
I need: to use Twilio Rest Client with Whitepages Pro AddOn to retrieve other data, ie, "standard_address_line1", for an individual phone number. I do not want the $0.07 per call AddOn enabled for all incoming calls, although I was able to receive this data from the AddOn that way.
Twilio API Documentation is scant. Shows output format, but not REST Client request syntax: WhitePagesPro AddOn Documentation
Here is what I tried:
<?php
require 'vendor/autoload.php';
use Twilio\Rest\Client;
$client = new Client(ACxxxxxxxxxx,Tokenxxxxxxxx);
$number = $client->lookups
->phoneNumbers("+1xxxxxxxxxx")
->fetch(
array("AddOns" => "whitepages_pro_caller_id")
);
echo $number->
results->
whitepages_pro_caller_id->
result->
results[0]->
associated_locations[0]->
standard_address_line1;
//This syntax works for 'basic' lookup
//Returns: "landline"
//
//$number = $client->lookups
// ->phoneNumbers("+1xxxxxxxxxx")
// ->fetch(
// array("type" => "carrier")
// );
//
//echo $number->carrier['type'];
?>
Throws error: Uncaught exception 'Twilio\Exceptions\TwilioException' with message 'Unknown property: results'
I'm way over my head, I don't know how to go about debugging this. Any Twilio experts?
Ideally I'd also like to know if it's possible to specify this particular data in the request vs traversing many levels of the response in order to get the data I need...
Twilio developer evangelist here.
You're very close with what you have there. The addOns results are actually returned in the addOns property of the number there. So, using your code, you can print the request SID of the call like this:
<?php
require 'vendor/autoload.php';
use Twilio\Rest\Client;
$client = new Client(ACxxxxxxxxxx,Tokenxxxxxxxx);
$number = $client->lookups
->phoneNumbers("+1xxxxxxxxxx")
->fetch(
array("AddOns" => "whitepages_pro_caller_id")
);
echo $number->addOns['results']['whitepages_pro_caller_id']['request_sid']
If you want to inspect the entire result, you can use var_dump to see the entire structure
var_dump($number->addOns['results']['whitepages_pro_caller_id'])
The structure will appear as it does in the documentation but it might be easier to see in the PHP output.
Let me know if that helps at all.

SendGrid v3 400 bad request

I'm using sendgrid/sendgrid-php the repo on github to send transnational emails. Today I've updated the library, the new one uses the API v3 whereas I used v2 before. I've changed the code as per their examples, here is a dump of my SendGrid\Mail object:
The problem is that I'm constantly receiving the 400 BAD REQUEST error without any additional info:
What am I doing wrong? The mail object seems to be correct.
I'm trying to send the email the following way:
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$request_body = [creating the mail object];
$response = $sg->client->mail()->send()->post($request_body);
I was having the same issue and discovered all personalizations need to be strings with double quotes. In your example:
$md_email_id = (string)26921
More info https://github.com/sendgrid/sendgrid-php/issues/264

Twilio sending message Using twilio library

Sending twilio message from my api returns this error
Twilio sending message The requested resource /2010-04-01/Accounts//Messages.json was not found
this is how I send a message. anyone incountered a problem?
$this->client = new \Services_Twilio($sid, $token);
return $this->client->account->messages->sendMessage($from ,$to, $message);
this is the documentation I followed
https://www.twilio.com/docs/api/rest/sending-sms
How do I create Messages.json
I used this https://github.com/twilio/twilio-php on laravel 4.2
Another Twilio developer evangelist here. Think I might be able to help.
The error message you got was this:
The requested resource /2010-04-01/Accounts//Messages.json was not found
The key point is the URL, particularly the double slash in the middle. That is where your Account Sid should be, thus leading to the 404 error.
In this case, I would double check how you are setting $sid. Make sure it is assigned before you try to create the Twilio client object.
Hi Twilio developer evangelist here.
Sorry to hear you're having trouble with your code.
You seem to not have posted your complete code, so I don't see where you actually require the library.
I have however written an example which worked for me.
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = 'AC';
$token = '01';
$client = new \Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
'+44', // From a valid Twilio number
'+44', // Text this number
"Hello monkey!"
);
I have removed some sensitive data on the code, but if you replace that with your token and numbers, you should be able to send a text message correctly.
Also, just in case you have the contents of the 'Services' folder elsewhere, make sure your paths are correct.
You have entered messages when it should be sms_messages.
CHANGE
$this->client->account->messages->sendMessage($from ,$to, $message);
INTO
$this->client->account->sms_messages->create($from ,$to, $message);
Also make sure that you are running this code inside a class otherwise you need to remove the $this-> from your code and use a local varible.

Categories