PHP cURL request failing to balanced payments - php

I'm trying to submit a cURL request to Balanced Payment's test marketplace to simulate charging a credit card but I keep on getting an "unauthorized" status with "authentication-required" as the category_code. I've been able to successfully submit other requests using their documentation, so I'm not quite sure what I'm doing wrong.
I'm following these steps to charge a credit card in the test marketplace.
I'm only at step 1 which is to create an account to associate the card token with which is referred to as the URI.
//all of these parameters are supplied in the documentation
$url = 'https://api.balancedpayments.com/v1/marketplaces/TEST-MP3k9AuX9cW549vxxxxxxxxxxxxxxxx/accounts';
$post_arr[] = 'username=6d2896e8e9a911e2b3cd02xxxxxxxxxxxxxx:';
$post_arr[] = 'card_uri=/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/cards/CC3DSm7qtThxh6DRe6lnYNVC';
$post = implode('&',$post_arr);
//make the request
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); // 3 seconds to connect
curl_setopt ($ch, CURLOPT_TIMEOUT, 10); // 10 seconds to complete
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
This is the output
{ "status": "Unauthorized", "category_code": "authentication-required", "category_type": "permission", "_uris": {}, "description": "Not permitted to perform show on cards. Your request id is OHMefab3f08ea6711e2950a026ba7xxxxxxxxxxxxx.", "request_id": "OHMefab3f08ea6711e2950a026baxxxxxxxxxxxx", "status_code": 401 }
However, I when I make the request with the following parameters to tokenize a card, it works.
$url = 'https://api.balancedpayments.com/v1/marketplaces/TEST-MP3k9AuX9cW549vxxxxxxxxxxxxx/cards';
$post_arr[] = '6d2896e8e9a911e2b3cd026bxxxxxxxxxxxxxx:';
$post_arr[] = 'expiration_month=12';
$post_arr[] = 'security_code=123';
$post_arr[] = 'card_number=5105105105105100';
$post_arr[] = 'expiration_year=2020';
$post_arr[] = 'category_type=request';
$post = implode('&',$post_arr);
Here is the output
{ "security_code_check": "true", "_type": "card", "hash": "b7250dd4b4827a88d5e4132b67f02916bce6f8e83d4ca0d779d1351b360ff6af", "brand": "MasterCard", "expiration_month": 12, "_uris": {}, "meta": {}, "last_four": "5100", "id": "CCSBORr685LWzmR62FSKZaw", "customer": null, "account": null, "postal_code_check": "true", "name": "None", "expiration_year": 2020, "created_at": "2013-07-11T21:01:53.245948Z", "uri": "/v1/marketplaces/TEST-MP3k9AuX9cW549vd1Ao5M0OW/cards/CCSBORr685LWzmR62FSKZaw", "card_type": "mastercard", "is_valid": true, "is_verified": true }
edit - I could still be doing something incorrectly, but I think there may be a mistake in the documentation
I removed the 'card_uri' parameter from my request and it succeeded. Upon checking out the returned JSON I noticed that it's 'cards_uri' not 'card_uri'. Maybe I'm still not doing something correctly, but when I changed my initial request to 'cards_uri' it then succeeded.
Here is the output now
{ "_type": "account", "_uris": { "holds_uri": { "_type": "page", "key": "holds" }, "bank_accounts_uri": { "_type": "page", "key": "bank_accounts" }, "refunds_uri": { "_type": "page", "key": "refunds" }, "customer_uri": { "_type": "customer", "key": "customer" }, "debits_uri": { "_type": "page", "key": "debits" }, "transactions_uri": { "_type": "page", "key": "transactions" }, "credits_uri": { "_type": "page", "key": "credits" }, "cards_uri": { "_type": "page", "key": "cards" } }, "bank_accounts_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/bank_accounts", "meta": {}, "transactions_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/transactions", "email_address": null, "id": "AC2A9aCbuzUWalMNX7JXbhrk", "credits_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/credits", "cards_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/cards", "holds_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/holds", "name": null, "roles": [], "created_at": "2013-07-11T21:24:55.567233Z", "uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk", "refunds_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/refunds", "customer_uri": "/v1/customers/AC2A9aCbuzUWalMNX7JXbhrk", "debits_uri": "/v1/marketplaces/TEST-MP24GBSQWq3M2nzdEtvvnHOf/accounts/AC2A9aCbuzUWalMNX7JXbhrk/debits" }

You are not authenticating. Try adding
curl_setopt('6d2896e8e9a911e2b3cd026ba7f8ec28:', CURLOPT_USERPWD)

Related

Cannot post data to API via Curl and PHP

Am working with Blinksky Payments API.
Below is the post parameters
URI https://api.blinksky.com/api/v1
POST /send
{
"gift": {
"action": "order",
"apikey": "{APIKey}",
"sender": "Athens Automotive Inc.",
"from": "17705551234",
"dest": "16150001234",
"code": "62",
"amount": 100,
"postal": "30005",
"msg": "Thanks for taking our test drive!",
"reference": "{your_unique_order_id}",
"handle_delivery": false
}
}
When I tried my code below, it throws error
{ "statusCode": 404, "message": "Resource not found" }
What am I doing wrong? Below is the code:
$url = "https://api.blinksky.com/api/v1";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
$post ='{
"gift": {
"action": "order",
"apikey": "my-api-key-goes-here",
"sender": "Luxury Automotive Inc.",
"from": "17705551xxxxxxx",
"dest": "16150001xxxxxxx",
"code": "62",
"amount": 100,
"postal": "90211",
"msg": "Thanks for the Gift!",
"reference": "G62-786",
"handle_delivery": false
}
}';
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json'
));
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'POST');
curl_setopt($ch,CURLOPT_POSTFIELDS, $post);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
print_r($response);
You are missing the /send path in your url.
Change this:
$url = "https://api.blinksky.com/api/v1";
to this:
$url = "https://api.blinksky.com/api/v1/send";

Can't insert multiple events at once in Google Calendar in php

I'm trying to insert multiple events to the google calendar with PHP. When I try to insert one event with this code below, it works, but when I want to insert multiple events on google calendar API server, to save more data, i get some error.
This is the code that I have:
I have an JSON string, this string was converted to a php array.
$calendar =
json_decode('
{
"summary": "Calendar name",
"description": "Calendar description",
"items":
[
{
"summary": "event1",
"colorId": "10",
"start": {
"dateTime": "2018-05-10T12:30:00+02:00"
},
"end": {
"dateTime": "2018-05-10T13:30:00+02:00"
},
"recurrence": [
"RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=TH"
]
},
{
"summary": "event2",
"start": {
"dateTime": "2018-05-17T12:30:00+02:00"
},
"end": {
"dateTime": "2018-05-17T13:30:00+02:00"
}
},
{
"summary": "event3",
"description": "event3 description",
"colorId": "2",
"start": {
"date": "2018-05-10"
},
"end": {
"date": "2018-05-11"
},
"transparency": "transparent"
}
]
}
', true);
With this functions, I can add only one event to google calendar. When I try to insert more events I get errors...
function CreateCalendarEvents($calendar_id, $access_token, $events_json) {
$url_events = 'https://www.googleapis.com/calendar/v3/calendars/'.$calendar_id.'/events';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_events);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token, 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($events_json));
$data = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if($http_code != 200){
throw new Exception('Error : Failed to create events');
}
return $data['id'];}
I call function with this line of code:
CreateCalendarEvents('primary', $_SESSION['access_token'], $calendar);

Enhance Air ticket showing incorrect result in codeigniter

I am trying to post this JSON in post with URL
$url = 'https://api.havail.sabre.com/v1.2.0/air/ticket';
$headers2 = array(
'Authorization: bearer '.$access_token,
'protocol: HTTP 1.1 ',
'Accept: */*',
"Content-Type: application/json"
);
$postData ='{
"AirTicketRQ": {
"DesignatePrinter": {
"Profile": {
"Number": 1
}
},
"Itinerary": {
"ID": "VWKJJT"
},
"Ticketing": [{
"FOP_Qualifiers": {
"BSP_Ticketing": {
"MultipleFOP": {
"Fare": {
"Amount": "100.00"
},
"FOP_One": {
"CC_Info": {
"Suppress": true,
"PaymentCard": {
"Code": "VI",
"ExpireDate": "2016-11",
"ExtendedPayment": 12,
"Number": ***********1003
}
}
},
"FOP_Two": {
"Type": "CK"
}
}
}
},
"PricingQualifiers": {
"PriceQuote": [{
"Record": [{
"Number": 1,
"Reissue": true
}]
}]
}
},
{
"FOP_Qualifiers": {
"BSP_Ticketing": {
"MultipleFOP": {
"Fare": {
"Amount": "100.00"
},
"FOP_One": {
"CC_Info": {
"Suppress": true,
"PaymentCard": {
"Code": "VI",
"ExpireDate": "2016-11",
"ExtendedPayment": 12,
"Number": ************1003
}
}
},
"FOP_Two": {
"Type": "CA"
}
}
}
},
"PricingQualifiers": {
"PriceQuote": [{
"Record": [{
"Number": 2,
"Reissue": true
}]
}]
}
}],
"PostProcessing": {
"EndTransaction": {
"Source": {
"ReceivedFrom": "SPTEST"
}
}
}
}
}';
$ch2 = curl_init();
curl_setopt($ch2,CURLOPT_HTTPHEADER,$headers2);
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, POST);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $postData);
//curl_setopt($curl_handle, CURLOPT_HTTPGET, TRUE);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
//var_dump( $results = json_decode(curl_exec($ch2)));
$results["get_data"] = json_decode(curl_exec($ch2),true);
I tried to use GET method for some other API and it was working. But for Enhanced Air ticket I am getting wrong data in response.
First Part:
Second Part:
What is the printer error and all. I used some get APIs that worked but why this API showing those problems? What is the actual problem? Is my JSON is correct that I am sending in request?
The problem is on this part of the code:
"DesignatePrinter": {
"Profile": {
"Number": 1
}
},
If this used to work, the you probably done it in a different environment or PCC.

Implementation of Bing Spell Check API v7 returns 0 flaggedTokens

I'm trying to implement the Bing Spell Check API v7. This is my current function:
# spell check
function bing_spell_check($q, $lang) {
$param = array();
$param['appName'] = PRO_NAME;
$param['text'] = $q;
$param['setLang'] = $lang;
$url = 'https://api.cognitive.microsoft.com/bing/v7.0/SpellCheck?'.http_build_query($param);
$process = curl_init();
curl_setopt($process, CURLOPT_URL, $url);
curl_setopt($process, CURLOPT_TIMEOUT, 10);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_HTTPHEADER,
array(
'Accept: application/ld+json',
'Ocp-Apim-Subscription-Key: '.PRO_BING_KEY_SPELL
)
);
$response = curl_exec($process);
return $response;
}
The problem is that this example:
print_r(bing_spell_check('en', 'whts yur name?'));
Returns:
{
"#context":{
"#vocab":"http:\/\/bingapis.com\/v7\/schemas\/",
"s":"http:\/\/schema.org\/",
"#base":"https:\/\/api.cognitive.microsoft.com\/api\/v7\/"
},
"#type":"SpellCheck",
"flaggedTokens":[
]
}
Which means it has not found any errors. I ran the very same test in Bing's test tool, and I received this structure instead:
{
"_type": "SpellCheck",
"FlaggedTokens": [
{
"Offset": 0,
"Token": "whts",
"Type": "UnknownToken",
"Suggestions": [
{
"suggestion": "what's",
"Score": 0.909352914464075
},
{
"suggestion": "whats",
"Score": 0.810588859407343
},
{
"suggestion": "what is",
"Score": 0.680176771139565
}
]
},
{
"Offset": 5,
"Token": "yur",
"Type": "UnknownToken",
"Suggestions": [
{
"suggestion": "your",
"Score": 0.909352914464075
}
]
}
]
}
Am I missing something. Any ideas? Thanks!
It is quite simple, you just mixed up your function parameters. You have
function bing_spell_check($q, $lang) {}
and
bing_spell_check('en', 'whts yur name?');
That is where the problem starts, $q is now en and $lang is now whts yur name?. Thus when you create your $param array you have the language and the text mixed up (which will cause the Spell Check API to silently fail). You can simply fix this by changing the parameter order:
function bing_spell_check($lang, $q) {}
Now your code
<?php
define(PRO_BING_KEY_SPELL, 'XXX');
define(PRO_NAME, 'XXX');
function bing_spell_check($lang, $q) {
$param = array();
$param['appName'] = PRO_NAME;
$param['text'] = $q;
$param['setLang'] = $lang;
$url = 'https://api.cognitive.microsoft.com/bing/v7.0/spellcheck?'.http_build_query($param);
$process = curl_init();
curl_setopt($process, CURLOPT_URL, $url);
curl_setopt($process, CURLOPT_TIMEOUT, 10);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_HTTPHEADER,
array(
'Accept: application/ld+json',
'Ocp-Apim-Subscription-Key: '.PRO_BING_KEY_SPELL
)
);
$response = curl_exec($process);
return $response;
}
print_r(bing_spell_check('en', 'whts yur name?'));
?>
results in
{
"#context": {
"#vocab": "http:\/\/bingapis.com\/v7\/schemas\/",
"s": "http:\/\/schema.org\/",
"#base": "https:\/\/api.cognitive.microsoft.com\/api\/v7\/"
},
"#type": "SpellCheck",
"flaggedTokens": [{
"offset": 0,
"token": "whts",
"type": "UnknownToken",
"suggestions": [{
"suggestion": "what's",
"score": 0.909352914464075
}, {
"suggestion": "whats",
"score": 0.810588859407343
}, {
"suggestion": "what is",
"score": 0.680176771139565
}]
}, {
"offset": 5,
"token": "yur",
"type": "UnknownToken",
"suggestions": [{
"suggestion": "your",
"score": 0.909352914464075
}]
}]
}

How to configure Authorize.Net webhooks

I have configured Authorize.net, accept hosted payment method for my client requirement, where everything is happening fine, except Transaction reponse. As per Authorize.net, response comes only either of these ways, webhooks or CommunicatorUrl. CommunicatorUrl not working for my code. so, opted for webhooks. Below is my code. please, suggest me something.
My doubts are:
My Code displaying this error when calling list of available webhooks
{
"status": 405,
"reason": "Method Not Allowed",
"message": "The requested resource does not support http method 'POST' for given parameters.",
"correlationId": "ff90ee25-0ba7-4006-bb1e-225ea64897e3"
}
Should i configure webhook anywhere in my Merchant Panel
How would i get my transaction response using webhook
<?php
$login_transKey = 'xxx:xxx'; //Login and Transaction Key of Authorize.net
$jsonObj = '{
"name": "Get WebHooks",
"request": {
"url": "http://localhost:81/hosted_payment_form/webhookstwo.php",
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
},
{
"key": "Authorization",
"value": "'.$login_transKey.'",
"description": ""
}
],
"body": {
"mode": "formdata",
"formdata": []
},
"description": ""
},
"response": []
}';
$jsonObj = json_encode($jsonObj);
$url = "https://apitest.authorize.net/rest/v1/eventtypes";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonObj);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
$content = curl_exec($ch);
echo '<pre>'; print_r($content); die();
curl_close($ch);
?>
Please, Let me know for more information.
You need to specify the webhook URL in authorize.net account.
Also you need to select the events in the settings page.
Please make sure that the Web-hook URL always return HTTP 200 response.
Otherwise it will be automatically changed to Inactive status.

Categories