簡體   English   中英

使用測試信用卡時,PHP解析雲和條帶問題

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

希望您能夠幫助我。 我在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);
                    }
                }
            );
        }

    });

});

我通過php從我的網站調用該函數,如下所示:

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

當信用卡還可以時,這可以正常工作,但是當我使用被拒絕的信用卡來處理錯誤時,即使在登錄Sashido dashboad中看到錯誤,我也無法在php代碼中收到錯誤消息。 這是日志:

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"
}

因此,我無法處理錯誤,而是在瀏覽器中收到HTTP 500錯誤,您有任何線索嗎?

這是處理$ result的方式,並且如果信用卡有效,則可以正常工作,我確實收到訂閱代碼:

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

       echo $results;

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

因此,當我使用4242424242424242信用卡時,我會收到訂閱代碼,但是當我用信用卡號4100000000000019強制輸入錯誤時,我無法收到錯誤消息。

這正是我在ini_set('display_errors',1)中使用PHP顯示錯誤時收到的。 ini_set('display_startup_errors',1); 使用error_reporting(E_ALL);

收到錯誤:

致命錯誤:未捕獲的Parse \\ ParseException:您的卡被拒絕。 在/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

我懷疑問題是您的ParseCloud::run調用不在try-catch塊內。 嘗試這樣的事情:

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