Reply
Member
Posts: 3
Registered: ‎04-19-2017

Desperately Need PHP Code Samples For Dynamic Pricing

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.

Posts: 2,248
Topics: 51
Kudos: 151
Blog Posts: 64
Registered: ‎12-05-2011

Re: Desperately Need PHP Code Samples For Dynamic Pricing

[ Edited ]

@ssgdev It may help if you provide a more detailed description of what you are trying to accomplish with Authorize.Net.

 

Richard

--------

Webhooks are now available for Authorize.Net

Using SOAP, see our deprecation notice.
Check out Accept.js, our Javascript replacement for DPM.
Pro Tip: Never use test mode in the sandbox, instead use the Testing Guide.
Member
Posts: 3
Registered: ‎04-19-2017

Re: Desperately Need PHP Code Samples For Dynamic Pricing

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?

Highlighted
Posts: 2,248
Topics: 51
Kudos: 151
Blog Posts: 64
Registered: ‎12-05-2011

Re: Desperately Need PHP Code Samples For Dynamic Pricing

@ssgdev

 

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 

--------

Webhooks are now available for Authorize.Net

Using SOAP, see our deprecation notice.
Check out Accept.js, our Javascript replacement for DPM.
Pro Tip: Never use test mode in the sandbox, instead use the Testing Guide.
Member
Posts: 3
Registered: ‎04-19-2017

Re: Desperately Need PHP Code Samples For Dynamic Pricing

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.

Posts: 63
Topics: 0
Kudos: 4
Blog Posts: 0
Ideas: 0
Solutions: 3
Registered: ‎04-28-2017

Re: Desperately Need PHP Code Samples For Dynamic Pricing

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);

 

Powered by NexWebSites.com -
Certified Authorize.net developers