我正在创建一个网站,我将在其中销售单件商品,并希望能够通过 Paypal、Google Checkout 和 Amazon 接受付款,但不想仅针对一件商品使用一些繁重的电子商务软件。
我正在寻找一个好的 PHP 解决方案,可以轻松实现所有 3 个,例如 Django 的 Django-Merchant。
谢谢
最佳答案
如果您希望获得有关解决方案架构设计的建议,
首先,您需要创建一个接口(interface),其中包含所有网关所必需的所有方法
interface PaymentGateway {
public function processPayment();
public function authorize();
}
然后为每个支付网关创建具体类
public class GoogleCheckoutGateway extends PaymentGateway {
public function processPayment() {
//Code to process google checkout payment
}
}
//Same like other payment gateways like paypal
public class PaypalCheckoutGateway extends PaymentGateway {
public function processPayment() {
//Code to process paypal payment
}
}
然后创建一个业务逻辑方法通过处理不同的网关来处理支付
public class PaymentProcessor {
public function processPayment(string gateway) {
//Create the respective object depending upon gateway
$gateway = getGateway(type);
$response = $gateway->processPayment();
}
}
此设计将帮助您稍后添加其他网关
关于PHP - 接受多个支付网关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10029880/