I want to implement 2checkout for my website. I am using a sandbox account and am testing the code on localhost. I have followed this tutorial https://github.com/2Checkout/php-examples. My code is more or less similar to the one on that page but i keep getting an authorization failed even for credit card information whose response is supposed to be a successful authorization. Heres my view that has the form
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h2>Checkout</h2>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<form class="form-horizontal" id="myCCForm" action="<?php echo base_url().'two_checkout/sale';?>" method="post">
<input id="token" name="token" type="hidden" value="">
<input id="order_id" name="order_id" type="hidden" value="<?php echo $order_id;?>">
<div class="form-group">
<label class="col-xs-2">
<span>Card Number</span>
</label>
<div class="col-xs-10">
<input class="form-control" id="ccNo" type="text" size="20" placeholder="Debit/Credit Card Number" value="" autocomplete="off" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-2">
<span>Expiration Date (MM/YYYY)</span>
</label>
<div class="col-md-10">
<div class="row">
<div class="col-xs-3">
<select class="form-control" id="expMonth" required>
<option value="">Month</option>
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
</div>
<div class="col-xs-3">
<input class="form-control" type="text" size="2" id="expYear" placeholder="Year" required>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-xs-2"">
<span>CVV</span>
</label>
<div class="col-xs-4">
<input class="form-control" id="cvv" size="4" type="text" value="" placeholder="Security Code" autocomplete="off" required />
</div>
</div>
<input type="submit" class="btn btn-success" value="Pay Now">
</form>
</div>
</div>
</div>
Heres my sale method that handles the post data
public function sale(){
$order = $this->order_model->getOrderById($this->input->post('order_id'));
if(!$order) redirect('home');
// Your sellerId(account number) and privateKey are required to make the Payment API Authorization call.
Twocheckout::privateKey('my private key');
Twocheckout::sellerId('my seller id');
// If you want to turn off SSL verification (Please don't do this in your production environment)
Twocheckout::verifySSL(false); // this is set to true by default
// To use your sandbox account set sandbox to true
Twocheckout::sandbox(true);
try {
$charge = Twocheckout_Charge::auth(array(
"merchantOrderId" => $this->input->post('order_id'),
"token" => $this->input->post('token'),
"currency" => 'USD',
"total" => number_format($order['total'],2)
));
if ($charge['response']['responseCode'] == 'APPROVED') {
echo "Thanks for your Order!";
echo "<h3>Return Parameters:</h3>";
echo "<pre>";
print_r($charge);
echo "</pre>";
}
} catch (Twocheckout_Error $e) {
print_r($e->getMessage());
}
}//end method sale
I did a vardump on in the sale method just to make sure the token and order_id were not empty and they were in deed not empty, so the data is being posted correctly. Any ideas on what might be the problem?
The form must also pass in the buyer’s name, email, and full billing address. This is because i am using inline checkout. Found the solution to my problem after reading the 2checkout documentation more