1

私はci-merchantライブラリを使用しており、それをうまく統合しており、paypalアカウントの所有者ユーザーでも機能します.しかし、paypalアカウントを持っておらず、私のウェブサイトのみでクレジットカードまたはデビットカードで支払いたいユーザーの処理方法がわかりません* (リダイレクトなし)ペイパルへ) * 何か考えはありますか????これは、コントローラーで通常のペイパル支払いに使用するコードであり、うまく機能します..

    $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 にリクエストを送信する必要があります
  • どちら応答が必要です
  • etc etc 抽象化を遠ざける

これらをどのように処理するかは、ライブラリ自体に固有のものになります。

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 に答える