Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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 条带API状态200正常无创建事件_Javascript_Php_Wordpress_Api_Stripe Payments - Fatal编程技术网

Javascript 条带API状态200正常无创建事件

Javascript 条带API状态200正常无创建事件,javascript,php,wordpress,api,stripe-payments,Javascript,Php,Wordpress,Api,Stripe Payments,我正在使用带测试密钥的条带API。我已将付款表单成功发布到Stripe API端点,但未创建任何事件。当我检查条带事件/日志时,我能够在我提交的测试付款的日志选项卡下看到200-Ok成功消息,但是事件选项卡仍然为空。我似乎无法理解这一点。我的代码如下 以下是我处理付款的php: function wpay_stripe_process_payment() { if(isset($_POST['action']) && $_POST['action'] == 'stripe

我正在使用带测试密钥的条带API。我已将付款表单成功发布到Stripe API端点,但未创建任何事件。当我检查条带事件/日志时,我能够在我提交的测试付款的日志选项卡下看到200-Ok成功消息,但是事件选项卡仍然为空。我似乎无法理解这一点。我的代码如下

以下是我处理付款的php:

function wpay_stripe_process_payment() {
    if(isset($_POST['action']) && $_POST['action'] == 'stripe' && wp_verify_nonce($_POST['stripe_nonce'], 'stripe-nonce')) {

        global $stripe_options;

        // load the stripe libraries
        require_once(STRIPE_BASE_DIR . '/lib/Stripe.php');

        // retrieve the token generated by stripe.js
        $token = $_POST['stripeToken'];

        // check if we are using test mode
        if(isset($stripe_options['test_mode']) && $stripe_options['test_mode']) {
            $secret_key = $stripe_options['test_secret_key'];
        } else {
            $secret_key = $stripe_options['live_secret_key'];
        }

        // attempt to charge the customer's card
        try {
            Stripe::setApiKey($secret_key);
            $charge = Stripe_Charge::create(array(
                    'amount' => 1000, // $10
                    'currency' => 'usd',
                    'card' => $token
                )
            );


            // redirect on successful payment
            $redirect = add_query_arg('payment', 'paid', $_POST['redirect']);

        } catch (Exception $e) {
            // redirect on failed payment
            $redirect = add_query_arg('payment', 'failed', $_POST['redirect']);
        }

        // redirect back to our previous page with the added query variable
        wp_redirect($redirect); exit;
    }
}
add_action('wpay_stripe_process_payment');
以下是我发送付款信息的js:

Stripe.setPublishableKey(stripe_vars.publishable_key);

function stripeResponseHandler(status, response) {
    if (response.error) {
        // show errors returned by Stripe
        jQuery(".payment-errors").html(response.error.message);
        // re-enable the submit button
        jQuery('#stripe-submit').attr("disabled", false);
    } else {
        var form$ = jQuery("#stripe-payment-form");
        // token contains id, last4, and card type
        var token = response['id'];
        // insert the token into the form so it gets submitted to the server
        form$.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");
        // and submit
        form$.get(0).submit();
    }
}
jQuery(document).ready(function($) {
    $("#stripe-payment-form").submit(function(event) {
        // disable the submit button to prevent repeated clicks
        $('#stripe-submit').attr("disabled", "disabled");

        // send the card details to Stripe
        Stripe.createToken({
            number: $('.card-number').val(),
            cvc: $('.card-cvc').val(),
            exp_month: $('.card-expiry-month').val(),
            exp_year: $('.card-expiry-year').val()
        }, stripeResponseHandler);

        // prevent the form from submitting with the default action
        return false;
    });
});

您的条带标记位于
response.id
,而不是
response['id']

// token contains id, last4, and card type
var token = response.id;

响应是一个JSON对象,因此您必须像遍历任何其他js对象一样遍历该对象。

根据Stripe文档,在我看来,您似乎没有为令牌提供正确的密钥:

这:

应该是这样的:

$charge = Stripe_Charge::create(array(
    'amount' => 1000, // $10
    'currency' => 'usd',
    'source' => $token
));
对我来说,我使用的是他们提供的Stripe PHP库,而不是:

Stripe_Charge::create(...);
我正在使用:

\Stripe\Charge::create(...);

但我真的认为问题可能是你在充电时需要使用“源”,而不是“卡”。

你能在200-OK日志中添加JSON响应吗?@spartacus我已经用JSON响应更新了帖子。实际上,响应['id']工作正常。我这样使用它没有问题。我的前端的条带API使用括号表示法失败。然而,我认为你的回答可能触及了真正的问题。它应该是(在PHP中)“源代码”,而不是“卡片”。向上投票你的答案。事实上,既然你提到了它,它应该是response.id。甚至条纹文档也显示了这一点。我也投票给你了。这是相关的,应该得到解决。
Stripe_Charge::create(...);
\Stripe\Charge::create(...);