2checkout授权失败

时间:2016-12-31 10:05:17

标签: php codeigniter 2checkout

我想为我的网站实施2checkout。我正在使用沙盒帐户并在localhost上测试代码。我已经按照本教程https://github.com/2Checkout/php-examples进行了操作。 我的代码或多或少类似于该页面上的代码,但即使对于响应应该是成功授权的信用卡信息,我仍然获得授权失败。 继承了我的观点

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

继承我处理发布数据的销售方法

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

我在销售方法中做了一个vardump,只是为了确保令牌和order_id不是空的,并且他们的行为不是空的,所以数据正在正确发布。关于可能出现什么问题的任何想法?

1 个答案:

答案 0 :(得分:0)

表格还必须传递买家的姓名,电子邮件和完整的帐单地址。这是因为我使用内联结帐。阅读2checkout documentation更多

后,找到了我的问题的解决方案
 "billingAddr" => array(
        "name" => 'Testing Tester',
        "addrLine1" => '123 Test St',
        "city" => 'Columbus',
        "state" => 'OH',
        "zipCode" => '43123',
        "country" => 'USA',
        "email" => 'example@2co.com',
        "phoneNumber" => '555-555-5555'
    )