2016-09-24 74 views
1

你好我使用下面的交易代碼如何取消條紋支付和借記錢給客戶帳戶

require_once('Stripe/lib/Stripe.php'); 
    Stripe::setApiKey("<Api key>"); 

    $customer = Stripe_Charge::create(array(
    "amount" => 1500, 
    "currency" => "usd", 
    "card" => $_POST['stripeToken'], 
    "description" => "Charge for Facebook Login code." 
)); 
echo "<pre>";print_r($customer);die; 

// Charge the Customer instead of the card 
$charge = Stripe_Charge::create(array(
    "amount" => 1500, 
    "currency" => "usd", 
    "customer" => $customer->id) 
); 
echo 'Transaction Id '.$charge->id; 

我有一個取消按鈕,如果我點擊的是哪個用戶完成付款將恢復返回客戶帳戶

回答

1

您很可能需要退還您從卡上收取的款項,然後讓取消按鈕對客戶運行收費。

這是可以實現如下:

(1)檢索的電荷的標識符:

$charge = \Stripe\Charge::create(array(
    ... 
)); 

// you can use the var_dump function to see what's inside the $charge object 
// var_dump($charge); 

$chargeID = $charge->id; 

(2)退款用戶:

$re = \Stripe\Refund::create(array(
    "charge" => $chargeID 
)); 

(3)充電客戶相反:

// Charge the Customer instead of the card 
$charge = Stripe_Charge::create(array(
    "amount" => 1500, 
    "currency" => "usd", 
    "customer" => $customer->id) 
); 
echo 'Transaction Id '.$charge->id;