Neteller TransferOut with PHP / CURL - php

I'm having some problems using the Neteller API to transfer money out of our merchant account to a user. I've succcessfully received the accessToken, however when I try using transferOut I just get invalid credentials? The code I'm using is:
$headers = array(
"Content-type" => "application/json",
"Authorization" => "Bearer " . $accessToken
);
//build the request body structure
$requestParams = array(
"payeeProfile" => array(
"email" => $the_email_address_to_send_to
),
"transaction" => array(
"merchantRefId" => $transaction_id,
"amount" => $amount,
"currency" => $currencyCode
)
);
// encode the requestParams to a string
$requestParams = json_encode($requestParams);
// The curl stuff
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, "https://api.neteller.com/v1/transferOut");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestParams);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Ok lets send this lovely looking curl over
$serverOutput = json_decode(curl_exec($curl));
Obviously all variables ($transaction_id, $amount, $currency) are set appropriately. However the response I get back is:
stdClass Object
(
[error] => stdClass Object
(
[code] => 5279
[message] => Authentication credentials are invalid
)
)
I'm confused, surely the accessToken is the credentials I need, and theyve already been received. Am I meant to include anything else in the transferOut curl postfields?
Thanks in advance

As per user3584460's comment:
$headers does not look OK - try $headers = array("Content-type: application/json", "Authorization: Bearer " . $accessToken);. At least this is the format according to http://php.net/manual/en/function.curl-setopt.php
Note, the Merchant Ref ID also needs to be a certain length. unsure what - can't find reference, but 8 characters is not long enough.

Related

PHP Xero API is creating duplicate overpayment entries (BankTransaction)

We are creating overpayments via the PHP Xero API.
In some cases, the overpayments are being duplicated.
Here is the code we are using:
<?php
$endpoint = 'https://api.xero.com/api.xro/2.0/BankTransactions';
$headers = array(
"Content-Type: application/json",
"Xero-tenant-id: " . $xero_access['tenant_id'],
"Authorization: Bearer " . $xero_access['token'],
);
$postFields = array(
"Type" => "RECEIVE-OVERPAYMENT",
'Contact' => ['ContactID' => $contactID],
'BankAccount' => ['accountID' => $xero_settings['account_id']],
'LineAmountTypes' => 'NoTax',
'LineItems' => [0 => [
'Description' => 'Customer Credit',
'LineAmount' => $price
]]
);
try {
$ch = #curl_init();
#curl_setopt($ch, CURLOPT_URL, $endpoint);
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
#curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
#curl_setopt($ch, CURLOPT_POST, 1);
#curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields, JSON_PRETTY_PRINT));
$response = #curl_exec($ch);
$status_code = #curl_getinfo($ch, CURLINFO_HTTP_CODE);
error_log($status_code);
error_log($response);
} finally {
#curl_close($ch);
}
?>
I am not quite sure why the transactions are being duplicated or even if it is a network issue, or something in the code above.
Is there a way to make these API calls unique and make sure a request is not sent twice?
Thanks
Could you raise a case with Xero Support and include:
Your client id, the name of the connect tenant, the date and time of a call with duplication (and your timezone), the details of the overpayment eg the contact name, date and amount

Curl Php Returns NULL in browser on

I am trying to authenticate to third party ticketing system, connect and retrieve agent info. I then want to parse retrieved file so as to only show specific info such as 'id' and' 'active_since', but I get an NULL error in browser. Any help?
FILE RETURNED BY THIRDPARTY
[agent] => Array
(
[active_since] => 2015-11-30T08:09:26-01:00
[available] => 1
[created_at] => 2015-05-14T19:15:18+00:00
[id] => XXXXX
[occasional] =>
[points] => 5520
[scoreboard_level_id] => 5000402007
[signature] =>
[signature_html] =>
Below is the PHP CURL code.
<?php
$username = "xxxxxxx";
$password = "xxxxxxx";
$url = 'http://support.xxxx.com/agents/xxx132067';
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json',
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
);
$result = file_get_contents($url);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
$array["active_since"];
?>
Remove the 'header' => from the Authorization header. And it should be as below:
"Authorization: Basic " . base64_encode("$username:$password")
And I didn't see you are calling curl at all. Replace your file_get_contents with proper curl call.
$result = curl_exec($cURL);
curl_close($cURL);

PayPal Adaptive payment using Access Token

I want to make a Adaptive payment from one account to other account.I can get a Access token .But i don't know how to make a Pay API call using Access token.
Actually I want to bypass PayPal login screen.
global $token;
$url = 'https://api.sandbox.paypal.com/v1/AdaptivePayments/Pay';
$createPacket = array(
"actionType" => 'PAY',
"currencyCode" => "SGD",
"receiverList" => array(
"receiver" => array(
array(
"amount" => '34.00',
"email" => 'abc#gmail.com',
)
)
),
"returnUrl" => $params['redirect_url'],
"cancelUrl" => $params['cancel_url'],
'senderEmail' =>'abcd#gmail.com',
"requestEnvelope" => $this->envelope);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $token,
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($createPacket) );
#curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec($curl);
Your help would be appreciated.
To the best of my knowledge, it is not possible to skip the authentication screen. At some point, the user or owner of the account you are working with must authenticate in order to prove that he has given you permission to perform the work you are doing.
You might wonder why Authentication is needed when you pass an Authorization token in the API call, but the auth token that you pass as 'Authorization: Bearer ' . $token, is actually identification of your application and not the user.

invalid_grant while trying to get the Access token request Azure AD

I am trying to get the access token from Azure Ad as explained the below link. I need to use the office 365 REST API.
msdn.microsoft.com/en-us/library/azure/dn645542.aspx
Authorization code request is successfull and i am getting the code in return URL. But the Access token request is failing and the response i am getting as below.
stdClass Object
(
[error] => invalid_grant
[error_description] => AADSTS70002: Error validating credentials. AADSTS70000: The provided access grant is invalid or malformed.
Trace ID: baf9f98a-655d-48e1-bc30-021a7d57effa
Correlation ID: 5030b57f-42e2-403a-ab3c-cfc970d886e2
Timestamp: 2015-04-21 12:58:00Z
[error_codes] => Array
(
[0] => 70002
[1] => 70000
)
[timestamp] => 2015-04-21 12:58:00Z
[trace_id] => baf9f98a-655d-48e1-bc30-021a7d57effa
[correlation_id] => 5030b57f-42e2-403a-ab3c-cfc970d886e2
[submit_url] =>
[context] =>
)
Below is my code:
$url = "https://login.windows.net/<tenant-id>/oauth2/token";
$postUrlData = "grant_type=authorization_code&client_id=$clientId&code=$authCode&redirect_uri=$redirectUri&client_secret=$secretKey";
$headers = array(
'Content-type: application/x-www-form-urlencoded',
'Content-length: '. strlen($postUrlData)
);
//echo $postUrlData;die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS , $postUrlData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$res = json_decode($result);
curl_close($ch);
Can you please tell me what am i doing wrong?
Take a look at this PHP sample: https://github.com/jasonjoh/php-calendar. Specifically, look at the getTokenFromAuthCode function in https://github.com/jasonjoh/php-calendar/blob/master/o365/Office365Service.php.

paypal rest api payment call returning 401 using php

I am trying to add paypal to my site. I have been following the instructions at https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/, but it is not working. I have sent the request for an access token successfully and gotten a response. The information in the response is stored in an object called $accessToken. The problem lies when I try to make the API call in step 3 from the site listed above. I get a 401 error sent back from the request. I'm pretty sure the $url that the request is sent to as a function parameter is correct. It is https://api.sandbox.paypal.com/v1/payments/payment. I have been going all over the internet for help for the past week and a half, and I haven't made any progress whatsoever. Any help would be greatly appreciated. Thanks!
function MakePaymentAPICall($accessToken, $sale, $url, $url_success, $url_cancel){
// Create cURL resource
$ch = curl_init();
// Set url
curl_setopt($ch, CURLOPT_URL, $url);
$tokenType = $accessToken->GetTokenType();
$token = $accessToken->GetAccessToken();
$auth = "Authorization:" . $tokenType . " " . $token;
$saleTotal = $sale->GetTotal();
$header = array(
'Content-Type' => 'application/json',
'Authorization' => $tokenType . ' ' . $token
);
$dataArray = array(
'intent' => 'sale',
'redirect_urls' => array(
'return_url' => $url_success,
'cancel_url' => $url_cancel
),
'payer' => array(
'payment_method' => 'paypal'
),
'transactions' => array(
'amount' => array(
'total' => $saleTotal,
'currency' => 'USD'
),
'description' => 'Test payment.'
)
);
curl_setopt($ch, CURLOPT_HEADER, http_build_query($header));
// set data to post
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($dataArray));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
// Execute curl command
$output = curl_exec($ch);
// Get info about request
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close cURL resource to free up system resources
curl_close($ch);
return $output;
} // MakePaymentAPICall function
#Jason247
http://php.net/manual/en/function.curl-setopt.php
I think that CURLOPT_HEADER requires an int or bool, either 1 or TRUE to send headers.
I do believe CURLOP_HTTPHEADER is what you want, you can pass an array directly to it without encoding to a query string.
e.g.
curl_setopt($curlHandle, CURLOPT_HEADER, 1);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $curlHeaders);
A 401 error generally indicates that the access token is either invalid or expired:
https://developer.paypal.com/webapps/developer/docs/integration/direct/rest-payments-error-handling/
Are you including "Bearer" in the Authorization header? Example:
Authorization:Bearer EMxItHE7Zl4cMdkvMg-f7c63GQgYZU8FjyPWKQlpsqQP

Categories