我正在为移动应用程序实施REST API,我需要在其中实现功能,以便直接向客户付款到他们的银行帐户。我已经集成了Stripe支付网关来完成提供功能的支付流程 向已连接的Stripe帐户的银行帐户或借记卡发起付款。
<?php
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("sk_test_tD8Pxvmv2sOhucPuhqvPDvSP");
$error = '';
$success = '';
if ($_POST) {
try {
if (!isset($_POST['stripeToken']))
throw new Exception("The Stripe Token was not generated correctly");
$payment_result=\Stripe\Charge::create(array("amount" => 2000,
"currency" => "usd",
"card" => $_POST['stripeToken']));
$success = 'Your payment was successful.';
}
catch (Exception $e) {
$error = $e->getMessage();
}
}
try{
$Account=\Stripe\Account::create(array(
"type" => "custom",
"country" => "US",
"email" => "demo3455675666gfg5@info.com"
));
if($Account!=NULL){
$TokenInfo=\Stripe\Token::create(array(
"bank_account" => array(
"country" => "US",
"currency" => "usd",
"account_holder_name" => "Mason Wilson",
"account_holder_type" => "individual",
"routing_number" => "110000000",
"account_number" => "000123456789"
)
));
$external_account_info=$Account->external_accounts->create(array("external_account" => $TokenInfo->id));
$payout_response=\Stripe\Payout::create(array(
"amount" => 400,
"currency" => "usd",
"destination"=>$external_account_info->id
));
}
}
catch(Exception $e)
{
echo $e->getMessage();exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<script type="text/javascript" src="https://js.stripe.com/v1/"></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
// this identifies your website in the createToken call below
Stripe.setPublishableKey('pk_test_W2y6W7HcwlV02a8MuCQUHnDn');
function stripeResponseHandler(status, response) {
if (response.error) {
// re-enable the submit button
$('.submit-button').removeAttr("disabled");
// show the errors on the form
$(".payment-errors").html(response.error.message);
} else {
var form$ = $("#payment-form");
// token contains id, last4, and card type
var token = response['id'];
// insert the token into the form so it gets submitted to the server
form$.append("<input type='hidden' name='stripeToken' value='" + token + "' />");
// and submit
form$.get(0).submit();
}
}
$(document).ready(function() {
$("#payment-form").submit(function(event) {
// disable the submit button to prevent repeated clicks
$('.submit-button').attr("disabled", "disabled");
// createToken returns immediately - the supplied callback submits the form if there are no errors
Stripe.createToken({
number: $('.card-number').val(),
cvc: $('.card-cvc').val(),
exp_month: $('.card-expiry-month').val(),
exp_year: $('.card-expiry-year').val()
}, stripeResponseHandler);
return false; // submit from callback
});
});
</script>
</head>
<body>
<h1>Charge $10 with Stripe</h1>
<!-- to display errors returned by createToken -->
<span class="payment-errors"><?= $error ?></span>
<span class="payment-success"><?= $success ?></span>
<form action="" method="POST" id="payment-form">
<div class="form-row">
<label>Card Number</label>
<input type="text" size="20" autocomplete="off" class="card-number" />
</div>
<div class="form-row">
<label>CVC</label>
<input type="text" size="4" autocomplete="off" class="card-cvc" />
</div>
<div class="form-row">
<label>Expiration (MM/YYYY)</label>
<input type="text" size="2" class="card-expiry-month"/>
<span> / </span>
<input type="text" size="4" class="card-expiry-year"/>
</div>
<button type="submit" class="submit-button">Submit Payment</button>
</form>
</body>
</html>
执行上面的代码片段时,它会生成一个错误,指出
没有这样的外部账户:ba_1CHYY2DVYgPG6LmYtQdcu53B
请建议我使用Stripe支付网关向银行帐户付款的合适解决方案。
答案 0 :(得分:0)
您创建付款的电话失败,因为您是在 条带帐户上执行它,而不是已连接条带帐户。< / p>
您需要在付款通话中添加条带帐户标题,因为银行帐户已附加到已连接帐户而非您自己的Stripe帐户。
$payout_response=\Stripe\Payout::create(array(
"amount" => 400,
"currency" => "usd",
"destination"=>$external_account_info->id
),
array("stripe_account"=>$Account->id)
);
有关此https://stripe.com/docs/connect/authentication#stripe-account-header
的更多信息,请参阅此处退一步,支付到银行账户的资金来自Connect账户的余额。要将资金存入 Connected Account 的余额,您需要使用此处描述的方法之一,您很可能会使用目标费用或分开收费和转账