Skip to content

Commit

Permalink
Merge branch 'feature/payment_provider_gateway' of https://github.com…
Browse files Browse the repository at this point in the history
…/buckaroo-it/Magento2 into feature/clean_payment_provider_gateway
  • Loading branch information
LucianTuriacArnia committed Oct 31, 2022
2 parents bf600be + 096ccd0 commit 649d4a8
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Gateway/Request/LocaleDataBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Buckaroo\Magento2\Gateway\Request;

use Magento\Sales\Api\Data\OrderAddressInterface;

class LocaleDataBuilder extends AbstractDataBuilder
{
public function build(array $buildSubject): array
{
parent::initialize($buildSubject);

return ['locale' => $this->getLocaleCode()];
}

private function getLocaleCode(): string
{
$country = $this->getOrder()->getBillingAddress()->getCountryId();

if ($country == 'CN') {
$localeCode = 'zh-CN';
} elseif ($country == 'TW') {
$localeCode = 'zh-TW';
} else {
$localeCode = 'en-US';
}
return $localeCode;
}
}
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@

<buckaroo_magento2_wechatpay>
<active>0</active>
<model>Buckaroo\Magento2\Model\Method\Wechatpay</model>
<model>WechatpayFacade</model>
<order_status>pending</order_status>
<title>Buckaroo WeChatPay</title>
<allowspecific>0</allowspecific>
Expand Down
119 changes: 118 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@
<arguments>
<argument name="requestBuilder" xsi:type="object">BuckarooOrderRequest</argument>
<argument name="transferFactory" xsi:type="object">Buckaroo\Magento2\Gateway\Http\SDKTransferFactory</argument>
<argument name="client" xsi:type="object">Buckaroo\Magento2\Gateway\Http\Client\TransactionPay</argument>
<argument name="client" xsi:type="object">Buckaroo\Magento2\Gateway\Http\Client\TransactionPayRemainder</argument>
<argument name="handler" xsi:type="object">OrderResponseHandler</argument>
<argument name="validator" xsi:type="object">Buckaroo\Magento2\Gateway\Validator\ResponseCodeSDKValidator</argument>
<argument name="errorMessageMapper" xsi:type="object">Buckaroo\Magento2\Gateway\ErrorMapper\VirtualErrorMessageMapper</argument>
Expand Down Expand Up @@ -4113,4 +4113,121 @@
<!-- END SepaDirectDebit Order Command -->
<!-- END SepaDirectDebit Commands infrastructure -->
<!-- END Payment Method: SepaDirectDebit -->


<!-- Payment Method: Wechatpay -->
<!-- Wechatpay Payment Method Facade configuration -->
<virtualType name="WechatpayFacade" type="Buckaroo\Magento2\Model\Method\BuckarooAdapter">
<arguments>
<argument name="code" xsi:type="const">Buckaroo\Magento2\Model\ConfigProvider\Method\Wechatpay::CODE</argument>
<argument name="formBlockType" xsi:type="string">Magento\Payment\Block\Form</argument>
<argument name="infoBlockType" xsi:type="string">Buckaroo\Magento2\Block\Info</argument>
<argument name="valueHandlerPool" xsi:type="object">WechatpayValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">WechatpayValidatorPool</argument>
<argument name="commandPool" xsi:type="object">WechatpayGatewayCommandPool</argument>
<argument name="usesRedirect" xsi:type="boolean">true</argument>
</arguments>
</virtualType>

<!-- Wechatpay Value handlers infrastructure -->
<virtualType name="WechatpayValueHandlerPool" type="Magento\Payment\Gateway\Config\ValueHandlerPool">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="default" xsi:type="string">WechatpayConfigValueHandler</item>
</argument>
</arguments>
</virtualType>
<!-- Configuration reader -->
<virtualType name="WechatpayConfigValueHandler" type="Magento\Payment\Gateway\Config\ConfigValueHandler">
<arguments>
<argument name="configInterface" xsi:type="object">Buckaroo\Magento2\Model\ConfigProvider\Method\Wechatpay</argument>
</arguments>
</virtualType>
<!-- END Wechatpay Value handlers infrastructure -->

<!-- Wechatpay validators infrastructure -->
<virtualType name="WechatpayValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">WechatpayCountryValidator</item>
</argument>
</arguments>
</virtualType>
<virtualType name="WechatpayCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">Buckaroo\Magento2\Model\ConfigProvider\Method\Wechatpay</argument>
</arguments>
</virtualType>
<!-- END Wechatpay validators infrastructure -->

<!-- Wechatpay Commands infrastructure -->
<virtualType name="WechatpayGatewayCommandPool" type="Magento\Payment\Gateway\Command\CommandPool">
<arguments>
<argument name="commands" xsi:type="array">
<item name="order" xsi:type="string">WechatpayOrderCommand</item>
<item name="refund" xsi:type="string">BuckarooRefundCommand</item>
</argument>
</arguments>
</virtualType>

<!-- Wechatpay Order Command -->
<virtualType name="WechatpayOrderCommand" type="Magento\Payment\Gateway\Command\GatewayCommand">
<arguments>
<argument name="requestBuilder" xsi:type="object">WechatpayOrderRequest</argument>
<argument name="transferFactory" xsi:type="object">Buckaroo\Magento2\Gateway\Http\SDKTransferFactory</argument>
<argument name="client" xsi:type="object">Buckaroo\Magento2\Gateway\Http\Client\TransactionPay</argument>
<argument name="handler" xsi:type="object">OrderResponseHandler</argument>
<argument name="validator" xsi:type="object">Buckaroo\Magento2\Gateway\Validator\ResponseCodeSDKValidator</argument>
<argument name="errorMessageMapper" xsi:type="object">Buckaroo\Magento2\Gateway\ErrorMapper\VirtualErrorMessageMapper</argument>
</arguments>
</virtualType>

<!-- Wechatpay Order Command - Request Builder -->
<virtualType name="WechatpayOrderRequest" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments>
<argument name="builders" xsi:type="array">
<item name="order_request" xsi:type="string">BuckarooOrderRequest</item>
<item name="locale" xsi:type="string">Buckaroo\Magento2\Gateway\Request\LocaleDataBuilder</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CustomerWechatpayDataBuilder" type="Buckaroo\Magento2\Gateway\Request\BuckarooBuilderComposite">
<arguments>
<argument name="builders" xsi:type="array">
<item name="billing" xsi:type="string">WechatpayBillingDataBuilder</item>
<item name="shipping" xsi:type="string">WechatpayShippingDataBuilder</item>
</argument>
</arguments>
</virtualType>

<virtualType name="WechatpayBillingDataBuilder" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments>
<argument name="builders" xsi:type="array">
<item name="recipient" xsi:type="string">Buckaroo\Magento2\Gateway\Request\Recipient\WechatpayDataBuilder</item>
<item name="address" xsi:type="string">Buckaroo\Magento2\Gateway\Request\BillingAddressDataBuilder</item>
<item name="phone" xsi:type="string">Buckaroo\Magento2\Gateway\Request\PhoneDataBuilder</item>
<item name="email" xsi:type="string">Buckaroo\Magento2\Gateway\Request\EmailAddressDataBuilder</item>
</argument>
</arguments>
</virtualType>

<virtualType name="WechatpayShippingDataBuilder" type="Magento\Payment\Gateway\Request\BuilderComposite">
<arguments>
<argument name="builders" xsi:type="array">
<item name="recipient" xsi:type="string">WechatpayShippingRecipientDataBuilder</item>
<item name="address" xsi:type="string">Buckaroo\Magento2\Gateway\Request\ShippingAddressDataBuilder</item>
<item name="phone" xsi:type="string">PhoneShippingDataBuilder</item>
<item name="email" xsi:type="string">EmailAddressShippingDataBuilder</item>
</argument>
</arguments>
</virtualType>

<virtualType name="WechatpayShippingRecipientDataBuilder" type="Buckaroo\Magento2\Gateway\Request\Recipient\WechatpayDataBuilder">
<arguments>
<argument name="addressType" xsi:type="string">shipping</argument>
</arguments>
</virtualType>
<!-- END Wechatpay Order Command -->
<!-- END Wechatpay Commands infrastructure -->
<!-- END Payment Method: Wechatpay -->
</config>

0 comments on commit 649d4a8

Please sign in to comment.