Payment(付款)
Request a payment - 发送一个付款请求
这些示例演示了请求付款所需的最少信息。有关可用参数的完整详细信息,可以看API文档(https://api-reference.checkout.com/#tag/Payments/paths/~1payments/post)
。要使用预授权付款,请设置capture
为false
。并且在付款之后,要使用capture
命令进行付款捕获。
Full Card
仅适用于PCI兼容商家,这允许您提供完整的卡详细信息。CVV号码要求取决于帐户设置。
普通支付的功能,支付结果同步返回不需要回调,只要确定返回的结果里Approved=true
就是支付成功,在使用3D安全支付的时候,支付结果不同步返回,而且异步返回到回调地址
$method = new Checkout\Models\Payments\CardSource('4242424242424242', 01, 2020);
$method->cvv = '100';
$payment = new Checkout\Models\Payments\Payment($method, 'GBP');
$payment->capture = false;
$payment->amount = 999; // = 9.99
$response = $checkout->payments()
->request($payment);
Source ID
申请卡付款后,您将收到一张来源ID,该ID可用于后续付款。
$method = new Checkout\Models\Payments\IdSource($sourceID);
$payment = new Checkout\Models\Payments\Payment($method, 'GBP');
$payment->capture = false;
$payment->amount = 999; // = 9.99
$response = $checkout->payments()
->request($payment);
Tokens
这是一次性付款的推荐集成,并使用由Checkout Frames,Apple Pay或Google Pay令牌生成的卡令牌来请求付款。在此处了解有关令牌的更多信息。
$method = new Checkout\Models\Payments\TokenSource($tokenID);
$payment = new Checkout\Models\Payments\Payment($method, 'GBP');
$payment->capture = false;
$payment->amount = 999; // = 9.99
$response = $checkout->payments()
->request($payment);
Network Tokens
与令牌相同,您可以使用Visa令牌服务生成的Visa网络令牌进行付款。
$method = new Checkout\Models\Payments\NetworkTokenSource($tokenID);
$payment = new Checkout\Models\Payments\Payment($method, 'GBP');
$payment->capture = false;
$payment->amount = 999; // = 9.99
$response = $checkout->payments()
->request($payment);
3-D Secure
使用3-D Secure可以增加额外的安全性,以防止欺诈性付款。持卡人必须在结账过程中完成额外步骤以验证其身份。这种情况下,支付请求的返回结果不再是同步返回,而是异步回调给我们在checkout.com后台操作界面设置的回调地址!了解有关3-D Secure的更多信息3-Dsecure介绍。
$payment = new Checkout\Models\Payments\Payment($method, 'GBP');
$payment->threeDs = new Checkout\Models\Payments\ThreeDs(TRUE);
$response = $checkout->payments()
->request($payment);
$redirectionUrl = $response->getRedirection();
Idempotency - 幂等
有时,由于API调用中断(例如网络错误或超时),您可能需要重试付款。我们的付款API支持幂等性,因此您可以安全地重试请求而无需重复付款。
$payment = new Checkout\Models\Payments\Payment($method, 'GBP');
$payment->setIdempotencyKey($uuid);
Details - 获取支付详情
通过传递其ID来获取付款的详细信息。可以从付款请求响应$paymentID = $response->getId()或$paymentID = $response->id
或先前的付款细节$paymentID = $details->getId()或$paymentID = $details->id
中检索此ID 。
$details = $checkout->payments()->details($paymentID);
Capture - 捕获(应该可以理解为消费预授权)
如果要求付款$payment->capture = false
,您必须命令获取付款或从中心获取付款,否则付款将仅被授权。如果,则不允许手动捕获$payment->capture = true
。通过设置金额可以全部或部分捕获授权付款(剩余金额将自动取消)。
$payment = new Checkout\Models\Payments\Capture($paymentID);
// Partial capture: $payment->amount = 999;
$capture = $checkout->payments()->capture($payment);
Void - 置空预授权
如果尚未捕获付款,则可以通过运行void命令来清空预售权。
$payment = new Checkout\Models\Payments\Voids($paymentID);
$void = $checkout->payments()->void($payment);
Refund - 退款
捕获的款项可以全额或部分退款。处理完毕后,退款将无法取消。付款可以多次退款,但不能超过原始付款金额。
$payment = new Checkout\Models\Payments\Refund($paymentID);
// Partial capture: $payment->amount = 999;
$refund = $checkout->payments()->refund($paymentID);
Actions
获取与按处理日期按降序排序的付款相关的所有操作(最新的第一个)。
$actions = $checkout->payments()->actions($paymentID);
附上一段项目中Checkout普通支付的代码
checkout = $checkout;
}
public function setSerectKey($serect_key){
$this->serect_key = $serect_key;
}
public function setPublicKey($public_key){
$this->public_key = $public_key;
}
public function setSandBox($sand_box){
$this->sandbox = $sand_box;
}
public function __construct($foo,$foo,false)
{
$this->setSerectKey($foo);
$this->setPublicKey($foo);
$this->setSandbox(false);
// Initialize the Checkout API
$checkout = new CheckoutApi($this->serect_key,$this->sandbox,$this->public_key);
$this->setCheckout($checkout);
}
public function checkoutpay($params){
$card_number = $params['card_number'];
$expiry_year = $params['expiry_year'];
$expiry_month = $params['expiry_month'];
$cvv = $params['cvv'];
$currency = $params['currency'];
$amount = $params['amount'];
// Create a Card token
$card = new Card($card_number, $expiry_month, $expiry_year);
$card->cvv = $cvv;
$token = $this->checkout->tokens()->request($card);
// Create a payment method instance with card details
$method = new TokenSource($token->getId());
// Prepare the payment parameters
$payment = new Payment($method, $currency);
$payment->amount = $amount; // = 10.00
// Send the request and retrieve the response
$response = $this->checkout->payments()->request($payment);
return $response;
}
public function getDetails($paymentID){
$details = $this->checkout->payments()->details($paymentID);
return $details;
}
}
?>
有问题可以留言