adnane-ka / omnipay-paddle

1.2 2024-09-06 20:27 UTC

This package is auto-updated.

Last update: 2024-09-07 23:36:42 UTC


README

为Omnipay支付处理库提供的Paddle支付网关

Build Status Latest Stable Version Total Downloads

Omnipay 是一个适用于PHP 5.3+的、无框架、多网关的支付处理库。此包实现了Omnipay的Tap支持。

安装

composer require adnane-ka/omnipay-paddle

基本用法

此包提供了以下网关

  • Paddle

此包与Paddle的API交互。

有关一般使用说明,请参阅主要的Omnipay 仓库。

流程

  1. 配置网关
  2. 创建一个交易草稿
  3. 显示交易草稿的叠加结账表单
  4. 通过网关处理支付
  5. 重定向到网站上的支付处理

示例用法

配置

use Omnipay\Omnipay;

$gateway = Omnipay::create('Paddle');
$gateway->setApiKey('YOUR_API_KEY');
$gateway->setTestMode(true);

创建购买

$response = $gateway->purchase([
    'amount' => 5.00 * 100, // in cents
    'checkoutUrl' => 'https://:8000/checkout.php', // where you'll display the overlay / inline checkout
    'returnUrl' => 'https://:8000/complete.php',  // where you'll be proccessing the payment 
    'currency' => 'USD'
])->send();

if ($response->isRedirect()) {
    // The transaction is created as a draft and you're ready to be redirected to checkout
    $response->redirect(); 
} else {
    // An error occured
    echo $response->getMessage();
}

结账

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Paddle Checkout</title>
</head>
<body>
<script src="https://cdn.paddle.com/paddle/v2/paddle.js"></script>
<script type="text/javascript">
    Paddle.Environment.set("sandbox");
    Paddle.Initialize({ 
      token: "test_4c116d8b4cc5cd9756de9765db9", // Your public API key 
    });
    Paddle.Checkout.open({
      transactionId: "<?php echo $_GET['transactionId']; ?>", // Locate this from request 
      settings: {
        successUrl: "<?php echo urldecode($_GET['returnUrl']); ?>" // Locate this from request
      }
    });
</script>
</body>
</html>

完成购买

当用户在叠加结账中付款后提交结账表单,他们将重定向到 returnUrl,在那里您将处理支付

$response = $gateway->completePurchase([
    'transactionId' => $_GET['transactionId'] // sent in request or retrieved from backend
])->send();

if($response->isSuccessful()){
    // Payment was successful and charge was captured
    // $response->getData()
    echo $response->getTransactionReference(); // payment reference
}else{
    // Charge was not captured and payment failed
    echo $response->getMessage();
}

支持

如果您在使用Omnipay时遇到一般问题,我们建议在 Stack Overflow 上发布。请确保添加 omnipay 标签,以便它容易被找到。

如果您想了解发布公告,讨论项目想法或提出更详细的问题,还可以订阅 邮件列表

如果您认为您已经发现了一个错误,请使用 GitHub问题跟踪器 报告它,或者更好的做法是分支库并提交一个拉取请求。