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