2016-11-10 9 views
0

私はストーリーに喜んでトークンを作成し、それを私のPHPチャージスクリプトに送ります。この時点で、ストライプコントロールパネルに200 OK - Tokenログが作成されます。それはちょうど私がすべてを正しく行ったことがわかる限り、私はPHPやStripe APIから、エラーを取得していない限り、カードを充電することはありません。ストライプがカードにチャージしていない

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

$error = 0; 

require_once('stripe-php-master/init.php'); 

$trialAPIKey = "sk_test_???"; // These are the SECRET keys! 
$liveAPIKey = "sk_live_???"; 

\Stripe\Stripe::$apiBase = "https://api-tls12.stripe.com"; 

// Switch to change between live and test environments 

\Stripe\Stripe::setApiKey($trialAPIKey); 
/* \Stripe\Stripe::setApiKey($liveAPIKey); */ 

$token = $_POST['token']; 
$price = $_POST['amount']; 
$price = $price * 100; 
$desc = $_POST['desc']; 

try { 
    $charge = \Stripe\Charge::create(array(
    "amount" => $price, 
    "currency" => "gbp", 
    "source" => $token, 
    "description" => $desc 
    )); 
} catch(\Stripe\Error\Card $e) { 
    // The card has been declined 
    $error++; 
} 

if($error>=1) { 
    echo "There was an error processing your card, please try again."; 
} else { 
    echo "Thank you, your payment was successful."; 
} 

答えて

0

sucessfull電荷をストライプするために、このコードを使用してください。

<?php 
require_once("stripe2/init.php"); 
$card_no = '4242 4242 4242 4242'; 
$card_exp = '05/20'; 
$card_cvc = '123'; 
$token = createstripetoken($card_cvc,$card_exp,$card_no); 
$testcharge = charges(10,$token); 
echo $testcharge; 

function charges($amount,$token) 
{ 
$charge = \Stripe\Charge::create(array(
"amount" => $amount * 100, 
"currency" => "usd", 
"source" => $token, 

)); 
$succes = 'your one time charges successfully'; 
return $succes; 
} 
function createstripetoken($card_cvc,$card_exp,$card_no) 

{ 

    $exp_month = substr($card_exp,0,2); 

    $exp_year = substr($card_exp,5,2); 


    \Stripe\Stripe::setApiKey("your key here"); 



    $data = \Stripe\Token::create(array(

    "card" => array(

    "number" => $card_no, 

    "exp_month" => $exp_month, 

    "exp_year" => $exp_year, 

    "cvc" => $card_cvc 

    ) 

    )); 

    $response = json_decode(json_encode($data), True); 

$token = $response['id']; 
return $token; 
    } 
    ?> 
関連する問題