duanmu6752 2018-08-23 12:17 采纳率: 0%
浏览 64

2检查未经授权的错误Laravel

I'm trying to use Sandbox 2checkout API but I'm facing some issues. I am using Laravel as php framework and 2co.min.js to generate the token. When I fill the inputs and press submit I got 'unauthorized'.

I get the seller id from my sandbox account and the public, private key for the API and checked them but I still get this error:

The seller id , public and private keys

The seller id , public and private keys

The HTML CODE

    <form id="myCCForm" class="col-md-6" action="{{ route('pay') }}" method="post">
        @csrf
        <input id="token1" name="token1" type="hidden" value="">
        <div>
            <label>
                <span>Card Number</span>
            </label>
            <input id="ccNo" type="text" size="20" value="" autocomplete="off" required/>
        </div>
        <div>
            <label>
                <span>Expiration Date (MM/YYYY)</span>
            </label>
            <input type="text" size="2" id="expMonth" required/>
            <span> / </span>
            <input type="text" size="2" id="expYear" required/>
        </div>
        <div>
            <label>
                <span>CVC</span>
            </label>
            <input id="cvv" size="4" type="text" value="" autocomplete="off" required/>
            <input type="text" id="billingAddr" name="billingAddr" placeholder="Billing Adr ">
        </div>
        <input type="submit" value="Submit Payment">
    </form>

The JS Code

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
 <script src="https://www.2checkout.com/checkout/api/2co.min.js"></script>

<script>

// Pull in the public encryption key for our environment
// Called when token created successfully.
var successCallback = function (data) {
    var myTokenInput = document.getElementById('token1');

    // Set the token as the value for the token input
    myTokenInput.value = data.response.token.token;

    // IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
    myForm.submit();
};

// Called when token creation fails.
var errorCallback = function (data) {
    if (data.errorCode === 200) {
        console.log(data);
    } else {
        console.log(data);
    }
};

var tokenRequest = function () {
    // Setup token request arguments
    var args = {
        sellerId: "203840804",
        publishableKey: "ACC02BE7-70FC-4AEF-9F75-D592E299DEDA​",
        ccNo: $("#ccNo").val(),
        cvv: $("#cvv").val(),
        expMonth: $("#expMonth").val(),
        expYear: $("#expYear").val(),
        billingAddr: $("#billingAddr").val()
    };

    // Make the token request
    TCO.requestToken(successCallback, errorCallback, args);
};

$(function () {
    // Pull in the public encryption key for our environment
    TCO.loadPubKey('production');

    $("#myCCForm").submit(function (e) {
        e.preventDefault();
        // Call our token request function
        tokenRequest();

        // Prevent form from submitting
        return false;
    });
});

I Need Help Guys

  • 写回答

1条回答 默认 最新

  • douzhi8488 2018-09-07 22:34
    关注

    You need to change the senderId and the publishableKey in your script.

    Change the tokenRequest function to this one:

    var tokenRequest = function () {
        // Setup token request arguments
        var args = {
            sellerId: "901389630",
            publishableKey: "A4B8A470-61A2-470E-9DCB-013A033FD206",
            ccNo: $("#ccNo").val(),
            cvv: $("#cvv").val(),
            expMonth: $("#expMonth").val(),
            expYear: $("#expYear").val(),
            billingAddr: $("#billingAddr").val()
        };
    
        // Make the token request
        TCO.requestToken(successCallback, errorCallback, args);
    };
    

    And like @LahiruTM wrote, change the TCO.loadPubKey('production'); to TCO.loadPubKey('sandbox');

    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch