2017-04-24 62 views
1

我正在測試一個基本的PayPal按鈕表單,這個按鈕表單是用PHP動態創建的,並且在頁面加載後經過短暫的延遲後用JS提交給沙盒。大約有一半的時間工作正常,PayPal大約有一半的時間響應500錯誤。當我收到錯誤信息時,我可以回到瀏覽器並讓它重新提交完全相同的表單,此時,它有時會起作用,有時會出錯。使用JavaScript提交PayPal按鈕時發生間歇性500錯誤

任何想法將不勝感激。這可能是某種餅乾問題?我已經向PayPal提交了一張票 - 尚未回覆。謝謝!

編輯:這裏是相關的代碼。這是一個Drupal 8網站,這是一個使用Form API進行多步驟表單的自定義模塊。被稱爲(然後validateForm())然後submitForm()。這種情況下的流程在「步驟」3建立之後開始。客戶點擊「支付」,並調用submitForm()

public function buildForm(array $form, FormStateInterface $form_state) { 
    ... 
    //'step' 3 
    ... 
    //'step' 4 is just to redirect to PayPal 
    elseif ($form_state->get('step') == 4) { 
     //prints in main form content area 
     $form['redirecting'] = array(
      '#type' => 'html_tag', 
      '#tag' => 'div', 
      '#value' => $this->t('Redirecting to PayPal...'), 
     ); 
    } 
    ... 
} 

public function submitForm(array &$form, FormStateInterface $form_state) { 
    ... 
    //called after 'step' 3 
    //gets id of record just inserted into database 
    $paypal_invoice = $query->execute()->fetchField(); 
    $paypal_item_name = '[name of item]'; 
    $paypal_amount = $form_state->getValue('amount'); 
    $token = bin2hex(openssl_random_pseudo_bytes(16)); 

    $paypal_html = 
     '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top" id="paypal_form"> 
      <input type="hidden" name="cmd" value="_xclick"> 
      <input type="hidden" name="business" value="______________"> 
      <input type="hidden" name="lc" value="US"> 
      <input type="hidden" name="invoice" value="' . $paypal_invoice . '"> 
      <input type="hidden" name="item_name" value="' . $paypal_item_name . '"> 
      <input type="hidden" name="amount" value="' . $paypal_amount . '"> 
      <input type="hidden" name="button_subtype" value="services"> 
      <input type="hidden" name="no_note" value="1"> 
      <input type="hidden" name="no_shipping" value="1"> 
      <input type="hidden" name="rm" value="1"> 
      <input type="hidden" name="return" value="http://__________________"> 
      <input type="hidden" name="cancel_return" value="http://______________?cancel=1&token=' . $token . '"> 
      <input type="hidden" name="currency_code" value="USD"> 
     </form> 
     <script type="text/javascript"> 
      window.onload = setTimeout(function() { 
       document.getElementById("paypal_form").submit(); 
      }, 4000); 
     </script>'; 

    //make sure html tags are evaluated 
    $rendered_message = \Drupal\Core\Render\Markup::create($paypal_html); 
    //string will be added to message area of form when 'step' 4 is loaded with buildForm() 
    drupal_set_message($rendered_message); 

    $form_state->set(['step'], 4); 
    ... 
} 
+0

你能分享你的代碼嗎? – bluepnume

回答

0

回答我自己的問題以防別人幫助別人:這是貝寶沙箱問題。

我在PayPal網站上生成了一個等效的按鈕表單,在我的代碼之外多次提交給沙箱,並且得到了類似的間歇性500錯誤。

然後我將代碼中的參考信息切換到現場貝寶信息,多次運行(無需完成交易),並且沒有錯誤。

因此,沙盒配置與實時配置有所不同,並導致此問題(可能是內存問題?)。這不能是一個獨特的情況,所以這是令人沮喪的PayPal不記錄沙箱的限制。但很高興看起來可以繼續前進。

編輯:這裏是貝寶的回覆確認。

我們意識到我們的PayPal沙盒的一些問題,間歇性地導致有效的請求失敗,並出現500內部服務器錯誤。我們的開發人員正在處理這個問題,當問題得到完全解決時,我會向您更新。

請注意,此問題僅影響沙箱環境。沒有注意到生產環境的影響。

更多編輯:從貝寶更新。

感謝您的耐心配合,因爲我們在沙箱環境中追蹤了不穩定的來源。

貝寶工程師已解決導致頻繁發生內部服務器錯誤的問題。但是,他們表示所有請求都應該轉到https://www.sandbox.paypal.com/域。如果您的集成發送到https://sandbox.paypal.com(沒有www),那麼您可能仍然會遇到一些延遲。如果您的情況屬實,請更新您的集成以包含www。

相關問題