apvanlaan / usaepay
允许轻松连接和使用Laravel的USAePay REST API
Requires
- illuminate/support: ~5|~6|~7|~8|~9
- usaepay/usaepay-php: ^2.0
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~3|~4
- phpunit/phpunit: ^8.0
- sempro/phpunit-pretty-print: ^1.0
- dev-master
- v1.1
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- 1.0
- dev-dependabot/npm_and_yarn/minimist-1.2.8
- dev-dependabot/composer/symfony/http-kernel-4.4.50
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/qs-and-express-6.11.0
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-and-resolve-url-loader-1.4.2
- dev-dependabot/npm_and_yarn/color-string-1.9.1
- dev-dependabot/npm_and_yarn/axios-0.21.2
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/ajv-6.12.6
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/composer/league/flysystem-1.1.4
- dev-dependabot/npm_and_yarn/ws-6.2.2
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
This package is auto-updated.
Last update: 2024-09-05 08:11:00 UTC
README
该项目由Aaron VanLaan创建并维护:Aaron VanLaan.
使用方法
目录
- 要求
- 安装
- EpayCustomer 类
- EpayTransaction 类
- EpayBatch 类
- EpayProduct 类
- EpayCategory 类
- EpayInventory 类(即将推出)
- 示例
要求
该库使用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\EpayAmountDetailcreditcard
Transactions\EpayCreditCardsave_card
布尔值traits
交易\epayTraitcustkey
字符串save_customer
布尔型save_customer_paymethod
布尔型billing_address
交易\epayCustomerAddressshipping_address
交易\epayCustomerAddresslineitmes
交易\epayLineItemcustom_fields
交易\epayCustomFieldcurrency
字符串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 许可。