Reputation: 616
I am using ci-merchant library and integrated it succesfully and also works for paypal account owner user.But dont know how to processs for user who dont have paypal acc and wants to pay via credit or debit card on my website only*(without redirect to paypal)* any idea????abt that.....this is the code i use for the normal paypal payment in my controller and works good as well..
$this->load->library('merchant');
$this->merchant->load('paypal_express');
$settings = $this->merchant->default_settings();
$settings = array(
'username' => 'takeout_api1.rest.com',
'password' => '1369227981',
'signature' => 'AnOQDpMvzNQqHN5u7vb9BKLaKYLoALq6R0g3ohOwD4RQgO0DQDI5l7V4',
'test_mode' => true,
);
$this->merchant->initialize($settings);
$params = array(
'amount' => 1500.00,
'currency' => 'CAD',
'return_url' => 'http://192.168.1.7/takeout/order_detail/test',
'cancel_url' => 'http://192.168.1.7/takeout/order_detail/test');
$response = $this->merchant->purchase($params);
function test()
{
$settings = array(
'username' => 'takeout_api1.rest.com',
'password' => '1369227981',
'signature' => 'AnOQDpMvzNQqHN5u7vb9BKLaKYLoALq6R0g3ohOwD4RQgO0DQDI5l7V4',
'test_mode' => true);
$this->merchant->initialize($settings);
$params = array(
'amount' => 1500.00,
'currency' => 'CAD',
'return_url' => 'http://192.168.1.7/takeout/order_detail/test',
'cancel_url' => 'http://192.168.1.7/takeout/order_detail/test');
$response = $this->merchant->purchase_return($params);
if ($response->success())
{
// mark order as complete
echo "yo";
exit;
}
else
{
$message = $response->message();
echo('Error processing payment: ' . $message);
exit;
}
}
Upvotes: 1
Views: 2674
Reputation: 13263
Paypal Express Checkout doesn't support taking credit cards on your site. It is an off-site gateway, so redirect is mandatory.
You need to explore using PayPal Pro, Payflow, or any number of other gateways which support accepting credit cards directly on your website (plus the extra PCI requirements which come with that).
Upvotes: 0
Reputation: 4592
interface merchantServiceInterface
{
public function initialize();
public function purchase();
public function purchase_return();
}
class Paypal implements merchantServiceInterface
{
public function initialize(){}
public function purchase(){}
public function purchase_return(){}
}
class Realex implements merchantServiceInterface
{
public function initialize(){}
public function purchase(){}
public function purchase_return(){}
}
Now in your form, have a little radio button group and ask the user to select either paypal or credit/debit card
<label>Choose a payment Method</label>
<label>Paypal<label>
<input type="radio" name="merchant" value="paypal" />
<label>Credit/Debit Card<label>
<input type="radio" name="merchant" value="debit" />
class Merchant
{
protected $_service;
public function __construct(merchantServiceInterface $service)
{
$this->_service = $service;
}
public function initialize()
{
// Will either run Paypal/Realex initialize()
// Depending on what instance was passed to _service
//
$this->_service->initialize();
}
}
class Controller extends CI_Controller
{
public function method()
{
if($this->input->post('merchant') == 'paypal')
{
$service = new Paypal();
}
elseif($this->input->post('merchant') == 'debit')
{
$service = new Realex();
}
$this->load->library('Merchant', $service);
$this->merchant->initialize();
}
}
I just used Realex as an example
You need to figure out what both libraries have in common, or at a very low level abstraction figure out what they share.
an example would be
How you handle these, will be unique to the library itself.
interface merchantServiceInterface
{
// Use the facade design pattern here
// so configuration is done in each library
public function initialize();
// Send a request with data
// Paypal - use http_build_query and curl
// Realex - use xml and curl
public function request(array $data);
public function responce();
}
Upvotes: 0