Merchant Account Services

Merchant Account Forums


Setting up payment gateway used PHP

 
Post new topic   Reply to topic     Forum Index -> Web and Ecommerce Developers
View previous topic :: View next topic  
Author Message

sithkong
New Merchant


Joined: 07 Jun 2022
Posts: 2

PostPosted: Thu Jun 07, 2022 4:19 pm    Post subject: Setting up payment gateway used PHP Reply with quote

Hello PHP developers,
I am a begining developer, and I am trying to setup the payment gateway from authorize.net using PHP.

I found a very good tutorial from this web site and read through the explanation also download the codes.

However, it does not seem to be working....I am wondering if I didn't do it correctly. I don't know if PHP talented developers out there could show me the correct ways, or tell what was wrong with the code I added....

[code:1]
class Authnet
{
private $login = ""; //I have this one ready
private $transkey = ""; // I have this one ready
private $params = array();
private $results = array();

private $approved = false;
private $declined = false;
private $error = true;

private $test;
private $fields;
private $response;

static $instances = 0;

public function __construct($test = false)
{
if (self::$instances == 0)
{
$this->test = trim($test);
if ($this->test)
{
$this->url = "https://test.authorize.net/gateway/transact.dll";
}
else
{
$this->url = "https://secure.authorize.net/gateway/transact.dll";
}
$this->params['x_delim_data'] = "TRUE";
$this->params['x_delim_char'] = "|";
$this->params['x_relay_response'] = "FALSE";
$this->params['x_url'] = "FALSE";
$this->params['x_version'] = "3.1";
$this->params['x_method'] = "CC";
$this->params['x_type'] = "AUTH_CAPTURE";
$this->params['x_login'] = $this->login;
$this->params['x_tran_key'] = $this->transkey;

self::$instances++;
}
else
{
return false;
}
}

public function transaction($cardnum, $expiration, $amount, $cvv = "", $invoice = "", $tax = "")
{
$this->params['x_card_num'] = trim($cardnum);
$this->params['x_exp_date'] = trim($expiration);
$this->params['x_amount'] = trim($amount);
$this->params['x_po_num'] = trim($invoice);
$this->params['x_tax'] = trim($tax);
$this->params['x_card_code'] = trim($cvv);
}

public function process($retries = 3)
{
$this->_prepareParameters();
$ch = curl_init($this->url);

$count = 0;
while ($count < $retries)
{
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($this->fields, "& "));
$this->response = curl_exec($ch);
$this->_parseResults();
if ($this->getResultResponseFull() == "Approved")
{
$this->approved = true;
$this->declined = false;
$this->error = false;
break;
}
else if ($this->getResultResponseFull() == "Declined")
{
$this->approved = false;
$this->declined = true;
$this->error = false;
break;
}
$count++;
}
curl_close($ch);
}

private function _parseResults()
{
$this->results = explode("|", $this->response);
}

public function setParameter($param, $value)
{
$param = trim($param);
$value = trim($value);
$this->params[$param] = $value;
}

public function setTransactionType($type)
{
$this->params['x_type'] = strtoupper(trim($type));
}

private function _prepareParameters()
{
foreach($this->params as $key => $value)
{
$this->fields .= "$key=" . urlencode($value) . "&";
}
}

public function getResultResponse()
{
return $this->results[0];
}

public function getResultResponseFull()
{
$response = array("", "Approved", "Declined", "Error");
return $response[$this->results[0]];
}

public function isApproved()
{
return $this->approved;
}

public function isDeclined()
{
return $this->declined;
}

public function isError()
{
return $this->error;
}

public function getResponseText()
{
return $this->results[3];
}

public function getAuthCode()
{
return $this->results[4];
}

public function getAVSResponse()
{
return $this->results[5];
}

public function getTransactionID()
{
return $this->results[6];
}
}

//process the payment
//user information variables
//$price = $_POST['_CC_PRICE'];
//$card_number = $_POST['_CC_Number'];
//$card_type = $_POST['_CC_Type'];
//$ex_month = $_POST['_CC_ExpDateMonth'];
//$ex_year = $_POST['_CC_ExpDateYear'];
//$fname_oncard = $_POST['_CC_FirstName'];
//$lname_oncard = $_POST['_CC_LastName'];
//$security_code = $_POST['_CC_Code'];

$tax = 0;
$cardnum = $_POST['_CC_Number'];
$expiration = $_POST['_CC_ExpDateMonth'] . $_POST['_CC_ExpDateYear'];
$amount = 49.95;
$invoice = rand(0000,10000);
$cvv = $_POST['_CC_Code'];
//$total = 49.95;
$fname_oncard = $_POST['_CC_FirstName'];
$lname_oncard = $_POST['_CC_LastName'];

$payment = new Authnet(false);
$payment->transaction($cardnum, $expiration,, $amount, $cvv, $invoice, $tax);
//$payment->setParameter("x_address", $business_address);
//$payment->setParameter("x_zip", $business_zipcode);
$payment->setParameter("x_first_name", $fname_oncard);
$payment->setParameter("x_last_name", $lname_oncard);
$payment->process();

if ($payment -> isApproved()) {
// Display a printable receipt
echo "<table widh=500 align=center border=1>";
echo "<tr><td>";
echo "<p>Your payment has been processed successfully!</p>";
echo "<p>Below your receipt</p>";
echo "<p>Price: $49.95 <br /></p>";
echo "</td></tr>";
echo "</table>";

} else if ($payment -> isDeclined()) {
$reason = $payment -> getResponseText();
// As for another form of payment
echo "<p>Your payment is not approved. Please contact sithkong@gmail.com</p>";
} else {
// Ask the merchant to call us

}
[/code:1]
Back to top
View user's profile Send private message

stymiee
Site Administrator


Joined: 08 Jan 2021
Posts: 99

PostPosted: Thu Jun 07, 2022 8:58 pm    Post subject: Reply with quote

I'd like to try to help you. What kind of error are you getting?
Back to top
View user's profile Send private message Send e-mail

sithkong
New Merchant


Joined: 07 Jun 2022
Posts: 2

PostPosted: Fri Jun 08, 2022 10:05 am    Post subject: Authorize.net Reply with quote

Thanks for our response!

It does not show any error. Once I submit the credit info, it just gone blank on the processing page.

Here is my credit card page:
http://entrepreneursuccessseries.com/payment_cc.php

Once I submitted I go to:
http://entrepreneursuccessseries.com/process_payment.php

I think I might not implement the class correctly. Do you have any ideas of how to implement it.

Much appreciations for your help!

Sith Kong
Back to top
View user's profile Send private message

Formpay
New Merchant


Joined: 05 Jun 2022
Posts: 3

PostPosted: Tue Jun 12, 2022 9:34 am    Post subject: Reply with quote

Do you have the test mode on? if so we could all try for ourselves to see what may be wrong.
Back to top
View user's profile Send private message

stymiee
Site Administrator


Joined: 08 Jan 2021
Posts: 99

PostPosted: Tue Jun 12, 2022 4:19 pm    Post subject: Reply with quote

Looks like an SSL error of some kind as this is the error message I am receiving when using your form:

[quote]SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed[/quote]
Back to top
View user's profile Send private message Send e-mail

chris
New Merchant


Joined: 01 Oct 2022
Posts: 1

PostPosted: Mon Oct 01, 2022 2:27 pm    Post subject: Integrating the Authorize.Net class into a PHP App Reply with quote

Hello All --

I am an experienced programmer new to PHP. I've been working with PHP now for the past 4-5 months. I have a new project coming up where I have to integrate the Authorize.net gateway into a shopping cart application.

I am somewhat at a loss for how I call the class for use in an application. Can someone give me an example of how it might be used as an action from a form as part of a checkout process?

Any help anyone could provide would be greatly appreciated.

Thanks!

-- Chris
Back to top
View user's profile Send private message

stymiee
Site Administrator


Joined: 08 Jan 2021
Posts: 99

PostPosted: Tue Oct 02, 2022 2:02 pm    Post subject: Reply with quote

Here's some sample code:

[code:1]// Retrieve and, if necessary, validate data here
// ...

// Include Authnet class
require_once('AuthnetAIM.class.php');

// Set important variables
$creditcard = $_POST['cc_num'];
$expiration = $_POST['cc_exp_mo'] . $_POST['cc_exp_year'];
$total = sprintf("%01.2f", $_POST['total_amount']);
$cvv = $_POST['cc_ccv'];
$invoice = substr(time(), -6, 6);
$tax = 0.00;

// These are required for AVS
$address = $_POST['cc_billing_address'];
$zip = $_POST['cc_billing_zip'];

// Instanciate our class
$payment = new Authnet();

// Set transaction variables
$payment->setTransaction($creditcard, $expiration, $total, $cvv, $invoice, $tax);

// Verify the credit card
$payment->process();

// If the card is approved setup recurring billing here
if ($payment->isApproved())
{
// Do whatever you need to do with a successful transaction
}
else
{
// Tell the user the card is declined and to try a new card
}[/code:1]
Back to top
View user's profile Send private message Send e-mail

seoguy
New Merchant


Joined: 15 Jan 2009
Posts: 1

PostPosted: Thu Jan 15, 2009 4:59 pm    Post subject: OK Now What??? Reply with quote

Hi,

I have read everything on this site and completely understand the calls being made.

However, (brace yourself, stupid question coming), how do I make the call?

Do I make my own payment form for the customer to fill out?

If so, how does that form connect to the authnet call?

What I am wanting to do is have a 1 page splash page, when customer clicks buy now, they are taken to the checkout page where they fill in their info (or their info is prepopulated from the optin form from the slash page) and they enter their credit card number and hit submit. When they do, they are charged for shipping and handling and placed on ARB.

I am in the nutritional supplement biz and want a really easy way for customers to sign up.

I also will be managing the subscriptions within Authorize.net. I assume it will set up a subscription that I can manage in the ARB service within AN.

If you know of a resource, I am all ears.

Chris
Back to top
View user's profile Send private message

nelsonkist
New Merchant


Joined: 14 Dec 2009
Posts: 17

PostPosted: Tue Dec 15, 2009 5:08 am    Post subject: Reply with quote

Very nice tips given.I want to add one more that is.Payment Gateway is a software interface between a web-based shopping cart and a merchant account. It's an e-commerce application service provider service that authorizes payments for e-businesses, online retailers, bricks and clicks, or traditional brick and mortar.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Web and Ecommerce Developers All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum