如何取消条带付款并将钱记入客户帐户

时间:2016-09-24 17:28:47

标签: php stripe-payments

您好我正在使用以下代码进行交易

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 个答案:

答案 0 :(得分: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;