Magento2中Adyen Drop-in集成Scalapay的实现方案问询
Magento2 Adyen Drop-in集成Scalapay实现指南
一、整体实现流程
Adyen官方Drop-in已原生支持Scalapay,但Magento2的Adyen连接器未默认集成该支付方式,核心操作是扩展Adyen连接器模块,让Magento能识别并传递Scalapay支付方式到前端Drop-in,再配合Adyen后台配置完成集成。
二、扩展Adyen-Magento连接器步骤
1. 创建自定义扩展模块
新建一个自定义模块(例如YourVendor_AdyenScalapay),目录结构如下:
app/code/YourVendor/AdyenScalapay/ ├── etc/ │ ├── adminhtml/ │ │ └── system.xml │ ├── config.xml │ ├── module.xml │ └── di.xml ├── Model/ │ └── Service/ │ └── DropInService.php └── registration.php
2. 添加后台配置项
在etc/adminhtml/system.xml中新增Scalapay的支付配置(嵌套在Adyen支付组下):
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <section id="payment"> <group id="adyen"> <group id="scalapay" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Scalapay</label> <field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Enable</label> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> <field id="sort_order" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Sort Order</label> </field> <field id="allowspecific" translate="label" type="allowspecific" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Payment from Applicable Countries</label> <source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model> </field> <field id="specificcountry" translate="label" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Applicable Countries</label> <source_model>Magento\Directory\Model\Config\Source\Country</source_model> <depends> <field id="allowspecific">1</field> </depends> </field> <field id="min_order_total" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Minimum Order Total</label> <validate>validate-number validate-zero-or-greater</validate> </field> <field id="max_order_total" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0"> <label>Maximum Order Total</label> <validate>validate-number validate-zero-or-greater</validate> </field> </group> </group> </section> </system> </config>
在etc/config.xml中设置默认配置:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> <default> <payment> <adyen> <scalapay> <active>0</active> <sort_order>10</sort_order> <allowspecific>0</allowspecific> <min_order_total>0</min_order_total> <max_order_total>0</max_order_total> </scalapay> </adyen> </payment> </default> </config>
3. 重写Drop-in服务类传递Scalapay方法
在Model/Service/DropInService.php中重写Adyen的getPaymentMethods方法,添加Scalapay到支付方法列表:
<?php namespace YourVendor\AdyenScalapay\Model\Service; use Magento\Quote\Model\Quote; use Magento\Framework\App\Config\ScopeConfigInterface; use Adyen\Payment\Model\Service\DropInService as AdyenDropInService; class DropInService extends AdyenDropInService { /** * @var ScopeConfigInterface */ protected $scopeConfig; public function __construct( \Adyen\Payment\Model\Config $adyenConfig, \Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Model\Api\PaymentMethods $paymentMethodsApi, ScopeConfigInterface $scopeConfig, \Psr\Log\LoggerInterface $logger, \Magento\Customer\Model\Session $customerSession, \Adyen\Payment\Model\RecurringType $recurringType ) { parent::__construct($adyenConfig, $adyenHelper, $paymentMethodsApi, $logger, $customerSession, $recurringType); $this->scopeConfig = $scopeConfig; } /** * @param Quote $quote * @return array */ public function getPaymentMethods(Quote $quote) { $paymentMethodsResponse = parent::getPaymentMethods($quote); $storeId = $quote->getStoreId(); // 检查Scalapay是否在后台启用,且符合订单条件 if ($this->isScalapayAvailable($quote, $storeId)) { $scalapayMethod = [ 'type' => 'scalapay', 'name' => 'Scalapay', 'configuration' => [ // 可根据需要添加配置,比如logo URL等 ] ]; $paymentMethodsResponse['paymentMethods'][] = $scalapayMethod; } return $paymentMethodsResponse; } /** * 验证Scalapay是否可用 * @param Quote $quote * @param int $storeId * @return bool */ private function isScalapayAvailable(Quote $quote, int $storeId): bool { // 检查是否启用 if (!$this->scopeConfig->isSetFlag('payment/adyen_scalapay/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)) { return false; } // 检查订单金额范围 $minTotal = $this->scopeConfig->getValue('payment/adyen_scalapay/min_order_total', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $maxTotal = $this->scopeConfig->getValue('payment/adyen_scalapay/max_order_total', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $orderTotal = $quote->getGrandTotal(); if (($minTotal > 0 && $orderTotal < $minTotal) || ($maxTotal > 0 && $orderTotal > $maxTotal)) { return false; } // 检查适用国家 $allowsSpecific = $this->scopeConfig->getValue('payment/adyen_scalapay/allowspecific', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); if ($allowsSpecific) { $allowedCountries = explode(',', $this->scopeConfig->getValue('payment/adyen_scalapay/specificcountry', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)); $billingCountry = $quote->getBillingAddress()->getCountryId(); if (!in_array($billingCountry, $allowedCountries)) { return false; } } return true; } }
在etc/di.xml中配置重写:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Adyen\Payment\Model\Service\DropInService" type="YourVendor\AdyenScalapay\Model\Service\DropInService" /> </config>
4. 注册模块
registration.php内容:
<?php use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::MODULE, 'YourVendor_AdyenScalapay', __DIR__);
etc/module.xml内容:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="YourVendor_AdyenScalapay" setup_version="1.0.0"> <sequence> <module name="Adyen_Payment"/> </sequence> </module> </config>
三、关键配置检查
1. Adyen后台配置
- 登录Adyen Merchant Area,在Settings > Payment methods中找到Scalapay,启用并配置商户信息(如Scalapay API密钥、商户ID)
- 确认Scalapay的适用国家与Magento后台配置一致
- 检查Webhook配置,确保
AUTHORISATION、CANCELLATION等事件能正常通知到Magento
2. Magento后台配置
- 进入Stores > Configuration > Sales > Payment Methods > Adyen > Scalapay,启用该支付方式,设置排序、适用国家、订单金额范围
- 确认Adyen主配置(Stores > Configuration > Sales > Payment Methods > Adyen)中的API密钥、Merchant Account、环境(测试/生产)与Adyen后台一致
四、Scalapay不显示的排查步骤
配置层面排查
- 确认Adyen后台已启用Scalapay,且Merchant Account与Magento配置一致
- 检查Magento后台Scalapay是否启用,适用国家、订单金额是否匹配当前订单
- 验证Adyen API密钥是否有权限访问Scalapay支付方式(可通过Adyen测试工具调用
paymentMethods接口查看返回)
代码与日志排查
- 查看
var/log/adyen.log,检查调用AdyenpaymentMethods接口的请求和响应,确认Scalapay是否被添加到返回列表 - 检查自定义模块是否正确启用(
bin/magento module:status),重写是否生效(可通过bin/magento setup:di:compile验证) - 打开浏览器控制台,检查是否有JS错误导致Drop-in渲染失败
- 查看
缓存与静态资源
- 清理Magento缓存:
bin/magento cache:clean - 重新部署静态资源:
bin/magento setup:static-content:deploy -f - 重建索引:
bin/magento indexer:reindex
- 清理Magento缓存:
五、测试验证
- 使用Adyen测试环境,创建符合Scalapay条件的订单(如对应国家、金额范围),检查结账页面是否显示Scalapay选项
- 完成支付流程,验证订单状态是否正确更新,Webhook通知是否被Magento正常接收处理
内容的提问来源于stack exchange,提问作者Sreepriya
相关产品推荐
相关产品推荐

