繁体   English   中英

PayPal 智能按钮服务器端集成在实时模式下失败

[英]PayPal Smart Buttons Server Side Integration is failing on live mode

我正在 php 中开发一个应用程序,我必须将 PayPal 智能按钮集成到我的应用程序中。 在沙盒模式下一切正常。 但是当我把它转到现场或生产环境时。 它给出了 JSON 错误。

PayPal 智能按钮返回给我 JSON 错误

这个答案在为沙盒和其他所有东西设置环境时帮助了我很多,这真的很好。 但仅适用于沙盒模式!

我检查了 paypal 上的帐户,交易在那里创建,但没有响应发送到服务器进行进一步处理。 说明 API 设置成功,密钥正常。 但唯一的问题是我无法捕获响应并将其发送回服务器这是我的代码

创建贝宝交易。php

public static function createOrder($debug=false)
  {
    $request = new OrdersCreateRequest();
    $request->prefer('return=representation');
    $request->body = self::buildRequestBody();
   // 3. Call PayPal to set up a transaction
    $client = PayPalClient::client();
    $response = $client->execute($request);

    // 4. Return a successful response to the client.
    $json_obj= array('id'=>$response->result->id);
    $jsonstring = json_encode($json_obj);
    echo $jsonstring;
  }

在客户端

createOrder: function() {
      return fetch('payments/create-paypal-transaction.php', {
        method: 'post',
        headers: {
          'content-type': 'application/json'
        },
        body: JSON.stringify($('#form_add').serializeObject())
      }).then(function(res) {
        console.log(res);
        return res.json();
      }).then(function(data) {
        console.log(data);
        return data.id;
      });

我使用 console.log() 来调试服务器响应,但它总是

{
...
ok: true
redirected: false
status: 200
statusText: "OK"
type: "basic"
...
}

控制台也显示以下错误

create_order_error 

click_initiate_payment_reject

Uncaught SyntaxError: Unexpected token < in JSON at position 0

任何帮助,将不胜感激:)

我遇到了同样的问题,我读过你需要将它们重定向到批准 url 像这样

    public static function createOrder($debug=false)
  {
    $request = new OrdersCreateRequest();
    $request->prefer('return=representation');
    $request->body = self::buildRequestBody();

    // 3. Call PayPal to set up a transaction
    $client = PayPalClient::client();
    $response = $client->execute($request);
    $res_links = $response->result->links;
    $approve_index = array_search('approve',array_column($res_links,'rel'));
    redirect($res_links[$approve_index]->href);

    // 4. Return a successful response to the client.
    $json_obj= array('id'=>$response->result->id);
    $jsonstring = json_encode($json_obj);
    echo $jsonstring;
   }

This ends up giving a cors error and when bypassing the cors checking in chrome(which is terrible) it simply closes the checkout popup and the response for the approval url is the html for the page.

在开发控制台的网络选项卡中,检查 create-paypal-transaction.php 文件的响应。 它会给你实际的错误 json > 错误是无关的。 您还可以直接从浏览器访问该文件并查看您遇到的错误。

如果你希望我也在努力让这个工作正常,你可以在 discord 上给我发消息。 红鼓#9269

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM