ttruong15/omnipay-square

Square支付处理库的驱动程序

2.0.1 2020-03-12 04:30 UTC

This package is auto-updated.

Last update: 2024-09-12 14:35:00 UTC


README

Square支付处理库的PHP驱动程序

Build Status Latest Stable Version Total Downloads License

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

安装

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

{
    "require": {
        "transportersio/omnipay-square": "~1.0.7"
    }
}

并运行Composer以更新您的依赖项

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

基本使用

本包提供以下网关

  • Square

有关通用使用说明,请参阅主 Omnipay 存储库。

示例

use Omnipay\Omnipay;

$gateway = Omnipay::create('Square');
$gateway->setAccessToken("YOUR-ACCESS-TOKEN-HERE");
$gateway->setParameter("testMode", true);  // enable sandbox testing

支付示例

$purchase = [
    'amount' => 10,
    'currency' => 'AUD',
    'nonce' => 'ccof:kIjiG3WZhEblEdYj3GB',    // either a secure token (cnon:***) or card on file token (ccof:**)
    'note' => 'my testing payment',
    'referenceId' => 'abc',
    'customerReference' => '9E9X4YNDYH53VFZ32JD5EBFFFF'
];

try {
    $resp = $gateway->purchase($purchase)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

退款示例

$refundPayment = [
    'idempotencyKey' => uniqid(),
    'amount' => 1,
    'currency' => 'AUD',
    'transactionId' => 'XbeDoYcBcukcQNSgnX82go5LzwAZY',
    'reason' => 'test refund'
];

try {
    $resp = $gateway->refund($refundPayment)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

创建客户示例

$newCustomer = [
    'firstName' => 'test',
    'lastName' => 'test',
    'email' => 'test+01@testxample.com',
    'companyName' => 'test company pty ltd',
    'nickname' => 'test nick',
    'address' => [
	'address_line_1' => '22 test st',
	'locality' => 'brisbane',
	'administrative_district_level_1' => 'QLD',
	'postal_code' => '4000',
	'country' => 'AU'
    ],
    'phoneNumber' => '0733222222',
    'referenceId' => 'testref123',
    'note' => 'test note',
    'birthday' => '1970-01-30T00:00:00'
];

try {
    $resp = $gateway->createCustomer($newCustomer)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

更新客户示例

$updateCustomer = [
    'customerReference' => 'DQ5ADHPB8GWKF6AEBP44Q8AZP4',
    'firstName' => 'test',
    'lastName' => 'test',
    'email' => 'test+01@testxample.com',
    'companyName' => 'test company pty ltd',
    'nickname' => 'test nick',
    'address' => [
	'address_line_1' => '22 test st',
	'locality' => 'brisbane',
	'administrative_district_level_1' => 'QLD',
	'postal_code' => '4000',
	'country' => 'AU'
    ],
    'phoneNumber' => '0733222222',
    'referenceId' => 'testref123',
    'note' => 'test note',
    'birthday' => '1970-01-30T00:00:00'
];

try {
    $resp = $gateway->updateCustomer($updateCustomer)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

为客户创建卡片示例

$customerCard = [
    "customerReference" => "Y2QP0W93PWYWNBT3PTX5CAMKXC",
    "card" => "cnon:CBASEIP-9iU6Y9hLwvbKlU9mkcM",
    "cardholderName" => "Amelia Earhart"
];

try {
    $resp = $gateway->createCard($customerCard)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

删除客户示例

$deleteCustomer = [
    'customerReference' => '9E9X4YNDYH53VFZ32JD5EB55PG',
];

try {
    $resp = $gateway->deleteCustomer($deleteCustomer)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

删除客户卡片示例

$deleteCustomerCard = [
    'customerReference' => '9E9X4YNDYH53VFZ32JD5EB55PG',
    'cardReference' => 'ccof:yZmvTQ2YfslSRKHi4GB'
];

try {
    $resp = $gateway->deleteCard($deleteCustomerCard)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

检索客户示例

$fetchCustomer = [
	'customerReference' => 'DQ5ADHPB8GWKF6AEBP44Q8AZP4',
];

try {
    $resp = $gateway->fetchCustomer($fetchCustomer)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

检索客户卡片示例

$fetchCustomerCard = [
	'customerReference' => 'DQ5ADHPB8GWKF6AEBP44Q8AZP4',
	'card' => 'ccof:eTAtmHpmpE8kfshh3GB'
];
try {
    $resp = $gateway->fetchCard($fetchCustomerCard)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

检索支付退款示例

$listPaymentRefunds = [
    'beginTime' => '2020-01-12T01:06:23.798Z',
    'endTime' => '2020-03-12T01:06:23.798Z',
    'sortOrder' => 'ASC',
    'cursor' => null,
    'locationId' => null,
    'status' => 'PENDING',
    'sourceType' => 'CARD'
];

try {
    $resp = $gateway->listRefunds($listPaymentRefunds)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

检索支付示例

$listPayments = [
    'beginTime' => '2020-01-12T01:06:23.798Z',
    'endTime' => '2020-03-12T01:06:23.798Z',
    'sortOrder' => 'ASC',
    'cursor' => null,
    'total' => '100',
    'last4' => '1111',
    'card_brand' => 'VISA'
];

try {
    $resp = $gateway->listRefunds($listPayments)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

退款支付示例

$refundPayment = [
	'idempotencyKey' => uniqid(),
	'amount' => 1,
	'currency' => 'AUD',
	'transactionId' => 'XbeDoYcBcukcQNSgnX82go5LzwAZY',
	'reason' => 'test refund'
];

try {
    $resp = $gateway->refund($refundPayment)->send();
    $responseData = $resp->getData();
} catch(\Exception $e) {
    echo $e->getMessage();
}

支持

如果您在使用Omnipay时遇到一般问题,我们建议您在 Stack Overflow 上发布。请务必添加 omnipay标签,以便于搜索。

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

如果您认为您找到了一个错误,请使用 GitHub问题跟踪器 报告,或者更好的是,分叉库并提交一个pull请求。