apvanlaan/usaepay 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

apvanlaan/usaepay

Composer 安装命令:

composer require apvanlaan/usaepay

包简介

Allows easy connection with and use of USAePay's REST API with Laravel

README 文档

README

Latest Version on Packagist Build Status

Project was created by, and is maintained by Aaron VanLaan.

Usage

Table Of Content

  1. Requirements
  2. Installation
  3. EpayCustomer Class
  4. EpayTransaction Class
  5. EpayBatch Class
  6. EpayProduct Class
  7. EpayCategory Class
  8. EpayInventory Class (COMING SOON)
  9. Examples

Requirements

This library uses PHP 7.4+ and Laravel 6+

You can find the USAePay Rest API docs here : https://help.usaepay.info/api/rest/

Installation

Require via Composer

$ composer require apvanlaan/usaepay

Publish Assets

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

Add required ENV variables to .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)

Note: In the following sections, the included routes relate to the controllers I have included in the package. If you end up rolling your own then obviously you can ignore those. The required fields, however, are required via the USAePay API, so those must remain.

EpayCustomer Class

The EpayCustomer Class handles the creation of the Customer object and the associated api calls.

Parameters

EpayCustomer parameters are: (note: all listed required are the minimum required by the USAePay API)

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

EpayCustomer Methods w/ default required params and Examples

(note: there are two ways to instantiate the epay classes, you can pass an array/object with the paramters or you can instantiate an empty class and manually set the parameters as needed.)

getCustomer()

  • Route : GET epay/customer/get/{custkey}
  • Required : custkey
$customer = new EpayCustomer();
$customer->custkey = $custkey;

return $customer->getCustomer();

listCustomers()

  • Route : GET epay/customer/list
  • Required : none
$customer = new EpayCustomer();

return $customer->listCustomers();

addCustomer()

  • Route : POST epay/customer/create
  • Required : company (if no first_name && last_name), first_name (if no company), last_name (if no 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()

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

$customer = new EpayCustomer($params);

return $customer->updateCustomer();

deleteCustomer()

  • Route : POST epay/customer/delete
  • Required : custkey
$params = ['custkey'=>$request->custkey];
$customer = new EpayCustomer($params);

return $customer->deleteCustomer();

EpayTransaction Class

The EpayTransaction Class handles the creation of the Transaction object and the associated api calls.

Parameters

EpayTransaction parameters are:

  • trankey String
  • refnum String
  • invoice String
  • ponum String
  • orderid String
  • description String
  • comments String
  • email String
  • merchemailaddr String
  • amount Float
  • amount_detail Transactions\EpayAmountDetail
  • creditcard Transactions\EpayCreditCard
  • save_card Bool
  • traits Transactions\EpayTrait
  • custkey String
  • save_customer Bool
  • save_customer_paymethod Bool
  • billing_address Transactions\EpayCustomerAddress
  • shipping_address Transactions\EpayCustomerAddress
  • lineitmes Transactions\EpayLineItem
  • custom_fields Transactions\EpayCustomField
  • currency String
  • terminal String
  • clerk String
  • clientip String
  • software String

EpayTransaction Methods w/ default required params

listAuthorized()

  • Route : GET epay/transaction/list
  • Required : none

listAuthorized()

  • Route : GET epay/transaction/list
  • Required : trankey

createSale()

  • Route : POST epay/transaction/sale
  • Required : amount, payment_key (if no creditcard), creditcard (if no payment_key)

createRefund()

  • Required : amount, creditcard

createVoid()

  • Route : POST epay/transaction/void
  • Required : trankey (if no refnum), refnum (if no trankey)

authorizeTransaction()

  • Route : POST epay/transaction/auth
  • Required : amount, payment_key (if no creditcard), creditcard (if no payment_key)

captureTransaction()

  • Route : POST epay/transaction/capture
  • Required : trankey (if no refnum), refnum (if no trankey)

EpayTransaction Child Classes

EpayAmountDetail Class & Parameters

  • subtotal Double
  • tax Double
  • nontaxable Bool
  • tip Double
  • discount Double
  • shipping Double
  • duty Double
  • enable_partialauth Bool

EpayCreditCard Class & Parameters

  • cardholder String
  • number String
  • expiration String
  • cvc Int
  • avs_street String
  • avs_postalcode String

EpayCustomerAddress Class & Parameters

  • company String
  • firstname String
  • lastname String
  • street String
  • street2 String
  • city String
  • state String
  • postalcode String
  • country String
  • phone String
  • fax; String

EpayLineItem Class & Parameters

  • product_key String
  • name String
  • cost Double
  • qty Int
  • description String
  • sku String
  • taxable Bool
  • tax_amount Double
  • tax_rate String
  • discount_rate String
  • discount_amount Double
  • location_key String
  • commodity_code String

EpayTrait Class & Parameters

  • is_debt Bool
  • is_bill_pay Bool
  • is_recurring Bool
  • is_healthcare Bool
  • is_cash_advance Bool
  • secure_collection Int

EpayBatch Class

The EpayBatch Class handles the creation of the Batch object and the associated api calls.

Parameters

EpayBatch parameters are:

  • limit Int
  • offset Int
  • openedlt String
  • openedgt String
  • closedlt String
  • closedgt String
  • openedle String
  • openedge String
  • closedle String
  • closedge String
  • batch_key String

EpayBatch Methods w/ default required params

listBatches()

  • Route : GET epay/batch/list
  • Required : none

currentBatch()

  • Route : GET epay/batch/current
  • Required : none

retrieveBatch()

  • Route : POST epay/batch/retrieve
  • Required : batch_key

getCurrentBatchTransactions()

  • Route : GET epay/batch/currentTransactions
  • Required : none

getTransactionsByBatch()

  • Route : GET epay/batch/transactionsByBatch
  • Required : trankey (if no refnum), refnum (if no trankey)

closeBatch()

  • Route : POST epay/batch/close
  • Required : batch_key

EpayProduct Class

The EpayProduct Class handles the creation of the Product object and the associated api calls.

Parameters

  • name String
  • price Float
  • enabled Bool
  • taxable Bool
  • available_all Bool
  • available_all_date String
  • categoryid Int
  • commodity_code String
  • date_available String
  • description String
  • list_price Float
  • wholesale_price Float
  • manufacturer String
  • merch_productid String
  • min_quantity Int
  • model String
  • physicalgood Bool
  • weight Int
  • ship_weight Int
  • sku String
  • taxclass String
  • um String
  • upc String
  • url String
  • allow_override Bool
  • product_key String
  • limit Int
  • offset Int
  • inventory Array
  • modifiers Array

EpayProduct Methods w/ default required params

listProducts()

  • Route : GET epay/product/list
  • Required : none

createProduct()

  • Route : POST epay/product/create
  • Required : name

getProduct()

  • Route : GET epay/product/get
  • Required : product_key

updateProduct()

  • Route : POST epay/product/update
  • Required : product_key

deleteProduct()

  • Route : POST epay/product/delete
  • Required : product_key

EpayCategory Class

The EpayCategory Class handles the creation of the Category object and the associated api calls.

Parameters

  • name String
  • categorykey String
  • limit Int
  • offset Int
  • modifiers Array

EpayCategory Methods w/ default required params

listCategories()

  • Route : GET epay/category/list
  • Required : none

createCategory()

  • Route : POST epay/category/create
  • Required : name

getCategory()

  • Route : GET epay/category/get
  • Required : category_key

updateCategory()

  • Route : POST epay/category/update
  • Required : category_key

deleteCategory()

  • Route : POST epay/category/delete
  • Required : category_key

EpayInventory Class

(COMING SOON)

Parameters (COMING SOON)

EpayInventory Methods w/ default required params (COMING SOON)

Examples

The following is an example of creating a View in Laravel that utilizes a Vue Component

Example View

<!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>

Example Vue Component

<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>

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Credits

License

The USAePay REST API Package for Laravel is open-sourced software licensed under the MIT license.

apvanlaan/usaepay 适用场景与选型建议

apvanlaan/usaepay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 292 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「usaepay」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 apvanlaan/usaepay 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 apvanlaan/usaepay 我们能提供哪些服务?
定制开发 / 二次开发

基于 apvanlaan/usaepay 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 292
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-10