Can anyone please provide some php code samples for dynamic pricing? We have been stuck on this for over a month and it's nowhere to be found in the documentation. Please if you can give, post a reply. Thank you.
04-19-2017 05:11 PM
@ssgdev It may help if you provide a more detailed description of what you are trying to accomplish with Authorize.Net.
Richard
04-19-2017 06:58 PM - edited 04-19-2017 06:59 PM
We are going to create invoices for our customers. So, we need to create dynamic pricing. For example, suppose one customer needs to pay $50, another needs to pay $96, and another needs to pay $76 etc., For this we need to send the price details to Authorize.net. How do send it? For that, we need step by step process flow with sample code. Can you please provide?
04-20-2017 10:01 AM
Our PHP SDK and sample code allows you to accept payment, but we don't offer code to implement sending invoices and presenting a payment page to the user in response to the invoice. Instead, you'll need to create that interim page within your own code.
Richard
04-20-2017 12:40 PM
After going through the php sdk sample, we found it is in pure php. We are working within "CodeIgniter" web framework (CI). This means for us it needs to be converted in php CodeIgniter. Do you have any specific relevant instructions on php CodeIgniter? This is where we are currently stuck.
04-27-2017 11:25 AM
Using the Authorize.net payment gateway in PHP is an easy task. All you need is the official PHP SDK and the code below. You can implement it as a standalone application or integrate with frameworks like Laravel, Codeigniter, and others.
If using composer, add the following to your composer.json file
{ "require": { "php": ">=5.5", "ext-curl": "*", "phpunit/phpunit": "~4.8||~6.0", "authorizenet/authorizenet": "1.9.3" }, "autoload": { "classmap": ["constants"] } }
Run composer install.
Once this process is completed, you should have a vendor folder created in your project directory.
Alternatively, you can download the Authorize.net PHP SDK. Extract it to your project directory and run composer update command.
require 'vendor/autoload.php'; use net\authorize\api\contract\v1 as AnetAPI; use net\authorize\api\controller as AnetController;
If your not using Composer. Authorize.net provides a custom SPL autoloader. Just download the SDK and point to its autoload.php file with:
require 'path/to/anet_php_sdk/autoload.php';
Go to the constants directory and open up the constants.php file. Set the up login_id and transaction_key that you have with your Authorize.net sandbox account.
<?php
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function chargeCreditCard($amount) {
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(\SampleCode\Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(\SampleCode\Constants::MERCHANT_TRANSACTION_KEY);
$refId = 'ref' . time();
//While testing, create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber("4111111111111111");
$creditCard->setExpirationDate("1227");
$creditCard->setCardCode("123");
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
$order = new AnetAPI\OrderType();
$order->setDescription("New Order Description");
//create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setOrder($order);
$transactionRequestType->setPayment($paymentOne);
//Prepare customer information object from your form $_POST data
$cust = new AnetAPI\CustomerAddressType();
$cust->setFirstName($_POST['fname']);
$cust->setLastName($_POST['lname']);
$cust->setAddress($_POST['address']);
$cust->setCity($_POST['city']);
$cust->setState($_POST['state']);
$cust->setCountry($_POST['country']);
$cust->setZip($_POST['zip']);
$cust->setPhoneNumber($_POST['phone']);
$cust->setEmail("Email-here");
$transactionRequestType->setBillTo($cust);
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId($refId);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
//Get response from Authorize.net
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
if ($response != null) {
if ($response->getMessages()->getResultCode() == \SampleCode\Constants::RESPONSE_OK) {
$tresponse = $response->getTransactionResponse();
if ($tresponse != null && $tresponse->getMessages() != null) {
echo " Transaction Response code : " . $tresponse->getResponseCode() . "\n";
echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
echo "Charge Credit Card TRANS ID : " . $tresponse->getTransId() . "\n";
echo " Code : " . $tresponse->getMessages()[0]->getCode() . "\n";
echo " Description : " . $tresponse->getMessages()[0]->getDescription() . "\n";
} else {
echo "Transaction Failed \n";
if ($tresponse->getErrors() != null) {
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
}
}
} else {
echo "Transaction Failed \n";
$tresponse = $response->getTransactionResponse();
if ($tresponse != null && $tresponse->getErrors() != null) {
echo " Error code : " . $tresponse->getErrors()[0]->getErrorCode() . "\n";
echo " Error message : " . $tresponse->getErrors()[0]->getErrorText() . "\n";
} else {
echo " Error code : " . $response->getMessages()->getMessage()[0]->getCode() . "\n";
echo " Error message : " . $response->getMessages()->getMessage()[0]->getText() . "\n";
}
}
} else {
echo "No response returned \n";
}
return $response;
}
$amount = \SampleCode\Constants::SAMPLE_AMOUNT;
if (!empty($_POST['amount']))
$amount = $_POST['amount'];
if (!defined('DONT_RUN_SAMPLES'))
chargeCreditCard($amount);
04-28-2017 01:49 PM
Please please PLEASE provide an example of what you're talking about when you say "Using the Authorize.net payment gateway in PHP is an easy task. All you need is the official PHP SDK and the code below. You can implement it as a standalone application or integrate with frameworks like Laravel, Codeigniter, and others." I have been writing PHP for over 10 years and I've never had to install anything like an SDK, nor have I heard of anything like Composer, Laravel, or the sort.
Is there anywhere at all which can explain what the heck we're supposed to do with Composer or anything to "install" the "SDK" so we can use it? It seems to be the first step in any tutorial I've found on Authorize.net and nowhere does it actually explain this step! It's infuriating!
Secondly, can we just to something simple, like move a bunch of files to our FTP and accomplish this same task?
(I don't like Authorize and its lack of support. That's why we usually just go with another company for money exchanges, but every so often, like now, I revisit Authorize and try to get it working.)
02-08-2019 01:15 PM
Hi @bparker
Have a look at our sample code and SDK in PHP for more details
https://github.com/AuthorizeNet/sample-code-php
https://github.com/AuthorizeNet/sdk-php
Thanks
Anurag
02-08-2019 02:09 PM
Thanks, but I've seen those already. They're scripts, sure, but where do I start? It doesn't look like there's a file with the actual front end form where I'd begin.
Also, what would I do with these? Download the zip and store them on my FTP? I've tried it with the one set of files and it looked like certain files were referencing things not supplied in the download, so maybe I'm missing something?
02-11-2019 06:24 AM - edited 02-11-2019 06:25 AM
02-12-2019 08:46 AM - edited 02-12-2019 08:47 AM