Nishant Lad
Nishant Lad

Reputation: 616

How to process creditcard payment option on your website (without redirect to paypal) paypalexpressceckout with ci-merchant library

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

Answers (2)

Adrian Macneil
Adrian Macneil

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

Philip
Philip

Reputation: 4592

You could interface your Merchant services

interface merchantServiceInterface
{
    public function initialize();

    public function purchase();

    public function purchase_return();
}

Paypal

class Paypal implements merchantServiceInterface
{
    public function initialize(){}

    public function purchase(){}

    public function purchase_return(){}
}

Credit/Debit Cards

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" />

Merchant Library

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

Controller

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

Edit to answer your comment

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

  • They both need a initialize method to configure options
  • They both need to send a request to an API
  • They both need a responce
  • etc etc keep abstracting away

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

Related Questions