1

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


    }

4

2 回答 2

0

您可以连接您的商家服务

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

现在在您的表单中,有一个小单选按钮组并要求用户选择贝宝或信用卡/借记卡

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

编辑以回答您的评论

我只是以 Realex 为例

您需要弄清楚两个库的共同点,或者在非常低的抽象层次上弄清楚它们共享什么。

一个例子是

  • 他们需要一个初始化方法来配置选项
  • 他们需要向 API 发送请求
  • 他们需要回应
  • 等等等等继续抽象

你如何处理这些,将是图书馆本身所独有的。

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();
}
于 2013-05-24T14:46:06.353 回答
0

Paypal Express Checkout不支持在您的网站上使用信用卡。它是一个异地网关,因此重定向是强制性的。

您需要探索使用 PayPal Pro、Payflow 或任何数量的其他支持直接在您的网站上接受信用卡的网关(以及随之而来的额外 PCI 要求)。

于 2013-05-26T11:33:36.900 回答