How to use authorize.net without framework - php

I am having problems just getting authorize.net to work. I feel Like I am missing something, but not sure what it is. I follow this guide here on the website: http://developer.authorize.net/hello_world/ I have composer setup correctly I believe, but when I run the sample code I get an error
Fatal error: Class 'Goetas\Xsd\XsdToPhp\Jms\Handler\BaseTypesHandler' not found in /home/admin/web/*****/public_html/pricing/vendor/authorizenet/authorizenet/lib/net/authorize/api/controller/base/ApiOperationBase.php on line 82
Note: The stars in the location after "/web/" were to hide the domain that was listed for security reasons.
Any clue how I can get this to work?
Does anyone have a step by step guide to integrate authorize.net into a custom built platform? We are just trying to send the basic information needed to charge a card and receive a response back.

To anyone running into issues with Trying to quickly integrate authorize.net into their pay system or website. Below is the code I used to built/customized to get this to work. The framework is not needed unless you are creating a fully integrated system, which is not clearly indicated on the site. You are obviously going to have to expand on this code further, but this should be what anyone needs to integrate into authorize quickly.
$params = array(
'x_invoice_num' => 'test',
'x_amount' => '5',
'x_exp_date' => '1202',
'x_address' => 'test',
'x_zip' => '12345',
'x_first_name' => 'test',
'x_last_name' => 'test',
'x_relay_response' => false,
'x_type' => 'AUTH_CAPTURE',
'x_method' => 'CC',
'x_login' => 'yourlogin code goes here',
'x_tran_key' => 'your trans key goes here',
'x_card_num' => '4111111111111111',
'x_card_code' => '143',
'x_delim_data' => true,
'x_delim_char' => '|',
'x_relay_response' => false
);
$postString = '';
foreach ($params as $key => $value)
$postString .= $key.'='.urlencode($value).'&';
$postString = trim($postString, '&');
$url = 'https://secure.authorize.net/gateway/transact.dll';
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_POSTFIELDS, $postString);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, false);
$postResponse = curl_exec($request);
curl_close($request);
print_r($postResponse);
$response = explode('|', $postResponse);
if (!isset($response[7]) || !isset($response[3]) || !isset($response[9]))
{
$msg = 'Authorize.net returned a malformed response for cart';
if (isset($response[7]))
$msg .= ' '.(int)$response[7];
die('Authorize.net returned a malformed response, aborted.');
}
$message = $response[3];
switch ($response[0]) // Response code
{
case 1: // Payment accepted
print_r($response[1]);
break ;
case 4: // Hold for review
print_r($response[4]);
break ;
default:
echo $message;
exit;
}

Related

unable to send out voice broadcast with callfire REST API

I'm trying to send out an outbound call with the callfire REST API and am having some difficulty doing so. Here's my code (adapted from https://developers.callfire.com/docs.html#createVoiceBroadcast):
<?php
$username = '...';
$password = '...';
$data = array(
'name' => 'Automation Test',
'fromNumber' => '...',
'recipients' => array(
array('phoneNumber' => '...')
),
'answeringMachineConfig' => 'AM_AND_ALIVE',
'liveSoundText' => 'hello, world!',
'machineSoundText' => 'hello, world!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://api.callfire.com/v2/campaigns/voice-broadcasts');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = json_decode(curl_exec($ch));
print_r($result);
The problem is in the response. It's as follows:
stdClass Object
(
[httpStatusCode] => 415
[internalCode] => 0
[message] => Exception in API
)
The 415 status code is for "Unsupported Media Type" per https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error but since I'm not uploading any media that error doesn't really make a lot of sense.
Maybe my value for answeringMachineConfig is invalid. idk what AM_AND_LIVE is supposed to mean but it's in the example so I'm using it. If there's only a small number of possible values the documentation should say so..
You need to set content type to 'application/json'.
Old I know, but just ran across it. Perhaps:
'answeringMachineConfig' => 'AM_AND_ALIVE',
should be:
'answeringMachineConfig' => 'AM_AND_LIVE',
You wrote ALIVE instead of LIVE

Authorize.net AIM error. Payment will still proceed even if it's supplied with an invalid billing address

I've tried to update the AVS settings and decline all transactions without or invalid billing address.
I'm trying to fix this issue but still cant figure it out.
Here is my current AVS Settings.
Please take a look at my code and see if there's wrong with it.
$post_url = "https://test.authorize.net/gateway/transact.dll";
$CC_API = "*****";
$CC_KEY = "*****";
$amount = number_format($formData[total_amt],2);
$post_values = array(
// the API Login ID and Transaction Key must be replaced with valid values
"x_login" => $CC_API,
"x_tran_key" => $CC_KEY,
"x_version" => "3.1",
"x_delim_data" => "TRUE",
"x_delim_char" => "|",
"x_relay_response" => "FALSE",
"x_type" => "AUTH_ONLY",
"x_method" => "CC",
"x_card_num" => $formData[cc_num],
"x_exp_date" => $formData[cc_expM].$formData[cc_expY],
"x_amount" => $amount ,
"x_description" => "Test Order",
"x_first_name" => $formData[cc_fname],
"x_last_name" => $formData[cc_lname],
"x_company" => $Data[cust_bill_company_name],
"x_address" => $Data[cust_bill_street_address],
"x_city" => $Data[cust_bill_city],
"x_state" => $Data[cust_bill_state],
"x_zip" => $Data[cust_bill_postcode],
"x_country" => $Data[cust_bill_country],
"x_email" => $Data[cust_email],
//shipping
"x_ship_to_first_name" => $Data[cust_ship_fname],
"x_ship_to_last_name" => $Data[cust_ship_lname],
"x_ship_to_company" => $Data[cust_ship_company_name],
"x_ship_to_address" => $Data[cust_ship_street_address],
"x_ship_to_city" => $Data[cust_ship_city],
"x_ship_to_state" => $Data[cust_ship_state],
"x_ship_to_zip" => $Data[cust_ship_zip],
"x_ship_to_country" => $Data[cust_ship_country]
);
// This section takes the input fields and converts them to the proper format
// for an http post. For example: "x_login=username&x_tran_key=a1B2c3D4"
$post_string = "";
foreach( $post_values as $key => $value )
{ $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );
// This sample code uses the CURL library for php to establish a connection,
// submit the post, and record the response.
// If you receive an error, you may want to ensure that you have the curl
// library enabled in your php configuration
$request = curl_init($post_url); // initiate curl object
curl_setopt($request, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.
$post_response = curl_exec($request); // execute curl post and store results in $post_response
// additional options may be required depending upon your server configuration
// you can find documentation on curl options at http://www.php.net/curl_setopt
curl_close ($request); // close curl object
// This line takes the response and breaks it into an array using the specified delimiting character
$response_array = explode($post_values["x_delim_char"],$post_response);
return ($response_array[0]=="1" && $response_array[1]=="1") ? "ok" : $response_array[3];
The sandbox only simulates a connection to the payment processor. To generate specific error conditions, you'll need to use the error generation guide at http://developer.authorize.net/tools/errorgenerationguide

Sending push notification using parse using query

I want to send push notification using query
for example
I have this query
$ages = array(18,19,20,21)
$parseQuery = new parseQuery('_User');
$parseQuery->whereContainedIn('age', $ages);
$result = $parseQuery->find();
and I want to send them a push notification
Should I use the Installation or is theres another way ?
Thanks
UPDATE:
I am using this sdk
https://github.com/apotropaic/parse.com-php-library
from the code I am returning list of people I am going to send them notification
I want to send the push notifications to the _User class
It looks like you're using parseQuery to retrieve a user with the age constraints you specified. Once you have the user data in your $result, you can use curl to send push notifications, according to the docs.
Here's a bit of code I found on the web, it should be simple to adopt it to your existing code to send a push notification to the user you've retrieved.
<?php
$APPLICATION_ID = "xxxxxxxx";
$REST_API_KEY = "xxxxxxxxx";
$MESSAGE = "your-alert-message";
$url = 'https://api.parse.com/1/push';
$data = array(
'channel' => '',
'type' => 'android',
'expiry' => 1451606400,
'where' => array(
'age' => array('$in' => array(18,19,20,21))
),
'data' => array(
'alert' => 'greetings programs',
),
);
$_data = json_encode($data);
$headers = array(
'X-Parse-Application-Id: ' . $APPLICATION_ID,
'X-Parse-REST-API-Key: ' . $REST_API_KEY,
'Content-Type: application/json',
'Content-Length: ' . strlen($_data),
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_exec($curl);
It's worth noting that you need php-curl for this to work. It's very easy to install or enable if you don't already have it. Alternatively you can use file_get_contents to achieve he same thing if you want to use something out of the box.
Edit: I've updated the $data array with the constraints you defined in the question. You don't need to use parseQuery to find users with the updated code. You're effectively telling Parse to apply the constraints with the call.
Update 2: I haven't tested this code but the library makes it very straightforward how to setup in the README. The library is just using curl underneath so you can use whichever is more convenient.
$parse = new parsePush('Sample push message');
$parse->where = array(
'age' => array('$in' => array(18,19,20,21))
);
//create acl
$parse->ACL = array("*" => array("write" => true, "read" => true));
$r = $parse->send();

PayPal - Instant Payment Notification / doDirectPayment in PHP

I have built a IPN Listener and tested it with the IPN Simulator in sandbox and it works fine, however when I add the "NOTIFYURL" parameter and set it to my IPN Listener I do not get any notifications from my listener, but payment still goes through.
Is there something else I have to do to get this to work?
Here's my codes
My IPN Listener (for the purposes of testing it simply Imports the entire result into a SQL Table)
include "dbconnect.php";
$request = "cmd=_notify-validate";
foreach ($_POST as $varname => $varvalue){
$email .= "$varname: $varvalue\n";
if(function_exists('get_magic_quotes_gpc') and get_magic_quotes_gpc()){
$varvalue = urlencode(stripslashes($varvalue));
}
else {
$value = urlencode($value);
}
$request .= "&$varname=$varvalue";
}
mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$email."')");
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
The portion of my payment processing script that interacts with paypal:
// Store request params in an array
$request_params = array
(
'METHOD' => 'DoDirectPayment',
'USER' => $api_username,
'PWD' => $api_password,
'SIGNATURE' => $api_signature,
'VERSION' => $api_version,
'PAYMENTACTION' => 'Sale',
'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
'CREDITCARDTYPE' => 'Visa',
'ACCT' => '4887864152287206',
'EXPDATE' => '072018',
'CVV2' => '123',
'FIRSTNAME' => 'Tester',
'LASTNAME' => 'Testerson',
'STREET' => '707 W. Bay Drive',
'CITY' => 'Largo',
'STATE' => 'FL',
'COUNTRYCODE' => 'US',
'ZIP' => '33770',
'AMT' => '100.00',
'CURRENCYCODE' => 'USD',
'NOTIFYURL' => 'http://www.mysite.com/ipnlistener.php',
'DESC' => 'Testing Payments Pro'
);
// Loop through $request_params array to generate the NVP string.
$nvp_string = '';
foreach($request_params as $var=>$val)
{
$nvp_string .= '&'.$var.'='.urlencode($val);
}
// Send NVP string to PayPal and store response
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $api_endpoint);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string);
$result = curl_exec($curl);
echo $result.'<br /><br />';
mysql_query("INSERT INTO `test` (`nvps`) VALUES ('".$result."')");
Why aren't I getting my notifications?
Can you take a look at the PHP IPN script over at https://github.com/paypal/ipn-code-samples/blob/master/IPN_PHP.txt?
Leave USE_SANDBOX and USE_DEBUG enabled and create an empty file called 'ipn.txt' in the same directory (writable by the webserver).
This will log all steps of the IPN process (receiving it, posting it back, verifying the results, etc). Should anything, that should make it clear.
the purpose of the ipn listener is for paypal to pass back payment info so you can process it, it will not send you any notifications as such unless you add things like a log file, where each payment status is logged or send email to yourself about processed payments (whether they failed or not)

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