2017-07-31 44 views
0

ストライプでは、テスト番号4000 0000 0000 0341は、Stripe Testing pageごとに「このカードを顧客オブジェクトに接続すると成功しますが、 "私の場合は、このような状況をエラーのように扱い、エラーが発生したことを顧客に報告するのではなく、エラーハンドラに送信します。ストライプ/ PHP:顧客オブジェクトの処理に失敗しましたが、請求が失敗しました(4000000000000341)

私はPHPでこれをやっているので、APIからJSONオブジェクトを取得するのではなく、顧客のPHPオブジェクトを取得しています。私はStripe APIの新機能ですので、ここで何をすべきかわかりません。私はこの状況に関する情報を検索しようとしましたが、役に立たないものは見つかりませんでした。そして、このケースは既存のSOの質問によって処理されたようには見えません。

コードの抜粋は以下のとおりです。お客様に請求されなかった場合は$charge_failedtrueと設定する必要があります。

\Stripe\Stripe::setApiKey(STRIPE_SECRET_KEY); 
// Create a customer. 
try { 
    $customer = \Stripe\Customer::create(array("source" => $my_token, 'email' => $customers_email, "description" => $my_description)); 

    $charge_failed = false; //TODO Set this boolean according to whether the charge passed or failed. 

    if ($charge_failed) { 
     //TODO Report to the user that the charge failed and they need to resubmit. 
     die(); 
    } 
} 
catch(\Stripe\Error\Card $e) { 
    // Card was declined. Report the card declined to the user. 
    die(); 
} 
catch (\Stripe\Error\RateLimit $e) { 
    // Report the error appropriately. 
    die(); 
} catch (\Stripe\Error\InvalidRequest $e) { 
    // Report the error appropriately. 
    die(); 
} catch (\Stripe\Error\Authentication $e) { 
    // Report the error appropriately. 
    die(); 
} catch (\Stripe\Error\ApiConnection $e) { 
    // Report the error appropriately. 
    die(); 
} catch (\Stripe\Error\Base $e) { 
    // Report the error appropriately. 
    die(); 
} catch (Exception $e) { 
    // Report the error appropriately. 
    die(); 
} 

答えて

0

数日前、私はストライプを正常に実装しました。これが助けになることを願って、

if ($params['testmode'] == "on") { 
    \Stripe\Stripe::setApiKey($params['private_test_key']); 
    $pubkey = $params['public_test_key']; 
} else { 
    \Stripe\Stripe::setApiKey($params['private_live_key']); 
    $pubkey = $params['public_live_key']; 
} 

include_once 'Stripe/init.php'; 
include_once 'Stripe/lib/Stripe.php'; 

//Set Stripe keys 
$params = array(
    "testmode" => "off", 
    "private_live_key" => "sk_live_", 
    "public_live_key" => "pk_live_", 
    "private_test_key" => "sk_test_", 
    "public_test_key" => "pk_test_" 
); 

if ($params['testmode'] == "on") { 
    \Stripe\Stripe::setApiKey($params['private_test_key']); 
    $pubkey = $params['public_test_key']; 
} else { 
    \Stripe\Stripe::setApiKey($params['private_live_key']); 
    $pubkey = $params['public_live_key']; 
} 

if (isset($_POST['stripeToken'])) { 
    try { 

     $customer = \Stripe\Customer::create(array(
        'email' => $varUserEmail, 
        'source' => $_POST['stripeToken'] 
       )); 

     $charge = \Stripe\Charge::create(array(
        'customer' => $customer->id, 
        'amount' => $price, 
        'currency' => 'usd', 
        'description' => $description, 
       )); 

     $result = "success"; 
     //Save information in the database and send an email with status 
      //Ends here 
    } catch (\Stripe\Error\Card $e) { 
     $error = $e->getMessage(); 
     $result = "declined"; 
     //Save information in the database and send an email with status 
} 
0

私が間違っている可能性が、私はこのような状況は、すでに既存の顧客オブジェクトを持っていて、その支払い方法を更新しようとしている場合にのみ発生すると考えています。顧客の作成を試みる前に、顧客を作成するために使用しているトークンが無効になり、顧客の作成が失敗します。これが初期料金であれば、javascriptメソッドは失敗を返します。

関連する問題