jinexus/worldpayus-restapi-sdk-php

Worldpay Total REST API 的 PHP SDK。

1.0.0 2018-01-14 16:00 UTC

This package is auto-updated.

Last update: 2024-09-11 02:09:06 UTC


README

Minimum PHP Version Latest Stable Version Total Downloads License Donate

JiNexus WorldpayUS REST API SDK PHP 是 Worldpay Total REST API 的 PHP SDK。

安装

建议使用 Composer 安装 JiNexus WorldpayUS REST API SDK PHP

$ composer require jinexus/worldpayus-restapi-sdk-php

这将安装 JiNexus WorldpayUS REST API SDK PHP 及所有必需依赖项。 JiNexus WorldpayUS REST API SDK PHP 需要 PHP 5.6 或更高版本。

基本用法

创建一个实例并设置必要的设置

<?php 
use JiNexus\WorldpayUs\WorldpayUs;

$secureNet = '1811021'; // This is just a sample value and must be replace with your own secure net value
$secureKey = 'vj8iZ0cHYTEX'; // This is just a sample value and must be replace with your own secure key
$config = [
    'publicKey' => '13ab2cd4-5efg-67hi-8jka-910l1112m8', // This is just a sample value and must be replace with your own public key
    'developerApplication' => [
        'developerId' => '12345678', // This is just a sample value and must be replace with your own developer ID
        'version' => '1.2',
    ],
];

// Create an Instance
$worldpayUs = new WorldpayUs($secureNet, $secureKey, $config);

// Set your origin in order to successfully use tokenization, this is most likely your base URI.
$worldpayUs->setOrigin($this->getBaseUrl());

// Set the gateway URL, I'll be using the demo API that WorldpayUS provided.
$worldpayUs->setGatewayUrl('https://gwapi.demo.securenet.com/api');

// Set your own HTTP Verb. Values are: 'POST', 'GET', 'PUT', 'PATCH' and 'DELETE' (Default: POST)
$worldpayUs->setVerb('POST');

仅授权

此方法授权交易但不会为结算捕获交易。
<?php 
$data = [
    'amount' => 11.00,
    'card' => [
        'number' => '4444 3333 2222 1111',
        'cvv' => '999',
        'expirationDate' => '07/2021',
        'address' => [
            'line1' => '123 Main St.',
            'city' => 'Austin',
            'state' => 'TX',
            'zip' => '78759',
            'country' => 'US',
        ],
        'firstName' => 'Jim',
        'lastName' => 'Test',
    ],
    'extendedInformation' => [
        'typeOfGoods' => 'PHYSICAL',
    ],
];

$response = $worldpayUs->authorize($data);
$result = json_decode($response, true);

预先授权捕获

此调用允许捕获先前授权的交易以进行结算。
<?php 
$data = [
    'amount' => 11.00,
    'transactionId' => 'REPLACE ME',
];

$response = $worldpayUs->capture($data);
$result = json_decode($response, true);

收费 - 授权和捕获

此调用授权交易,如果成功,则捕获它。
<?php 
$data = [
    'amount' => 11.00,
    'card' => [
        'number' => '4444 3333 2222 1111',
        'cvv' => '999',
        'expirationDate' => '07/2021',
        'address' => [
            'line1' => '123 Main St.',
            'city' => 'Austin',
            'state' => 'TX',
            'zip' => '78759',
            'country' => 'US',
        ],
    ],
    'extendedInformation' => [
        'typeOfGoods' => 'PHYSICAL',
    ],
];

$response = $worldpayUs->charge($data);
$result = json_decode($response, true);

使用次级账户收费

此调用使用与主要商户账户关联的保险库账户对次级账户进行交易授权,如果成功,则捕获它。
<?php 
$data = [
    'amount' => 11.00,
    'paymentVaultToken' => [
        'customerId' => '2000007',
        'paymentMethodID' => '1',
    ],
    'vaultCredentials' => [
        'secureNetId' => '7004183',
        'secureNetKey' => 'xyzabcdefghi',
    ],
    'extendedInformation' => [
        'typeOfGoods' => 'PHYSICAL',
    ],
];

$response = $worldpayUs->charge($data);
$result = json_decode($response, true);

使用令牌化收费

使用预保险库/卡或预保险库/支票操作创建令牌时返回的令牌可以用作实际卡或支票账户信息的替代品。此令牌还可以添加到保险库以供将来重用。
<?php 
$data = [
    'amount' => 11.00,
    'paymentVaultToken' => [
        'paymentMethodId' => '1211121',
        'publicKey' => $worldpayUs->config['publicKey'],
    ],
    'addToVault' => true,
    'extendedInformation' => [
        'typeOfGoods' => 'PHYSICAL',
    ],
];

$response = $worldpayUs->charge($data);
$result = json_decode($response, true);

关闭批次

关闭当前打开的批次将结算批次中捕获的所有交易,可以通过单个独立的 POST 操作完成。
<?php 
$response = $worldpayUs->closeBatch();
$result = json_decode($response, true);

检索已关闭的批次

一旦关闭批次,您可以使用此调用获取与该批次关联的所有交易的列表。如果调用成功,该方法将返回一个包含所有批处理交易及其原始授权返回的每个交易的详细信息的数组。
<?php 
$batchId = 'REPLACE ME';

$response = $worldpayUs->retrieveCloseBatch($batchId);
$result = json_decode($response, true);

检索当前批次

调用此方法检索当前打开的批次。不需要参数。如果成功,它将返回一个包含开放批次中交易的数组,以及每个交易在原始授权期间返回的完整详细信息。
<?php 
$response = $worldpayUs->retrieveCurrentBatch();
$result = json_decode($response, true);

退款交易

退款方法必须链接到已结算的交易。这通过指定请求中原始授权或收费的交易Id来完成。默认情况下,此方法全额退款交易。但是,您可以通过传递特定金额执行部分退款。如果尝试对尚未结算的交易进行退款,PayOS API 将自动运行一个取消交易。在这种情况下,transactionType 将切换到取消。
<?php 
$data = [
    'transactionId' => 'REPLACE ME',
];

$response = $worldpayUs->refund($data);
$result = json_decode($response, true);

取消交易

取消交易将在结算之前取消交易。
<?php 
$data = [
    'transactionId' => 'REPLACE ME',
];

$response = $worldpayUs->void($data);
$result = json_decode($response, true);

创建客户

在保险库中创建客户记录。保险库中的所有付款账户都与客户关联,因此,在添加付款账户之前,必须创建客户记录。单个客户可能有多个存储的付款账户,任何账户都可以设置为定期计费或用于执行交易。
<?php 
$data = [
    'firstName' => 'Juan',
    'lastName' => 'dela Cruz',
    'phone' => '512-122-1211',
    'emailAddress' => 'some@emailaddress.com',
    'sendEmailReceipts' => true,
    'notes' => 'This is test notes',
    'address' => [
        'line1' => '123 Main St.',
        'city' => 'Austin',
        'state' => 'TX',
        'zip' => '78759',
        'country' => 'US',
    ],
    'company' => 'Test company',
    'userDefinedFields' => [
        [
            'udfname' => 'udf1',
            'udfvalue' => 'udf1_value',
        ],
        [
            'udfname' => 'udf2',
            'udfvalue' => 'udf2_value',
        ],
        [
            'udfname' => 'udf3',
            'udfvalue' => 'udf3_value',
        ],
    ],
];

$response = $worldpayUs->createCustomer($data);
$result = json_decode($response, true);

检索客户

从保险库中检索客户记录。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';

$response = $worldpayUs->retrieveCustomer($customerId);
$result = json_decode($response, true);

更新客户

更新保险库中的客户记录。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';

$data = [
    'customerId' => $customerId,
    'firstName' => 'Updated First Name',
    'lastName' => 'Updated Last Name',
    'phone' => '512-111-1111',
    'emailAddress' => 'some@emailaddress.com',
    'sendEmailReceipts' => true,
    'notes' => 'This is test notes',
    'address' => [
        'line1' => '123 Main St.',
        'city' => 'Austin',
        'state' => 'TX',
        'zip' => '78759',
        'country' => 'US',
    ],
    'company' => 'Test company update',
    'userDefinedFields' => [
        [
            'udfname' => 'udf1',
            'udfvalue' => 'udf1_value',
        ],
        [
            'udfname' => 'udf2',
            'udfvalue' => 'udf2_value',
        ],
        [
            'udfname' => 'udf3',
            'udfvalue' => 'udf3_value',
        ],
    ],
];

$response = $worldpayUs->updateCustomer($customerId, $data);
$result = json_decode($response, true);

创建付款账户

在保险库中创建付款方式记录。保险库账户存储付款方式。每个保险库付款账户都与特定的客户ID关联。一旦创建保险库账户并与其关联客户,则可用于后续收费或定期计费。付款方式可以是信用卡、无密码借记卡或ACH付款账户。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';

$data = [
    'customerId' => $customerId,
    'card' => [
        'number' => '4444 3333 2222 1111',
        'cvv' => '999',
        'expirationDate' => '07/2021',
        'address' => [
            'line1' => '123 Main St.',
            'city' => 'Austin',
            'state' => 'TX',
            'zip' => '78759',
            'country' => 'US',
        ],
        'firstName' => 'Jim',
        'lastName' => 'Test',
    ],
    'phone' => '512-250-7865',
    'notes' => 'Create a vault account',
    'accountDuplicateCheckIndicator' => 0,
    'primary' => true,
    'userDefinedFields' => [
        [
            'udfname' => 'udf1',
            'udfvalue' => 'udf1_value',
        ],
        [
            'udfname' => 'udf2',
            'udfvalue' => 'udf2_value',
        ],
        [
            'udfname' => 'udf3',
            'udfvalue' => 'udf3_value',
        ],
    ],
];

$response = $worldpayUs->createPaymentAccount($customerId, $data);
$result = json_decode($response, true);

检索付款账户

从保险库中检索付款账户记录。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';

$response = $worldpayUs->retrievePaymentAccount($customerId, $paymentMethodId);
$result = json_decode($response, true);

更新付款账户

更新保险库中现有的付款账户记录。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';

$data = [
    'customerId' => $customerId,
    'paymentMethodId' => $paymentMethodId,
    'card' => [
        'number' => '4444 3333 2222 1111',
        'cvv' => '999',
        'expirationDate' => '07/2021',
        'address' => [
            'line1' => '123 Main St.',
            'city' => 'Austin',
            'state' => 'TX',
            'zip' => '78759',
            'country' => 'US',
        ],
        'firstName' => 'Jim',
        'lastName' => 'Updated',
    ],
    'phone' => '512-250-7865',
    'notes' => 'Update a vault account',
    'accountDuplicateCheckIndicator' => 0,
    'primary' => true,
    'userDefinedFields' => [
        [
            'udfname' => 'udf1',
            'udfvalue' => 'udf1_value',
        ],
        [
            'udfname' => 'udf2',
            'udfvalue' => 'udf2_value',
        ],
        [
            'udfname' => 'udf3',
            'udfvalue' => 'udf3_value',
        ],
        [
            'udfname' => 'udf4',
            'udfvalue' => 'udf4_value',
        ],
    ],
];

$response = $worldpayUs->updatePaymentAccount($customerId, $paymentMethodId, $data);
$result = json_decode($response, true);

删除付款账户

从保险库中移除现有的付款账户记录。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';

$data = [
    'customerId' => $customerId,
    'paymentMethodId' => $paymentMethodId,
];

$response = $worldpayUs->deletePaymentAccount($customerId, $paymentMethodId, $data);
$result = json_decode($response, true);

创建客户和付款

在保险库中创建客户和付款记录。保险库中的所有付款账户都与客户关联,此调用将添加客户及其关联的付款。
<?php 
$data = [
    'firstName' => 'REPLACE ME',
    'lastName' => 'REPLACE ME',
    'phone' => 'REPLACE ME',
    'emailAddress' => 'replace_me@emailaddress.com',
    'sendEmailReceipts' => true,
    'notes' => 'This is test notes',
    'address' => [
        'line1' => '123 Main St.',
        'city' => 'Austin',
        'state' => 'TX',
        'zip' => '78759',
        'country' => 'US',
    ],
    'company' => 'Test company',
    'userDefinedFields' => [
        [
            'udfname' => 'udf1',
            'udfvalue' => 'udf1_value',
        ],
        [
            'udfname' => 'udf2',
            'udfvalue' => 'udf2_value',
        ],
        [
            'udfname' => 'udf3',
            'udfvalue' => 'udf3_value',
        ],
    ],
    'customerDuplicateCheckIndicator' => 1,
    'card' => [
        'number' => '4444 3333 2222 1111',
        'cvv' => '999',
        'expirationDate' => '07/2021',
        'address' => [
            'line1' => '123 Main St.',
            'city' => 'Austin',
            'state' => 'TX',
            'zip' => '78759',
            'country' => 'US',
        ],
        'firstName' => 'REPLACE ME',
        'lastName' => 'REPLACE ME',
    ],
    'primary' => true,
    'accountDuplicateCheckIndicator' => 1,
];

$response = $worldpayUs->createCustomerPaymentAccount($data);
$result = json_decode($response, true);

更新客户和付款

更新保险库中的客户和付款记录。保险库中的所有付款账户都与客户关联,此调用将更新客户及其关联的付款。更新仅适用于主要付款ID。
<?php 
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';

$data = [
    'customerId' => $customerId,
    'paymentMethodId' => $paymentMethodId,
    'firstName' => 'REPLACE ME',
    'lastName' => 'REPLACE ME',
    'phone' => 'REPLACE ME',
    'emailAddress' => 'replace_me@emailaddress.com',
    'sendEmailReceipts' => true,
    'notes' => 'This is updated test notes',
    'company' => 'Test company',
    'customerDuplicateCheckIndicator' => 1,
    'card' => [
        'number' => '4444 1111 1111 1111',
        'cvv' => '999',
        'expirationDate' => '08/2021',
        'address' => [
            'line1' => '123 Main St.',
            'city' => 'Austin',
            'state' => 'TX',
            'zip' => '78749',
            'country' => 'US',
        ],
        'firstName' => 'REPLACE ME',
        'lastName' => 'REPLACE ME',
    ],
    'primary' => true,
    'accountDuplicateCheckIndicator' => 1,
];

$response = $worldpayUs->updateCustomerPaymentAccount($data);
$result = json_decode($response, true);

待办事项

  • 创建单元测试
  • 利用异常
  • 我需要找到一种更好的方式来利用setSandbox方法
  • 从Worldpay US添加更多资源
  • 改进文档(这里是最无聊的部分~)#抱怨

贡献

在贡献之前,请阅读有关细节的贡献文件

安全性

如果您发现与安全相关的问题,请通过电子邮件jinvirle@gmail.com而不是使用问题跟踪器。

鸣谢

依赖关系

许可

JiNexus WorldpayUS REST API SDK PHP是一个开源项目,根据BSD 3-Clause License许可。有关更多信息,请参阅许可文件。JiNexus保留更改未来版本许可的权利。

捐赠

捐赠非常受欢迎!

人必须为了食物而编码。人必须做他认为需要做的事情,从而给予应有的信用。

paypal