apvanlaan/usaepay

允许轻松连接和使用Laravel的USAePay REST API


README

Latest Version on Packagist Build Status

该项目由Aaron VanLaan创建并维护:Aaron VanLaan.

使用方法

目录

  1. 要求
  2. 安装
  3. EpayCustomer 类
  4. EpayTransaction 类
  5. EpayBatch 类
  6. EpayProduct 类
  7. EpayCategory 类
  8. EpayInventory 类(即将推出)
  9. 示例

要求

该库使用PHP 7.4+和Laravel 6+

您可以在以下位置找到USAePay Rest API文档:https://help.usaepay.info/api/rest/

安装

通过Composer安装

$ composer require apvanlaan/usaepay

发布资产

$ php artisan vendor:publish --provider="Apvanlaan\UsaEpay\UsaEpayServiceProvider"

将所需的ENV变量添加到.env文件中

EPAYAPI=
#EPAYPIN= (optional, only include if pin is utilized)
EPAYPUBLIC=
EPAY_SUB=sandbox (change to secure for production)
#EPAY_ENDPOINT= (optional, use if using a custom endpoint, otherwise defaults to v2)

注意:在以下章节中,包含的路由与我在包中包含的控制器相关。如果您自己实现,则显然可以忽略这些路由。但是,所需的字段是通过USAePay API必需的,因此这些字段必须保留。

EpayCustomer 类

EpayCustomer 类处理创建客户对象及其相关API调用。

参数

EpayCustomer 参数为:(注意:以下列出的所有必需字段都是USAePay API所需的最小字段)

  • company 字符串
  • first_name 字符串
  • last_name 字符串
  • customerid 字符串
  • street 字符串
  • street2
  • city 字符串
  • state 字符串
  • postalcode 字符串
  • country 字符串
  • phone 字符串
  • fax 字符串
  • email 字符串
  • url 字符串
  • notes 字符串
  • description 字符串
  • custkey 字符串

EpayCustomer 方法及其默认必需参数和示例

(注意:有两种方式可以实例化epay类,您可以通过传递带有参数的数组/对象来实例化,或者您可以实例化一个空的类并手动设置所需的参数。)

getCustomer()

  • 路由: GET epay/customer/get/{custkey}
  • 必需: custkey
$customer = new EpayCustomer();
$customer->custkey = $custkey;

return $customer->getCustomer();

listCustomers()

  • 路由: GET epay/customer/list
  • 必需: none
$customer = new EpayCustomer();

return $customer->listCustomers();

addCustomer()

  • 路由: POST epay/customer/create
  • 必需: company (如果无first_name && last_name), first_name (如果没有company), last_name (如果没有company)
$customer = new EpayCustomer();
$params = ['first_name' =>"John",'last_name' =>"Doe",'street' =>"123 House Rd",'city' =>"Beverly Hills",'state' =>"CA",'postalcode' =>"90210",'country' =>"USA",'phone' =>"5558675309",'email' =>"john.doe@email.com",'description' =>"Fake customer information for testing."];
return $customer->addCustomer($params);

updateCustomer()

  • 路由: POST epay/customer/update
  • 必需: custkey
$customerUpdate = new \StdClass();
$customerUpdate->custkey = "asdf";
$customerUpdate->description = 'Still a fake customer used for testing';

$customer = new EpayCustomer($params);

return $customer->updateCustomer();

deleteCustomer()

  • 路由: POST epay/customer/delete
  • 必需: custkey
$params = ['custkey'=>$request->custkey];
$customer = new EpayCustomer($params);

return $customer->deleteCustomer();

EpayTransaction 类

EpayTransaction 类处理创建交易对象及其相关API调用。

参数

EpayTransaction 参数为

  • trankey 字符串
  • refnum 字符串
  • invoice 字符串
  • ponum 字符串
  • orderid 字符串
  • description 字符串
  • comments 字符串
  • email 字符串
  • merchemailaddr 字符串
  • amount 浮点数
  • amount_detail Transactions\EpayAmountDetail
  • creditcard Transactions\EpayCreditCard
  • save_card 布尔值
  • traits 交易\epayTrait
  • custkey 字符串
  • save_customer 布尔型
  • save_customer_paymethod 布尔型
  • billing_address 交易\epayCustomerAddress
  • shipping_address 交易\epayCustomerAddress
  • lineitmes 交易\epayLineItem
  • custom_fields 交易\epayCustomField
  • currency 字符串
  • terminal 字符串
  • clerk 字符串
  • clientip 字符串
  • software 字符串

EpayTransaction 方法,默认必需参数

listAuthorized()

  • 路由:GET epay/transaction/list
  • 必需: none

listAuthorized()

  • 路由:GET epay/transaction/list
  • 必需:trankey

createSale()

  • 路由:POST epay/transaction/sale
  • 必需:amount, payment_key(如果没有信用卡), creditcard(如果没有payment_key)

createRefund()

  • 必需:amount, creditcard

createVoid()

  • 路由:POST epay/transaction/void
  • 必需:trankey(如果没有refnum),refnum(如果没有trankey)

authorizeTransaction()

  • 路由:POST epay/transaction/auth
  • 必需:amount, payment_key(如果没有信用卡), creditcard(如果没有payment_key)

captureTransaction()

  • 路由:POST epay/transaction/capture
  • 必需:trankey(如果没有refnum),refnum(如果没有trankey)

EpayTransaction 子类

EpayAmountDetail 类及参数

  • subtotal 双精度浮点数
  • tax 双精度浮点数
  • nontaxable 布尔型
  • tip 双精度浮点数
  • discount 双精度浮点数
  • shipping 双精度浮点数
  • duty 双精度浮点数
  • enable_partialauth 布尔型

EpayCreditCard 类及参数

  • cardholder 字符串
  • number 字符串
  • expiration 字符串
  • cvc 整数
  • avs_street 字符串
  • avs_postalcode 字符串

EpayCustomerAddress 类及参数

  • company 字符串
  • firstname 字符串
  • lastname 字符串
  • street 字符串
  • street2 字符串
  • city 字符串
  • state 字符串
  • postalcode 字符串
  • country 字符串
  • phone 字符串
  • fax; 字符串

EpayLineItem 类及参数

  • product_key 字符串
  • name 字符串
  • cost 双精度浮点数
  • qty 整数
  • description 字符串
  • sku 字符串
  • taxable 布尔型
  • tax_amount 双精度浮点数
  • tax_rate 字符串
  • discount_rate 字符串
  • discount_amount 双精度浮点数
  • location_key 字符串
  • commodity_code 字符串

EpayTrait 类及参数

  • is_debt 布尔型
  • is_bill_pay 布尔型
  • is_recurring 布尔型
  • is_healthcare 布尔型
  • is_cash_advance 布尔型
  • secure_collection 整数

EpayBatch 类

The EpayBatch 类处理批处理对象的创建和相关的api调用。

参数

EpayBatch 参数包括

  • limit 整数
  • offset 整数
  • openedlt 字符串
  • openedgt 字符串
  • closedlt 字符串
  • closedgt 字符串
  • openedle 字符串
  • openedge 字符串
  • closedle 字符串
  • closedge 字符串
  • batch_key 字符串

EpayBatch 方法,默认必需参数

listBatches()

  • 路由:GET epay/batch/list
  • 必需: none

currentBatch()

  • 路由:GET epay/batch/current
  • 必需: none

retrieveBatch()

  • 路由:POST epay/batch/retrieve
  • 必需:batch_key

getCurrentBatchTransactions()

  • 路由:GET epay/batch/currentTransactions
  • 必需: none

getTransactionsByBatch()

  • 路由:GET epay/batch/transactionsByBatch
  • 必需:trankey(如果没有refnum),refnum(如果没有trankey)

closeBatch()

  • 路由:POST epay/batch/close
  • 必需:batch_key

EpayProduct 类

The EpayProduct 类处理产品对象的创建和相关的api调用。

参数

  • name 字符串
  • price 浮点数
  • enabled 布尔型
  • taxable 布尔型
  • available_all 布尔型
  • available_all_date 字符串
  • categoryid 整数
  • commodity_code 字符串
  • date_available 字符串
  • description 字符串
  • list_price 浮点数
  • wholesale_price 浮点数
  • manufacturer 字符串
  • merch_productid 字符串
  • min_quantity 整数
  • model 字符串
  • physicalgood 布尔型
  • weight 整数
  • ship_weight 整数
  • sku 字符串
  • taxclass 字符串
  • um 字符串
  • upc 字符串
  • url 字符串
  • allow_override 布尔型
  • product_key 字符串
  • limit 整数
  • offset 整数
  • inventory 数组
  • modifiers 数组

EpayProduct 方法,包含默认必选参数

listProducts()

  • 路由:GET epay/product/list
  • 必需: none

createProduct()

  • 路由:POST epay/product/create
  • 必选:name

getProduct()

  • 路由:GET epay/product/get
  • 必选:product_key

updateProduct()

  • 路由:POST epay/product/update
  • 必选:product_key

deleteProduct()

  • 路由:POST epay/product/delete
  • 必选:product_key

EpayCategory 类

EpayCategory 类处理创建 Category 对象及其相关 API 调用。

参数

  • name 字符串
  • categorykey 字符串
  • limit 整数
  • offset 整数
  • modifiers 数组

EpayCategory 方法,包含默认必选参数

listCategories()

  • 路由:GET epay/category/list
  • 必需: none

createCategory()

  • 路由:POST epay/category/create
  • 必选:name

getCategory()

  • 路由:GET epay/category/get
  • 必选:category_key

updateCategory()

  • 路由:POST epay/category/update
  • 必选:category_key

deleteCategory()

  • 路由:POST epay/category/delete
  • 必选:category_key

EpayInventory 类

(即将推出)

参数(即将推出)

EpayInventory 方法,包含默认必选参数(即将推出)

示例

以下是在 Laravel 中创建使用 Vue 组件的视图的示例

示例视图

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://www.usaepay.com/js/v1/pay.js"></script>
</head>
<body>
    <div id='app'>
        <div class='col'>
            <h2>Payment/Auth Form</h2>
            <paymentform publickey={{config('usaepay.publickey')}}></paymentform>
        </div>
        <div class='col'>
            <h2>Transaction List</h2>
            <transactionlist></transactionlist>
        </div>
    </div>
</body>
<script src="{{ asset('js/app.js') }}"></script>
</html>

示例 Vue 组件

<template>
    <div>
        <form class='paymentForm' @submit.prevent='submitForm'>
                <div class='form-group'>
            <label for='saveCust'>Save Customer?</label>
            <input type='checkbox' name='saveCust' v-model='saveCust' />
            </div>
                <div class='form-group'>
            <label for='type'>Transaction Type</label>
                <div class='form-group'>
            <label>Authorization <input type='radio' value='auth' name='type' v-model='transaction.type' /></label>
            </div>
                <div class='form-group'>
            <label>Sale <input type='radio' value='sale' name='type' v-model='transaction.type' /></label>
            </div>
            </div>
                <div class='form-group'>
            <label for='amount'>Amount : ${{transaction.amount}}</label>
            </div>
                <div class='form-group'>
            <label for="email">Email</label>
            <input type="email" v-model="transaction.email" required/>
            </div>
            <div id='shipping_address'>
                <div class='form-group'>
                    <label class='label' for="company">Company</label>
                    <input type="text" name="company" v-model='transaction.shipping_address.company' />
                </div>
                <div class='form-group'>
                    <label class='label' for="firstname">First Name</label>
                    <input type="text" name="firstname" v-model='transaction.shipping_address.firstname' />
                </div>
                <div class='form-group'>
                    <label class='label' for="lastname">Last Name</label>
                    <input type="text" name="lastname" v-model='transaction.shipping_address.lastname' />
                </div>
                <div class='form-group'>
                    <label class='label' for="street">Address</label>
                    <input type="text" name="street" v-model='transaction.shipping_address.street' required/>
                </div>
                <div class='form-group'>
                    <label class='label' for="street2">Apt / Building</label>
                    <input type="text" name="street2" v-model='transaction.shipping_address.street2' />
                </div>
                <div class='form-group'>
                    <label class='label' for="city">City</label>
                    <input type='text' name='city' v-model='transaction.shipping_address.city' required/>
                </div>
                <div class='form-group'>
                    <label class='label' for="state">State</label>
                    <input type="text" name="state" v-model='transaction.shipping_address.state' required/>
                </div>
                <div class='form-group'>
                    <label class='label' for="postalcode">Zip</label>
                    <input type="text" name="postalcode" v-model='transaction.shipping_address.postalcode' required/>
                </div>
                <div class='form-group'>
                    <label class='label' for="country">Country</label>
                    <select name="country" v-model='transaction.shipping_address.country' required>
                        <option value="Select Country">Select Country</option>
                        <option value="US">US</option>
                        <option value="CA">Canada</option>
                    </select>
                </div>
                <div class='form-group'>
                    <label class='label' for="phone">Phone#</label>
                    <input type="text" name="phone" v-model='transaction.shipping_address.phone' />
                    </div>
            </div>
            <div class='form-group'>
            <label class='label' for='diffBilling'>Different Billing Address?</label>
            <input type='checkbox' name='diffBilling' v-model='diffBilling'/>
            </div>
            <div v-if="diffBilling == true" id='billing_address'>
                <div class='form-group'>
                <label class='label' for="company">Company</label>
                <input type="text" name="company" v-model='transaction.billing_address.company' /></div>
                <div class='form-group'>
                <label class='label' for="firstname">First Name</label>
                <input type="text" name="firstname" v-model='transaction.billing_address.firstname' /></div>
                <div class='form-group'>
                <label class='label' for="lastname">Last Name</label>
                <input type="text" name="lastname" v-model='transaction.billing_address.lastname' /></div>
                <div class='form-group'>
                <label class='label' for="street">Address</label>
                <input type="text" name="street" v-model='transaction.billing_address.street' required/></div>
                <div class='form-group'>
                <label class='label' for="street2">Apt / Building</label>
                <input type="text" name="street2" v-model='transaction.billing_address.street2' /></div>
                <div class='form-group'>
                <label class='label' for="city">City</label>
                <input type='text' name='city' v-model='transaction.billing_address.city' required/></div>
                <div class='form-group'>
                <label class='label' for="state">State</label>
                <input type="text" name="state" v-model='transaction.billing_address.state' required/></div>
                <div class='form-group'>
                <label class='label' for="postalcode">Zip</label>
                <input type="text" name="postalcode" v-model='transaction.billing_address.postalcode' required/></div>
                <div class='form-group'>
                <label class='label' for="country">Country</label>
                <select name="country" v-model='transaction.billing_address.country' required>
                    <option value="Select Country">Select Country</option>
                    <option value="US">US</option>
                    <option value="CA">Canada</option>
                </select>
                </div>
                <div class='form-group'>
                <label for="phone">Phone#</label>
                <input type="text" name="phone" v-model='transaction.billing_address.phone' /></div>              
            </div>
            <creditcard ref='cc' :publickey=publickey></creditcard>
            <button type='submit'>Submit</button>
        </form>
    <div>Results : <pre>{{results}}</pre></div>
    </div>
</template>
<script>
    export default {
        props: ['publickey'],
        data() {
            return {
                transaction:{
                    billing_address:{
                        company:'',
                        firstname:'',
                        lastname:'',
                        street:'',
                        street2:'',
                        city:'',
                        state:'',
                        postalcode:'',
                        country:'',
                        phone:'',
                    },
                    shipping_address:{
                        company:'',
                        firstname:'',
                        lastname:'',
                        street:'',
                        street2:'',
                        city:'',
                        state:'',
                        postalcode:'',
                        country:'',
                        phone:'',
                    },
                    lineitems:[
                        {
                            name: "Test1",
                            cost: 3.50,
                            qty: 2,
                            description: "This is the first test item."
                        },
                        {
                            name: "Test2",
                            cost: 3.75,
                            qty: 1,
                            description: "This is the second test item."
                        }
                    ],
                    email:'',
                    type:'auth',
                    amount:3.5,                                
                },
                diffBilling:false,
                results:'',
                results_output:'',
                payment_key:'',
                saveCust:false,
            }
        },
        methods: {
            submitForm(){
                var self = this;
                self.$refs.cc.errormsg = '';
                var client = this.$refs.cc.client;
                var paymentCard = this.$refs.cc.paymentCard;
                if(!self.diffBilling){
                    self.transaction.billing_address = self.transaction.shipping_address;
                }
                client.getPaymentKey(paymentCard).then(result => {
                    if (result.error) {                       
                        self.$refs.cc.errormsg = result.error.message;
                    } else {
                        // do something with your payment key
                        self.payment_key = result;
                    }
                    self.transaction.payment_key = self.payment_key;
                    if(self.saveCust == true){
                        self.transaction.save_customer = 1;
                    }
                    axios.post('api/epay/transaction/' + self.transaction.type,self.transaction).then(function(response){
                        self.results = response.data;
                        if(self.saveCust == true){
                            axios.get('api/epay/customer/get/' + response.data.customer.custkey).then(function(customer){
                                self.results.customer = customer.data;                     
                            })
                        }
                         self.results_output = JSON.stringify(response.data,null,2); 
                    })
                    .catch(function(error){
                        console.log(error.response.data.message);
                        self.$refs.cc.errormsg = "An error has occurred.  Please check the form and try again.\r\n Error Message: " + error.response.data.message;
                    });
                });                
            },
        },
        watch:{   
        },
        computed: {  
        },
        mounted: function(){
        }
    }
</script>
<style>
.paymentForm{width:300px;}
</style>

变更日志

请参阅变更日志,获取最近更改的更多信息。

贡献

请参阅contributing.md,获取详细信息以及待办事项列表。

致谢

许可

USAePay REST API 包含 Laravel 的开源软件,采用MIT 许可