Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript提交PayPal按钮时出现间歇性500错误_Paypal_Paypal Sandbox_Drupal 8 - Fatal编程技术网

使用JavaScript提交PayPal按钮时出现间歇性500错误

使用JavaScript提交PayPal按钮时出现间歇性500错误,paypal,paypal-sandbox,drupal-8,Paypal,Paypal Sandbox,Drupal 8,我正在测试一个基本的PayPal按钮表单,它是用PHP动态创建的,在加载页面时经过短暂的延迟后,用JS提交到沙箱中。大约有一半的时间它工作正常,大约有一半的时间PayPal的响应是500个错误。当我收到错误时,我可以返回浏览器,让它重新提交完全相同的表单,在这一点上,它有时工作,有时出错 任何想法都将不胜感激。这可能是某种饼干问题吗?我已经向PayPal提交了一张罚单——还没有回复。谢谢 编辑:这是相关代码。这是一个Drupal8站点,它位于一个自定义模块中,使用表单API实现多步骤表单buil

我正在测试一个基本的PayPal按钮表单,它是用PHP动态创建的,在加载页面时经过短暂的延迟后,用JS提交到沙箱中。大约有一半的时间它工作正常,大约有一半的时间PayPal的响应是500个错误。当我收到错误时,我可以返回浏览器,让它重新提交完全相同的表单,在这一点上,它有时工作,有时出错

任何想法都将不胜感激。这可能是某种饼干问题吗?我已经向PayPal提交了一张罚单——还没有回复。谢谢

编辑:这是相关代码。这是一个Drupal8站点,它位于一个自定义模块中,使用表单API实现多步骤表单<调用code>buildForm()(然后调用
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);
    ...
}
public function buildForm(数组$form,FormStateInterface$form\u state){
...
//“步骤”3
...
//“步骤”4只是重定向到PayPal
elseif($form_state->get('step')==4){
//在主窗体内容区域打印
$form['redirecting']=数组(
“#键入”=>“html_标记”,
“#标记”=>“div”,
“#value”=>this->t('重定向到贝宝…'),
);
}
...
}
公共函数submitForm(数组和$form,FormStateInterface$form\u state){
...
//在“步骤”3之后调用
//获取刚刚插入数据库的记录的id
$paypal_invoice=$query->execute()->fetchField();
$paypal_item_name='[项目名称]';
$paypal_amount=$form_state->getValue('amount');
$token=bin2hex(openssl_随机_伪_字节(16));
$paypal_html=
'
window.onload=setTimeout(函数(){
document.getElementById(“paypal_表单”).submit();
}, 4000);
';
//确保对html标记进行了评估
$rendered\u message=\Drupal\Core\Render\Markup::create($paypal\u html);
//当使用buildForm()加载“步骤”4时,字符串将添加到表单的消息区域
drupal_设置_消息($rendered_消息);
$form_state->set(['step'],4);
...
}

回答我自己的问题以防对其他人有所帮助:这是一个PayPal沙箱问题

我在PayPal网站上生成了一个等价的按钮表单,在代码之外多次将其提交到沙盒中,并得到了类似的间歇性错误

然后,我将代码中的引用切换到live PayPal信息,运行了多次(没有完成交易),没有出现错误

因此,沙盒配置与实时配置有所不同,并导致了这种情况(可能是内存问题?)。这一定不是一个独特的情况,所以PayPal没有记录沙箱的限制是令人沮丧的。但很高兴它看起来可以继续

编辑:下面是贝宝的回复

我们注意到PayPal沙箱存在一些问题,这些问题会间歇性地导致有效请求失败,并导致500个内部服务器错误。我们的开发人员正在处理这个问题,当问题完全解决后,我将向您提供最新信息

请注意,此问题仅影响沙箱环境。尚未注意到对生产环境的影响

进一步编辑:从贝宝更新

感谢您的耐心,我们在沙箱环境中找到了不稳定的根源

PayPal工程师已经解决了导致频繁内部服务器错误的问题。但是,他们指出,所有请求都应该发送到域。如果您的集成正在发送到(无www),则您可能仍会遇到一些延迟。如果您需要,请更新您的集成,以包括www


回答我自己的问题以防对其他人有所帮助:这是一个PayPal沙箱问题

我在PayPal网站上生成了一个等价的按钮表单,在代码之外多次将其提交到沙盒中,并得到了类似的间歇性错误

然后,我将代码中的引用切换到live PayPal信息,运行了多次(没有完成交易),没有出现错误

因此,沙盒配置与实时配置有所不同,并导致了这种情况(可能是内存问题?)。这一定不是一个独特的情况,所以PayPal没有记录沙箱的限制是令人沮丧的。但很高兴它看起来可以继续

编辑:下面是贝宝的回复

我们注意到PayPal沙箱存在一些问题,这些问题会间歇性地导致有效请求失败,并导致500个内部服务器错误。我们的开发人员正在处理这个问题,当问题完全解决后,我将向您提供最新信息

请注意,此问题仅影响沙箱环境。尚未注意到对生产环境的影响

进一步编辑:从贝宝更新

感谢您的耐心,我们在沙箱环境中找到了不稳定的根源

PayPal工程师已经解决了导致频繁内部服务器错误的问题。但是,他们指出,所有请求都应该发送到域。如果您的集成正在发送到(无www),则您可能仍会遇到一些延迟。如果您需要,请更新您的集成,以包括www


你能分享你的代码吗?你能分享你的代码吗?