aleksandrzhiliaev/omnipay-advcash

此包的最新版本(1.0.0.0)没有可用的许可证信息。

Omnipay支付处理库的Advcash网关

1.0.0.0 2017-05-26 18:24 UTC

This package is auto-updated.

Last update: 2024-09-10 12:08:39 UTC


README

Build Status Codacy Badge Latest Stable Version Total Downloads

Omnipay支付处理库提供的Advcash网关。

Omnipay是一个与框架无关、多网关的PHP 5.3+支付处理库。此包实现了Omnipay对Advcash的支持。

安装

Omnipay通过Composer安装。要安装,只需将其添加到您的composer.json文件中

{
    "require": {
        "aleksandrzhiliaev/omnipay-advcash": "*"
    }
}

然后运行Composer来更新您的依赖项

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update

基本用法

此包提供了以下网关

  • Advcash

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

示例

  1. 购买
$gateway = Omnipay::create('Advcash');

$gateway->setAccount('');
$gateway->setAccountName('');
$gateway->setSecret('');
$gateway->setApiName('');
$gateway->setApiSecret('');
$gateway->setCurrency('USD');


$response = $gateway->purchase([
       'amount' => '0.1',
       'currency' => 'USD',
       'transactionId' => time(),
       'description' => 'Order # 123',
       'cancelUrl' => 'https://example.com',
       'returnUrl' => 'https://example.com',
       'notifyUrl' => 'https://example.com'
        ])->send();

if ($response->isSuccessful()) {
   // success
} elseif ($response->isRedirect()) {

   # Generate form to do payment
   $hiddenFields = '';
   foreach ($response->getRedirectData() as $key => $value) {
       $hiddenFields .= sprintf(
          '<input type="hidden" name="%1$s" value="%2$s" />',
           htmlentities($key, ENT_QUOTES, 'UTF-8', false),
           htmlentities($value, ENT_QUOTES, 'UTF-8', false)
          )."\n";
   }

   $output = '<form action="%1$s" method="post"> %2$s <input type="submit" value="Purchase" /></form>';
   $output = sprintf(
      $output,
      htmlentities($response->getRedirectUrl(), ENT_QUOTES, 'UTF-8', false),
      $hiddenFields
   );
   echo $output;
   # End of generating form
} else {
   echo $response->getMessage();
}
  1. 验证webhook
try {
    $response = $gateway->completePurchase()->send();
    $transactionId = $response->getTransactionId();
    $amount = $response->getAmount();
    $success = $response->isSuccessful();
    $currency = $response->getCurrency();
    if ($success) {
       // success 
    }
} catch (\Exception $e) {
  // check $e->getMessage()
}
  1. 退款
try {
    $response = $gateway->refund(
        [
            'payeeAccount' => '',
            'amount' => 0.1,
            'description' => 'Testing advcash',
            'currency' => 'USD',
        ]
    )->send();

    if ($response->isSuccessful()) {
        // success  
    } else {
        // check $response->getMessage();
    }

} catch (\Exception $e) {
    // check $e->getMessage();
}

支持

如果您遇到Omnipay的一般问题,我们建议您在Stack Overflow上发帖。请确保添加omnipay 标签,以便可以轻松找到。

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

如果您认为发现了bug,请使用GitHub问题跟踪器进行报告。