craftcms / commerce-sagepay
Sage Pay 集成插件,适用于 Craft Commerce 4.0+/5.0+
5.1.0
2024-03-14 16:06 UTC
Requires
- php: ^8.0.2
- craftcms/cms: ^4.0.0-RC3|^5.0.0-beta.7
- craftcms/commerce: ^4.0.0-RC1|^5.0.0-beta.1
- craftcms/commerce-omnipay: ^4.1.0
- omnipay/sagepay: ^4.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- craftcms/rector: dev-main
This package is auto-updated.
Last update: 2024-09-21 17:14:41 UTC
README
Sage Pay for Craft Commerce
本插件为 Sage Pay 提供与 Craft Commerce 的集成。
提示:此插件使用 SagePay/Opayo API 的
4.00
版本。
要求
本插件需要以下之一:
- Craft 4.0 和 Craft Commerce 4.0 或更高版本
- Craft 5.0 和 Craft Commerce 5.0 或更高版本
安装
您可以从插件商店或使用 Composer 安装此插件。
从插件商店
前往项目控制面板中的插件商店,搜索“Sage Pay for Craft Commerce”,然后在模态窗口中点击“安装”按钮。
使用 Composer
打开您的终端,并运行以下命令
# go to the project directory cd /path/to/my-project.test # tell Composer to load the plugin composer require craftcms/commerce-sagepay # tell Craft to install the plugin ./craft install/plugin commerce-sagepay
设置
要添加 Sage Pay 支付网关,请转到“Commerce”→“设置”→“网关”,创建一个新的网关,并将网关类型设置为“Sage Pay Server”。
提示:网关设置可以设置为环境变量。有关更多信息,请参阅 Craft 文档中的环境配置。
使用传统购物车格式
Sage Pay 提供两种提交购物车数据的格式:Basket
和 BasketXML
。Basket
是传统格式,但它是与 Sage 50 Accounts 集成的唯一方式。
要使用传统格式,只需在网关设置中开启相应的设置。要完成与 Sage 50 Accounts 的集成,您可以使用以下事件:
use \craft\commerce\omnipay\base\Gateway as BaseGateway; Event::on(BaseGateway::class, BaseGatewa::EVENT_AFTER_CREATE_ITEM_BAG, function(ItemBagEvent $itemBagEvent) { $orderLineItems = $itemBagEvent->order->getLineItems(); /** * @var $item Item */ foreach ($itemBagEvent->items as $key => $item) { if (!isset($orderLineItems[$key])) { return; } $orderLineItem = $orderLineItems[$key]; // Make sure that the description and price are the same as we are relying upon the order // of the Order Items and The OmniPay Item Bag to be the same if ($orderLineItem->getDescription() != $item->getDescription()) { return; } if ($orderLineItem->price != $item->getPrice()) { return; } $sku = $orderLineItem->getSku(); // Place the SKU within [] as the Product Record for the Sage 50 Accounts Integration $description = '[' . $sku . ']' . $item->getDescription(); $item->setDescription($description); } });