2015-01-12 3 views
1

스트라이프를 사용하여 지불 게이트웨이를 만들고 싶습니다. 여기 내 코드가있다. config 파일과 우선 confiig 파일에 스트라이프 라이브러리를 추가합니다. 나는 토큰을 원해. 스트라이프에서 토큰을 만들거나 생성하려면 어떻게합니까?스트라이프 지불 게이트웨이에서 토큰을 생성하는 방법

<?php 
require_once('./lib/Stripe.php'); 

$stripe = array(
    secret_key  => 'sk_test_SrG9Yb8SrhcDNkqsGdc5eKu1', 
    publishable_key => 'pk_test_8ZBVXSwrHDKuQe6dgMNfk8Wl' 
); 

Stripe::setApiKey($stripe['secret_key']); 
?> 


<?php require_once('config.php'); ?> 

<form action="charge.php" method="post"> 
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" 
data-key="<?php echo $stripe['publishable_key']; ?>" 
data-amount="5000" data-description="One year's subscription"></script> 
</form> 


<?php require_once('config.php'); ?> 

<form action="charge.php" method="post"> 
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" 
data-key="<?php echo $stripe['publishable_key']; ?>" 
data-amount="5000" data-description="One year's subscription"></script> 
</form> 
+0

이 섹션을 살펴 보셨습니까? https://stripe.com/docs/api/php#tokens? bankaccount 및 카드에 대한 예가 있습니다. – RST

답변

3

이 코드는 해당 API Documentation에 있습니다.

당신은 당신의 charge.php에이 코드를 넣어 시도해야

// Set your secret key: remember to change this to your live secret key in production 
// See your keys here https://dashboard.stripe.com/account 
Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2"); 

// Get the credit card details submitted by the form 
$token = $_POST['stripeToken']; 

// Create the charge on Stripe's servers - this will charge the user's card 
try { 
    $charge = Stripe_Charge::create(array(
     "amount" => 1000, // amount in cents, again 
     "currency" => "usd", 
     "card" => $token, 
     "description" => "[email protected]") 
    ); 
} catch(Stripe_CardError $e) { 
    // The card has been declined 
} 

는 여전히이 토큰

7
require_once('../lib/Stripe.php'); 
       Stripe::setApiKey("sk_test_SrG9Yb8SrhcDNkqsGdc5eKu1"); 

       $result = Stripe_Token::create(
        array(
         "card" => array(
          "name" => $user['name'], 
          "number" => base64decrypt($user['card_number']), 
          "exp_month" => $user['month'], 
          "exp_year" => $user['year'], 
          "cvc" => base64decrypt($user['cvc_number']) 
         ) 
        ) 
       ); 

       $token = $result['id']; 

       $charge = Stripe_Charge::create(array(
         "amount" => $data_input['amount']*100, 
         "currency" => "usd", 
         "card" => $token, 
         "description" => "Charge for [email protected]" 
       )); 
+0

이 질문에 대한 답변을 찾았습니다 이 방법을 사용하면 강제로 스트립 지불 게이트웨이를 사용하기 위해 키를 생성 할 수있는 사용자를 생성 할 수 없습니다 ... –

0

당신은 자신의 문서를 확인할 수 있습니다 잡기 위해 문제가 있다면 알려주세요 . 이 페이지에서 그들은

https://stripe.com/docs/api#token_object 
1

스트라이프 3.12에 대한 업데이트 (자신의 단계별 가이드에 가리 켰을 때, 그리고뿐만 아니라 자바 스크립트, 등등 자바, PHP 등) 다른 언어로 토큰을 얻을하는 방법을 보여줍니다. 0

namespace Stripe; 

require_once('stripe-php-3.12.0/vendor/autoload.php'); 
require_once('stripe-php-3.12.0/lib/Stripe.php'); 


Stripe::setApiKey("yourAPIKey"); 

// Get the credit card details submitted by the form 

$status; 

if(isset($_POST['amount']) 
{ 
    $amount = $_POST['amount'] * 100; 


$token = Token::create(
        array(
          "card" => array(
          "name" => $user['name'], 
          "number" => $user['card_number'], 
          "exp_month" => $user['month'], 
          "exp_year" => $user['year'], 
          "cvc" => $user['cvc_number'] 
         ) 
        ) 
       ); 


// Create the charge on Stripe's servers - this will charge the user's card 

try { 
    $charge = Charge::create(array(

    "amount" => $amount , // amount in cents, again 
    "currency" => "usd", 
    "source" => $token, 
    "description" => "Example charge" 
    ));} catch(Error\Card $e) { 

     $status = "error: " . $e; 

} catch(Error\Card $e) { 
    // The card has been declined 

    $status = "declined: " . $e; 
} 
} 
else 
{ 
    //echo "missing params"; 

    $status = "missing params"; 
} 
관련 문제