小程序中ApexMerchant网关支付处理库略谈
发布于 2 年前 作者 leigang 1109 次浏览 来自 分享

一个多网关支付处理库,为Apex和Salesforce / Force.com受到ActiveMerchant的启发,一个集成多个支付处理器的ruby库。

这段代码来自我一直在开发的一个AppExchange/ISV支付应用程序。我投入了大量的时间去开发一个支付库,它支持多个支付网关,并且具有无缝/一致的API,所以我想我应该与社区分享。这个库本质上允许你用几行代码将信用卡和银行支付处理添加到你的Salesforce org或应用程序中。最好的部分是,由于API在所有网关上都是一致的,您可以轻松地切换支付提供商,而无需更改任何代码。这个项目正在进行中,我将在构建AppExchange应用时继续添加它。我希望随着时间的推移,社区将为这个库贡献更多的支付网关,我们都将为Salesforce提供一个简单的支付库。

使用

// Setup gateway options

Map<String, Object> options = new Map<String, Object> {

‘login’ => ‘sk_live_41Y6cbbMW9MQciBRf84hs84j’,

‘password’ => ‘sk_test_RSylZfxqhm65G0yGh4jks94jf’,

‘testMode’ => ‘true’

}

// Setup new instance of merchant passing in your gateway name (Stripe, AuthorizeDotNet, PayPal)

Merchant merchant = new Merchant(‘Stripe’, options);

// Setup credit card payment source

Map<String, Object> source = new Map<String, Object> {

‘name’ => ‘Card’,

‘firstName’ => ‘Charles’,

‘lastName’ => ‘Naccio’,

‘cardNumber’ => ‘4444333322221111’,

‘cvv’ => ‘123’,

‘month’ => ‘12’,

‘year’ => ‘2017’,

‘postalCode’ => ‘75070’

};

// Amount to charge in cents i.e. $1.00 = 100 cents

Integer amount = 100;

// Merchant transaction actions

merchant.purchase(amount, source);

Map<String, Object> reference = merchant.authorize(amount, source).reference;

merchant.capture(amount, reference);

merchant.void(reference);

merchant.refund(amount, reference);

merchant.credit(amount, source);

reference = merchant.store(source).reference;

merchant.unstore(reference);

这个简单的示例演示了如何使用个人的信用卡详细信息处理受支持的事务。

参看资料:

https://weibo.com/ttarticle/p/show?id=2309404697221449777161

https://weibo.com/ttarticle/p/show?id=2309404697222821577015

网关的方法

网关实现的主要方法有:

验证()—验证与支付网关的连接

购买数量,paymentSource[选项])-捕获,并授权在一个事务

授权(数量、paymentSource[选项])-授权支付捕获后

捕获(数量、引用[选项])-获取先前授权的付款

空白(参考[选项])-取消先前的事务

退款(数量、引用[选项])-退款以前的交易

信用(数量、来源、[选项])-在提供的信用卡上赊账

存储(paymentSource[选项])-将信用卡储存在支付供应商处,以备将来使用

unstore(参考[选项])-从支付提供商中删除/删除先前存储的支付方法

我将在将来提供更好的说明,但现在您可以简单地克隆一个现有的支付网关类,例如merchant_Gateway_Stripe为merchant_Gateway_YourMerchantName,并进行必要的更改。代码注释的相当好,所以这应该足以让您开始。

回到顶部