简体   繁体   English

使用测试信用卡时,PHP解析云和条带问题

[英]Problem with PHP Parse Cloud and Stripe when using Testing Credit Cards

Hope you can help me. 希望您能够帮助我。 I have a Parse Cloud function in Sashido (Parse Server) to manage a Stripe Subscription as following: 我在Sashido(Parse Server)中具有一个Parse Cloud功能来管理Stripe Subscription,如下所示:

var stripe = require("stripe")("sk_test_CCCCccCCXXXXXXxXXX");
Parse.Cloud.define("crearCargo", function(request, response) {
    var  token = request.params.stripeToken;
    var  mail = request.params.email;
//var mail = request.params.email;

    //Crear Customer
    const customer = stripe.customers.create({
        email: mail,
        source: token,
    }, function(err, customer) {
        // asynchronously called
        if(err){
            response.error("Fallo Customer");
        }else{
           //const{id} = customer;
            id = customer.id;
            stripe.subscriptions.create({

                    customer: id,
                    items: [
                        {
                            plan: "plan_E0jrObw8X7Le2F",

                        },
                    ]
                }, function(err, subscription) {
                    if(err){
                        response.error(err.message);
                    }else{                        
                        response.success(subscription.id);
                    }
                }
            );
        }

    });

});

I call that function from my site via php like this: 我通过php从我的网站调用该函数,如下所示:

$results = ParseCloud::run("crearCargo", ["stripeToken" => "$stripeToken", "email" => "$email"]);

This works fine when credit card is ok, but when I use a declined credit card to deal with the errors, I cant get error message in my php code, eventhough I see the error in the Log in Sashido dashboad. 当信用卡还可以时,这可以正常工作,但是当我使用被拒绝的信用卡来处理错误时,即使在登录Sashido dashboad中看到错误,我也无法在php代码中收到错误消息。 This is the log: 这是日志:

Failed running cloud function crearCargo for user undefined with:
  Input: {"stripeToken":"tok_1DaoDfHWMeJb0DRPDaAgN7rS","email":"shisuka11.08@gmail.com"}
  Error: {"code":141,"message":"Your card was declined."}
Nov 26, 2018, 12:50:44 -05:00 - ERROR
Error generating response for [POST] /1//functions/crearCargo 
"Your card was declined."

{
  "stripeToken": "tok_1DaoDfHWMeJb0DRPDaAgN7rS",
  "email": "myemail@email.com"
}

So I havent been able to deal with errors and instead I receeve a HTTP 500 ERROR in my browser, Do you have any clues why? 因此,我无法处理错误,而是在浏览器中收到HTTP 500错误,您有任何线索吗?

This is how a deal with the $result and works fine if credit card is valid, I do recieve the subscription code: 这是处理$ result的方式,并且如果信用卡有效,则可以正常工作,我确实收到订阅代码:

try {
    if(substr( $results, 0, 3 ) === "sub"){

       echo $results;

   }
} catch (ParseException $e) {
      echo 'Caught exception: '.$e->getMessage()."\n";
}

So when I use a 4242424242424242 credit card I do recieve subcription code, but when I force an error with credit card number 4100000000000019, I cant get error message back. 因此,当我使用4242424242424242信用卡时,我会收到订阅代码,但是当我用信用卡号4100000000000019强制输入错误时,我无法收到错误消息。

This is exactly what I received when I use PHP display error with ini_set('display_errors', 1); 这正是我在ini_set('display_errors',1)中使用PHP显示错误时收到的。 ini_set('display_startup_errors', 1); ini_set('display_startup_errors',1); error_reporting(E_ALL); 使用error_reporting(E_ALL);

Error recieved: 收到错误:

Fatal error: Uncaught Parse\\ParseException: Your card was declined. 致命错误:未捕获的Parse \\ ParseException:您的卡被拒绝。 in /home/u940759797/domains/powersellapp.com/public_html/web/Modelo/src/Parse/ParseClient.php:357 Stack trace: #0 /home/u940759797/domains/powersellapp.com/public_html/web/Modelo/src/Parse/ParseCloud.php(32): Parse\\ParseClient::_request('POST', 'functions/crear...', NULL, '{"stripeToken":...', false) #1 /home/u940759797/domains/powersellapp.com/public_html/web/Modelo/suscripcion.php(28): Parse\\ParseCloud::run('crearCargo', Array) #2 {main} thrown in /home/u940759797/domains/powersellapp.com/public_html/web/Modelo/src/Parse/ParseClient.php on line 357 在/home/u940759797/domains/powersellapp.com/public_html/web/Modelo/src/Parse/ParseClient.php:357中的堆栈跟踪:#0 /home/u940759797/domains/powersellapp.com/public_html/web/Modelo/src /Parse/ParseCloud.php(32):Parse \\ ParseClient :: _ request('POST','functions / crear ...',NULL,'{“ stripeToken”:...',false)#1 / home / u940759797 / domains / powersellapp.com / public_html / web / Modelo / suscripcion.php(28):Parse \\ ParseCloud :: run('crearCargo',Array)#2 {main}丢在/ home / u940759797 / domains / powersellapp中。 357行上的com / public_html / web / Modelo / src / Parse / ParseClient.php

I suspect the issue is your ParseCloud::run call is not within your try-catch block. 我怀疑问题是您的ParseCloud::run调用不在try-catch块内。 Try something like this: 尝试这样的事情:

try {
  $results = ParseCloud::run("crearCargo", ["stripeToken" => "$stripeToken", "email" => "$email"]);
} 
catch(ParseException $e) {
  echo 'Caught exception: '.$e->getMessage()."\n";
}
catch(Exception $e) {
  // do something with other exceptions, for testing we'll just print it out
  print_r($e);
}

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

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