diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e389eb07..f868de2a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -95,7 +95,7 @@ jobs: with: args: > -Dsonar.php.coverage.reportPaths=coverage/clover.xml - -Dsonar.coverage.exclusions=tests/**,assets/**,templates/**,woo-pagarme-payments.php + -Dsonar.coverage.exclusions=tests/**,assets/**,src/Controller/**,templates/**,woo-pagarme-payments.php -Dsonar.tests=tests/ -Dsonar.sources=src,assets,templates,woo-pagarme-payments.php diff --git a/assets/images/barcode.svg b/assets/images/barcode.svg index 886d25eb..cbe82881 100644 --- a/assets/images/barcode.svg +++ b/assets/images/barcode.svg @@ -1,185 +1,133 @@ - - - + \ No newline at end of file diff --git a/assets/javascripts/admin/pagarme_notices.js b/assets/javascripts/admin/pagarme_notices.js index 0747304f..e39d1fcd 100644 --- a/assets/javascripts/admin/pagarme_notices.js +++ b/assets/javascripts/admin/pagarme_notices.js @@ -1,10 +1,10 @@ -const { __ } = wp.i18n; +/* jshint esversion: 6 */ jQuery(function ($) { $('.pagarme-get-hub-account-info').on('click', function (e) { try { - swal({ - title: ' ', - text: __('Processing', 'woo-pagarme-payments'), + swal.fire({ + title: 'Processando', + icon: 'warning', allowOutsideClick: false }); swal.showLoading(); @@ -16,30 +16,29 @@ jQuery(function ($) { command: 'get' }), success: function (response) { - swal( - __('Success!', 'woo-pagarme-payments'), - __('Dash configuration was retrieved successfully. The page is reloading. Please, wait a moment.', - 'woo-pagarme-payments' - ), - 'success' - ) + swal.fire({ + title: 'Sucesso!', + text: 'As configurações da Dash foram recuperadas com sucesso. A página está recarregando.' + + ' Por favor, aguarde um momento.', + icon: 'success' + }); document.location.reload(true); }, fail: function (response) { - swal( - __('Fail!', 'woo-pagarme-payments'), - __('Dash configuration was not retrieved. Please, try again.', 'woo-pagarme-payments'), - 'error' - ) + swal.fire({ + title: 'Falha!', + text: 'As configurações da Dash não foram recuperadas. Por favor, tente novamente.', + icon: 'error' + }); } }); - } catch (e) { - swal( - __('Fail!', 'woo-pagarme-payments'), - __('Dash configuration was not retrieved. Please, try again.', 'woo-pagarme-payments'), - 'error' - ) + } catch (error) { + swal.fire({ + title: 'Falha!', + text: 'As configurações da Dash não foram recuperadas. Por favor, tente novamente.', + icon: 'error' + }); } }); }); diff --git a/assets/javascripts/admin/pagarme_settings.js b/assets/javascripts/admin/pagarme_settings.js index ce9e240a..62f2d523 100644 --- a/assets/javascripts/admin/pagarme_settings.js +++ b/assets/javascripts/admin/pagarme_settings.js @@ -64,20 +64,19 @@ const element = $(this); const value = element.val(); if (value === 'yes') { - swal({ + swal.fire({ type: 'warning', title: allow_no_address_swal.title, text: allow_no_address_swal.text, showConfirmButton: true, - showCancelButton: true, - cancelButtonText: allow_no_address_swal.cancelButtonText, + showDenyButton: true, + denyButtonText: allow_no_address_swal.cancelButtonText, allowOutsideClick: false, - }).then( - function (confirm) {}, - function (cancel) { + }).then((result) => { + if (!result.isConfirmed) { element.val('no'); } - ); + }); } } ); diff --git a/assets/javascripts/admin/sales/order/view/cancel-capture.js b/assets/javascripts/admin/sales/order/view/cancel-capture.js index 294436bf..0c410767 100644 --- a/assets/javascripts/admin/sales/order/view/cancel-capture.js +++ b/assets/javascripts/admin/sales/order/view/cancel-capture.js @@ -1,3 +1,4 @@ +/* jshint esversion: 6 */ $ = jQuery; const actionsTarget = '[data-ref]:enabled'; const modalTarget = '.modal'; @@ -101,9 +102,9 @@ let pagarmeCancelCapture = { }, requestInProgress: function () { - swal({ - title: ' ', - text: 'Processando...', + swal.fire({ + title: 'Processando', + icon: 'warning', allowOutsideClick: false }); swal.showLoading(); @@ -113,14 +114,14 @@ let pagarmeCancelCapture = { this.lock = false; $( modalTarget ).iziModal('close'); swal.close(); - swal({ - type: 'success', + swal.fire({ + icon: 'success', title: ' ', html: response.data.message, showConfirmButton: false, - timer: 2000 + timer: 2000, + timerProgressBar: true }).then( - function () { }, function (dismiss) { window.location.reload(); } @@ -135,12 +136,13 @@ let pagarmeCancelCapture = { this.lock = false; swal.close(); let data = JSON.parse(xhr.responseText); - swal({ - type: 'error', + swal.fire({ + icon: 'error', title: ' ', html: data.message, showConfirmButton: false, - timer: 2000 + timer: 2000, + timerProgressBar: true }); }, diff --git a/assets/javascripts/front/checkout/model/payment.js b/assets/javascripts/front/checkout/model/payment.js deleted file mode 100644 index 003dc525..00000000 --- a/assets/javascripts/front/checkout/model/payment.js +++ /dev/null @@ -1,34 +0,0 @@ -/* globals wc_pagarme_checkout */ - -jQuery(function ($) { - if (typeof wc_pagarme_checkout !== 'undefined') { - globalThis.wc_pagarme_checkout = wc_pagarme_checkout; - $.jMaskGlobals.watchDataMask = true; - wc_pagarme_checkout.validate = function () { - const checkedPayment = $('form .payment_methods input[name="payment_method"]:checked')?.val(); - if (!checkedPayment) { - return true; - } - const requiredFields = $('#shipping_number:visible, input[data-required=true]:visible,' + - 'select[data-required=true]:visible,' + - `.wc_payment_method.payment_method_${checkedPayment} [data-pagarmecheckout-element="brand-input"]`); - let isValid = true; - requiredFields.each(function (index, item) { - const field = $(item); - const wrapper = field.closest( '.form-row' ); - if (field.val() == 0 || !$.trim(field.val())) { - field.addClass('invalid').val(''); - if (isValid) { - field.focus(); - } - wrapper.addClass('woocommerce-invalid' ); // error - isValid = false; - } - }); - if (!isValid) { - swal('Preencha os campos obrigatórios'); - } - return isValid; - } - } -}); diff --git a/assets/javascripts/front/checkout/model/payment/card.js b/assets/javascripts/front/checkout/model/payment/card.js index 3abe978e..41713c53 100644 --- a/assets/javascripts/front/checkout/model/payment/card.js +++ b/assets/javascripts/front/checkout/model/payment/card.js @@ -1,15 +1,18 @@ /* globals wc_pagarme_checkout */ -/*jshint esversion: 8 */ +/* jshint esversion: 11 */ let pagarmeCard = { limitTokenize: 10, tokenExpirationAttribute: 'data-pagarmecheckout-expiration', cardNumberTarget: 'input[data-element="pagarme-card-number"]', - brandTarget: 'input[data-pagarmecheckout-element="brand-input"]', - valueTarget: 'input[data-pagarmecheckout-element="order-value"]', + cardHolderNameTarget: 'input[data-element="card-holder-name"]', + cardExpiryTarget: 'input[data-element="card-expiry"]', + cardCvvTarget: 'input[data-element="card-cvv"]', + brandTarget: 'input[data-pagarme-element="brand-input"]', + valueTarget: 'input[data-pagarme-element="order-value"]', installmentsTarget: '[data-pagarme-component="installments"]', installmentsInfoTarget: '[data-pagarme-component="installments-info"]', mundiCdn: 'https://cdn.mundipagg.com/assets/images/logos/brands/png/', - tokenElement: '[data-pagarmecheckout-element="token"]', + tokenElement: '[data-pagarme-element="token"]', fieldsetCardElements: 'fieldset[data-pagarmecheckout="card"]', billingCpfId: '#billing_cpf', voucherDocumentHolder: 'input[name="pagarme[voucher][cards][1][document-holder]"]', @@ -202,7 +205,7 @@ let pagarmeCard = { jQuery.ajax({ type: "GET", dataType: "json", - url: 'https://api.mundipagg.com/bin/v1/' + bin, + url: 'https://api.pagar.me/bin/v1/' + bin, async: false, cache: false, success: function (data) { @@ -221,6 +224,17 @@ let pagarmeCard = { let imageSrc = this.getImageSrc(card); let imgElem = jQuery(elem).parent().find('img'); + + const doesNotHaveBrand = !card[0].brand || card[0]?.brand?.length === 0; + if (doesNotHaveBrand) { + pagarmeCard.showErrorInPaymentMethod( + PagarmeGlobalVars.checkoutErrors.pt_BR[ + 'invalidBrand' + ] + ); + return; + } + jQuery(elem).parents('.pagarme-card-number-row').find(this.brandTarget).attr('value', card[0].brand); if (imgElem.length) { imgElem.attr('src', imageSrc); @@ -233,6 +247,24 @@ let pagarmeCard = { ); } }, + showErrorInPaymentMethod: function (error) { + const element = jQuery('input[name$="payment_method"]:checked') + .closest("li") + .find("#wcmp-checkout-errors"); + + swal.close(); + + wc_pagarme_checkout.errorList = `
{errors.inputCvv}
+{errors.inputExpiry}
+{errors.inputHolderName}
+{errors.inputNumber}
++ {backendConfig.instructions} +
+
+
+
{backendConfig.instructions}
-
-
-
+ data-required="true" class="input-text" data-pagarme-element="holder_name">
- + + data-required="true" data-pagarme-element="number"> + data-pagarme-element="brand-input"/>
- + \ No newline at end of file diff --git a/templates/checkout/payment/credit-card.phtml b/templates/checkout/payment/credit-card.phtml index 54ecdc85..bd1381eb 100644 --- a/templates/checkout/payment/credit-card.phtml +++ b/templates/checkout/payment/credit-card.phtml @@ -1,4 +1,5 @@ createBlock( 'qty_cards' => $this->getQtyCards() ] )->toHtml(); + +$this->createBlock( + '\Woocommerce\Pagarme\Block\Checkout\Form\Tds', + 'pagarme.checkout.form.tds', + [ + 'payment_instance' => $this->getPaymentInstance() + ] +)->toHtml(); diff --git a/templates/order/charge.phtml b/templates/order/charge.phtml index fadf32c6..677aac88 100644 --- a/templates/order/charge.phtml +++ b/templates/order/charge.phtml @@ -29,7 +29,8 @@ if (!function_exists('add_action')) { $this->getTransactionClass($transaction), 'pagarme.order.charge.transaction', [ - 'transaction' => $transaction + 'transaction' => $transaction, + 'orderId' => $this->getCharge()->getCode() ] )->toHtml(); ?> diff --git a/tests/Concrete/WoocommercePlatformOrderDecoratorTest.php b/tests/Concrete/WoocommercePlatformOrderDecoratorTest.php new file mode 100644 index 00000000..40b709bb --- /dev/null +++ b/tests/Concrete/WoocommercePlatformOrderDecoratorTest.php @@ -0,0 +1,103 @@ +shouldReceive('get_payment_data') + ->andReturn([ + [ + 'payment_method' => 'credit_card', + 'credit_card' => [ + 'installments' => 1, + 'statement_descriptor' => '', + 'capture' => null, + 'card' => [ + 'billing_address' => [ + 'street' => 'test street', + 'complement' => 'test', + 'number' => '123', + 'zip_code' => '1234567', + 'neighborhood' => 'neighborhood', + 'city' => 'city', + 'state' => 'SP', + 'country' => 'BR', + ], + 'card_token' => 'token_test' + ] + ], + 'amount' => 1000 + ] + ]); + + $paymentMethodName = 'credit_card'; + + $formData = [ + 'payment_method' => $paymentMethodName, + 'brand' => 'visa', + 'installments' => 1, + 'authentication' => ['trans_status' => 'Y', 'tds_server_trans_id' => 'test-trans-id'], + 'pagarmetoken1' => 'token_test' + ]; + + $platformOrderDecorator = new WoocommercePlatformOrderDecorator($formData, 'credit_card'); + + $customerIdMock = Mockery::mock(CustomerId::class); + $customerIdMock->shouldReceive('getValue') + ->andReturn(1); + + $customer = new Customer(); + $customerMock = Mockery::mock($customer); + $customerMock->shouldReceive('getPagarmeId') + ->andReturn($customerIdMock); + $platformOrderDecorator->setCustomer($customerMock); + + $platformOrderMock = Mockery::mock(WC_Order::class); + $platformOrderMock->shouldReceive('get_total') + ->andReturn(10); + $platformOrderMock->shouldReceive('get_total_tax') + ->andReturn(0); + + $platformOrderDecorator->setPlatformOrder($platformOrderMock); + + + $paymentFactoryMock->shouldReceive('createFromJson') + ->withArgs(function ($data) { + $formatedData = json_decode($data, true); + + $card = current($formatedData[AbstractCreditCardPayment::getBaseCode()]); + + return $card['authentication']['status'] === 'Y' + && $card['authentication']['threeDSecure']['transactionId'] === 'test-trans-id'; + }) + ->andReturn([]); + + $result = $platformOrderDecorator->getPaymentMethodCollection(); + + $this->assertIsArray($result); + } +} diff --git a/tests/Model/CheckoutTest.php b/tests/Model/CheckoutTest.php new file mode 100644 index 00000000..88a0bcc4 --- /dev/null +++ b/tests/Model/CheckoutTest.php @@ -0,0 +1,149 @@ +shouldReceive('getBrand') + ->andReturn('visa'); + $cardMock->shouldReceive('getInstallment') + ->andReturn(1); + $cardMock->shouldReceive('getAuthentication') + ->andReturn("{\"trans_status\":\"Y\",\"tds_server_trans_id\":\"test-trans-id\"}"); + $cardMock->shouldReceive('getToken') + ->andReturn('token_test'); + $cardMock->shouldReceive('getOrderValue') + ->andReturnFalse(); + $cardMock->shouldReceive('getSaveCard') + ->andReturnFalse(); + $cardMock->shouldReceive('getWalletId') + ->andReturnFalse(); + + $paymentRequestMock = Mockery::mock(PaymentRequest::class); + $paymentRequestMock->shouldReceive('getPaymentMethod') + ->andReturn('credit_card'); + $paymentRequestMock->shouldReceive('getCards') + ->andReturn([$cardMock]); + $paymentRequestMock->shouldReceive('getData') + ->andReturn([]); + + $_POST[PaymentRequestInterface::PAGARME_PAYMENT_REQUEST_KEY] = $paymentRequestMock; + + $subscriptionMock = Mockery::mock('alias:Woocommerce\Pagarme\Model\Subscription'); + $subscriptionMock->shouldReceive('getRecurrenceCycle') + ->andReturnNull(); + + $orderIdMock = Mockery::mock(OrderId::class); + $orderIdMock->shouldReceive('getValue') + ->andReturn(1); + + $order = new Order(); + $orderMock = Mockery::mock($order); + $orderMock->shouldReceive('getPagarmeId') + ->andReturn($orderIdMock); + + $orderMock->shouldReceive('getStatus') + ->andReturn(OrderStatus::paid()); + + $wcOrderMock = Mockery::mock(WC_Order::class); + $wcOrderMock->shouldReceive('get_total') + ->andReturn(10); + $wcOrderMock->shouldReceive('get_id') + ->andReturn(1); + $wcOrderMock->shouldReceive('set_total') + ->andReturnSelf(); + + $ordersMock->shouldReceive('create_order') + ->withArgs(function ($wcOrder, $paymentMethod, $fields) use ($wcOrderMock) { + return $wcOrder === $wcOrderMock + && $paymentMethod === 'credit_card' + && $fields['authentication']['trans_status'] === 'Y' + && $fields['authentication']['tds_server_trans_id'] === 'test-trans-id'; + }) + ->andReturn($orderMock); + + $orderModelMock = Mockery::mock('overload:Woocommerce\Pagarme\Model\Order'); + $orderModelMock->shouldReceive('getTotalAmountByCharges') + ->andReturn(10); + $orderModelMock->shouldReceive('calculateInstallmentFee') + ->andReturn(0); + $orderModelMock->shouldReceive('update_by_pagarme_status') + ->andReturnSelf(); + $orderModelMock->shouldReceive('getWcOrder') + ->andReturn($wcOrderMock); + + $wcCheckoutMock = Mockery::mock(WC_Checkout::class); + $wcCheckoutMock->shouldReceive('empty_cart') + ->andReturnSelf(); + $woocommerce = new stdClass(); + $woocommerce->cart = $wcCheckoutMock; + Brain\Monkey\Functions\stubs([ + 'WC' => $woocommerce, + ]); + + Brain\Monkey\Functions\stubs([ + 'wp_strip_all_tags', + ]); + + Brain\Monkey\Functions\expect('add_action') + ->once(); + + Brain\Monkey\Functions\expect('do_action') + ->once(); + + $checkout = new Checkout($gatewayMock, $configMock, $ordersMock, $wooOrderRepositoryMock); + + $this->assertTrue($checkout->process($wcOrderMock)); + } +} diff --git a/tests/Model/CoreTest.php b/tests/Model/CoreTest.php new file mode 100644 index 00000000..21d44740 --- /dev/null +++ b/tests/Model/CoreTest.php @@ -0,0 +1,65 @@ +shouldReceive('get_site_url')->andReturn($domain); + $utils->shouldReceive('add_prefix')->andReturn('pagarme-webhook'); + + $getUrl = Core::get_webhook_url(); + + $this->assertEquals($webhookLink, $getUrl); + } + + public function testGetWebhookWithoutCustomUrlWithPath() + { + $domain = "https://mycustomdomain.test"; + $domainWithPath = "https://mycustomdomain.test/app/customPath"; + $webhookLink = $domain . "/wc-api/pagarme-webhook/"; + + $utils = Mockery::mock("alias:Woocommerce\Pagarme\Helper\Utils"); + $utils->shouldReceive('get_site_url')->andReturn($domainWithPath); + $utils->shouldReceive('add_prefix')->andReturn('pagarme-webhook'); + + $getUrl = Core::get_webhook_url(); + + $this->assertEquals($webhookLink, $getUrl); + } + public function testGetWebhookWithoutCustomUrl() + { + $customDomain = "https://mycustomdomain.test"; + $webhookLink = $customDomain . "/wc-api/pagarme-webhook/"; + + $utils = Mockery::mock("alias:Woocommerce\Pagarme\Helper\Utils"); + $utils->shouldReceive('get_site_url')->andReturn($customDomain); + $utils->shouldReceive('add_prefix')->andReturn('pagarme-webhook'); + + $getUrl = Core::get_webhook_url($customDomain); + + $this->assertEquals($webhookLink, $getUrl); + } +} diff --git a/tests/Model/CustomerTest.php b/tests/Model/CustomerTest.php index ead8e510..a13a6796 100644 --- a/tests/Model/CustomerTest.php +++ b/tests/Model/CustomerTest.php @@ -333,4 +333,4 @@ public function testGetPagarmeCustomerIdShouldReturnPagarmeCustomerIdValue() $this->assertSame($id, $responsePagarmeCustomerId); } -} \ No newline at end of file +} diff --git a/tests/Service/AccountServiceTest.php b/tests/Service/AccountServiceTest.php index 91678df5..7e538e9d 100644 --- a/tests/Service/AccountServiceTest.php +++ b/tests/Service/AccountServiceTest.php @@ -4,13 +4,16 @@ use Mockery; use Pagarme\Core\Middle\Model\Account\PaymentEnum; -use Pagarme\Core\Middle\Proxy\AccountProxy; use PagarmeCoreApiLib\Models\GetAccountResponse; use PHPUnit\Framework\TestCase; use Woocommerce\Pagarme\Model\Config; use Woocommerce\Pagarme\Model\CoreAuth; use Woocommerce\Pagarme\Service\AccountService; +/** + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + */ class AccountServiceTest extends TestCase { public function tearDown(): void diff --git a/tests/Service/TdsTokenServiceTest.php b/tests/Service/TdsTokenServiceTest.php new file mode 100644 index 00000000..8667d6be --- /dev/null +++ b/tests/Service/TdsTokenServiceTest.php @@ -0,0 +1,69 @@ +shouldReceive('getIsSandboxMode') + ->andReturnFalse(); + + $tdsTokenService = new TdsTokenService($configMock); + + $token = 'tokentds'; + $getTdsTokenResponseMock = Mockery::mock(GetTdsTokenResponse::class); + $getTdsTokenResponseMock->tdsToken = $token; + + $tdsTokenProxyMock = Mockery::mock('overload:Pagarme\Core\Middle\Proxy\TdsTokenProxy'); + + + $accountId = 'acc_test'; + $tdsTokenProxyMock->shouldReceive('getTdsToken') + ->with('live', $accountId) + ->andReturn($getTdsTokenResponseMock); + + $this->assertSame($token, $tdsTokenService->getTdsToken($accountId)); + } + + public function testShoudGetTdsTokenWithTestEnviroment() + { + Mockery::mock('overload:Woocommerce\Pagarme\Model\CoreAuth'); + $configMock = Mockery::mock(Config::class); + $configMock->shouldReceive('getIsSandboxMode') + ->andReturnTrue(); + + $tdsTokenService = new TdsTokenService($configMock); + + $token = 'tokentds'; + $getTdsTokenResponseMock = Mockery::mock(GetTdsTokenResponse::class); + $getTdsTokenResponseMock->tdsToken = $token; + + $tdsTokenProxyMock = Mockery::mock('overload:Pagarme\Core\Middle\Proxy\TdsTokenProxy'); + + + $accountId = 'acc_test'; + $tdsTokenProxyMock->shouldReceive('getTdsToken') + ->with('test', $accountId) + ->andReturn($getTdsTokenResponseMock); + + $this->assertSame($token, $tdsTokenService->getTdsToken($accountId)); + } +} diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index d6d9c42c..849225fc 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -7,6 +7,7 @@ return array( 'apimatic\\jsonmapper\\' => array($vendorDir . '/apimatic/jsonmapper/src'), + 'Woocommerce\\Pagarme\\Tests\\' => array($baseDir . '/tests'), 'Woocommerce\\Pagarme\\' => array($baseDir . '/src'), 'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'), 'Pagarme\\Core\\Test\\Mock\\' => array($vendorDir . '/pagarme/ecommerce-module-core/tests/mock'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 89229c93..cbbe89fa 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -13,6 +13,7 @@ class ComposerStaticInitbb567e266966327c41fd47379c4c230d ), 'W' => array ( + 'Woocommerce\\Pagarme\\Tests\\' => 26, 'Woocommerce\\Pagarme\\' => 20, ), 'P' => @@ -39,6 +40,10 @@ class ComposerStaticInitbb567e266966327c41fd47379c4c230d array ( 0 => __DIR__ . '/..' . '/apimatic/jsonmapper/src', ), + 'Woocommerce\\Pagarme\\Tests\\' => + array ( + 0 => __DIR__ . '/../..' . '/tests', + ), 'Woocommerce\\Pagarme\\' => array ( 0 => __DIR__ . '/../..' . '/src', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 9ee3d2b5..7a957026 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -305,23 +305,23 @@ }, { "name": "pagarme/ecommerce-module-core", - "version": "2.3.1", - "version_normalized": "2.3.1.0", + "version": "2.4.1", + "version_normalized": "2.4.1.0", "source": { "type": "git", "url": "https://github.com/pagarme/ecommerce-module-core.git", - "reference": "9c9e927cea9b1bf90a499d2146f042f1f7f1c921" + "reference": "3e75e5365882c6806f2ac76e6901ee17815d101e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pagarme/ecommerce-module-core/zipball/9c9e927cea9b1bf90a499d2146f042f1f7f1c921", - "reference": "9c9e927cea9b1bf90a499d2146f042f1f7f1c921", + "url": "https://api.github.com/repos/pagarme/ecommerce-module-core/zipball/3e75e5365882c6806f2ac76e6901ee17815d101e", + "reference": "3e75e5365882c6806f2ac76e6901ee17815d101e", "shasum": "" }, "require": { "ext-json": "*", "monolog/monolog": "<3", - "pagarme/pagarmecoreapi": "v5.6.3", + "pagarme/pagarmecoreapi": "v5.6.4", "php": ">=7.1" }, "require-dev": { @@ -330,7 +330,7 @@ "nesbot/carbon": "1.39.0", "phpunit/phpunit": "^5 | ^6 | ^7 | ^8 | ^9" }, - "time": "2023-11-14T15:38:42+00:00", + "time": "2024-03-07T13:35:21+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -351,23 +351,23 @@ ], "description": "Core component for Pagar.me e-commerce platform modules.", "support": { - "source": "https://github.com/pagarme/ecommerce-module-core/tree/2.3.1" + "source": "https://github.com/pagarme/ecommerce-module-core/tree/2.4.1" }, "install-path": "../pagarme/ecommerce-module-core" }, { "name": "pagarme/pagarmecoreapi", - "version": "v5.6.3", - "version_normalized": "5.6.3.0", + "version": "v5.6.4", + "version_normalized": "5.6.4.0", "source": { "type": "git", "url": "https://github.com/pagarme/pagarme-core-api-php.git", - "reference": "49e0d222c50c69ac3e0debea9b69202e6555d3ef" + "reference": "acab7709b2579221417946b261f6c24710604eb8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pagarme/pagarme-core-api-php/zipball/49e0d222c50c69ac3e0debea9b69202e6555d3ef", - "reference": "49e0d222c50c69ac3e0debea9b69202e6555d3ef", + "url": "https://api.github.com/repos/pagarme/pagarme-core-api-php/zipball/acab7709b2579221417946b261f6c24710604eb8", + "reference": "acab7709b2579221417946b261f6c24710604eb8", "shasum": "" }, "require": { @@ -381,7 +381,7 @@ "require-dev": { "squizlabs/php_codesniffer": "^2.7" }, - "time": "2023-09-28T18:22:12+00:00", + "time": "2023-12-15T13:58:12+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -410,7 +410,7 @@ ], "support": { "issues": "https://github.com/pagarme/pagarme-core-api-php/issues", - "source": "https://github.com/pagarme/pagarme-core-api-php/tree/v5.6.3" + "source": "https://github.com/pagarme/pagarme-core-api-php/tree/v5.6.4" }, "install-path": "../pagarme/pagarmecoreapi" }, diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index c5b4bf7b..45e1d8fe 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -56,18 +56,18 @@ 'dev_requirement' => false, ), 'pagarme/ecommerce-module-core' => array( - 'pretty_version' => '2.3.1', - 'version' => '2.3.1.0', - 'reference' => '9c9e927cea9b1bf90a499d2146f042f1f7f1c921', + 'pretty_version' => '2.4.1', + 'version' => '2.4.1.0', + 'reference' => '3e75e5365882c6806f2ac76e6901ee17815d101e', 'type' => 'library', 'install_path' => __DIR__ . '/../pagarme/ecommerce-module-core', 'aliases' => array(), 'dev_requirement' => false, ), 'pagarme/pagarmecoreapi' => array( - 'pretty_version' => 'v5.6.3', - 'version' => '5.6.3.0', - 'reference' => '49e0d222c50c69ac3e0debea9b69202e6555d3ef', + 'pretty_version' => 'v5.6.4', + 'version' => '5.6.4.0', + 'reference' => 'acab7709b2579221417946b261f6c24710604eb8', 'type' => 'library', 'install_path' => __DIR__ . '/../pagarme/pagarmecoreapi', 'aliases' => array(), diff --git a/vendor/pagarme/ecommerce-module-core/catalog-info.yaml b/vendor/pagarme/ecommerce-module-core/catalog-info.yaml deleted file mode 100644 index 4989ab4b..00000000 --- a/vendor/pagarme/ecommerce-module-core/catalog-info.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: ECOMMERCE MODULE CORE - title: ECOMMERCE MODULE CORE - description: Modulo opensource para unificação de integração para a P&G - namespace: pagarme-psp - annotations: - legacy.stone.tech/owner-email: opensource@pagar.me - legacy.stone.tech/prod-date: 2021-03-30 - labels: - legacy.stone.tech/internal-user-auth-base: not-applicable - legacy.stone.tech/access-request-type: not-applicable - legacy.stone.tech/handle-lgpd: false - legacy.stone.tech/customer-auth-method: not-applicable - stone.tech/endpoint-type: none -spec: - type: library - lifecycle: production - owner: pagarme/opensource-apps-team \ No newline at end of file diff --git a/vendor/pagarme/ecommerce-module-core/composer.json b/vendor/pagarme/ecommerce-module-core/composer.json index 9219d50f..f3afe9d1 100644 --- a/vendor/pagarme/ecommerce-module-core/composer.json +++ b/vendor/pagarme/ecommerce-module-core/composer.json @@ -2,7 +2,7 @@ "name": "pagarme/ecommerce-module-core", "description": "Core component for Pagar.me e-commerce platform modules.", "license": "MIT", - "version": "2.3.1", + "version": "2.4.1", "authors": [ { "name":"Open Source Team" @@ -12,7 +12,7 @@ "require": { "php": ">=7.1", "monolog/monolog": "<3", - "pagarme/pagarmecoreapi": "v5.6.3", + "pagarme/pagarmecoreapi": "v5.6.4", "ext-json": "*" }, "require-dev": { diff --git a/vendor/pagarme/ecommerce-module-core/src/Kernel/Aggregates/Order.php b/vendor/pagarme/ecommerce-module-core/src/Kernel/Aggregates/Order.php index c7aac1ee..cce93df5 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Kernel/Aggregates/Order.php +++ b/vendor/pagarme/ecommerce-module-core/src/Kernel/Aggregates/Order.php @@ -104,6 +104,24 @@ public function getCharges() return $this->charges; } + + /** + * + * @return Transaction|null + */ + public function getPixOrBilletTransaction() + { + foreach ($this->getCharges() as $charge) { + foreach ($charge->getTransactions() as $transaction) { + $type = $transaction->getTransactionType()->getType(); + if ($type === 'pix' || $type === 'boleto') { + return $transaction; + } + } + } + return null; + } + public function applyOrderStatusFromCharges() { if (empty($this->getCharges())) { diff --git a/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/LogService.php b/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/LogService.php index 39e3e6d9..b4605104 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/LogService.php +++ b/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/LogService.php @@ -98,7 +98,7 @@ public function exception(\Exception $exception) $logObject = $this->prepareObject($exception); $code = ' | Exception code: ' . $exception->getCode(); $this->monolog->error($exception->getMessage() . $code, $logObject); - + } catch (\Throwable $th) { //throw $th; } @@ -132,9 +132,6 @@ protected function setFileName() { $base = 'Pagarme_PaymentModule_' . date('Y-m-d'); $fileName = $this->path . DIRECTORY_SEPARATOR . $base; - if ($this->addHost) { - $fileName .= '_' . gethostname(); - } $fileName .= '.log'; $this->fileName = $fileName; } @@ -187,7 +184,9 @@ private function blurSensitiveData($logObject) } } return $logObject; - } catch (\Exception $e) {} + } catch (\Exception $e) { + $this->exception($e); + } } /** diff --git a/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderLogService.php b/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderLogService.php index 73ea0fc7..600b412a 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderLogService.php +++ b/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderLogService.php @@ -16,7 +16,7 @@ public function orderInfo($orderCode, $message, $sourceObject = null) $orderMessage = "Order #$orderCode : $message"; parent::info($orderMessage, $sourceObject); } catch (\Throwable $throwable) { - + $this->orderException($throwable, $orderCode); } } diff --git a/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderService.php b/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderService.php index 21577910..ee1431ef 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderService.php +++ b/vendor/pagarme/ecommerce-module-core/src/Kernel/Services/OrderService.php @@ -243,13 +243,6 @@ public function cancelAtPagarmeByPlatformOrder(PlatformOrderInterface $platformO public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) { try { - $orderInfo = $this->getOrderInfo($platformOrder); - - $this->logService->orderInfo( - $platformOrder->getCode(), - 'Creating order.', - $orderInfo - ); //set pending $platformOrder->setState(OrderState::stateNew()); @@ -257,6 +250,11 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) //build PaymentOrder based on platformOrder $paymentOrder = $this->extractPaymentOrderFromPlatformOrder($platformOrder); + $this->logService->orderInfo( + $platformOrder->getCode(), + 'Creating order.', + $paymentOrder + ); $i18n = new LocalizationService(); @@ -270,13 +268,13 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) $this->logService->orderInfo( $platformOrder->getCode(), "Can't create order. - Force Create Order: {$forceCreateOrder} | Order or charge status failed", - $orderInfo + $paymentOrder ); $charges = $this->createChargesFromResponse($response); $errorMessages = $this->cancelChargesAtPagarme($charges); - $this->addChargeMessagesToLog($platformOrder, $orderInfo, $errorMessages); + $this->addChargeMessagesToLog($platformOrder, $paymentOrder, $errorMessages); $this->persistListChargeFailed($response); @@ -312,7 +310,7 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) $this->logService->orderInfo( $platformOrder->getCode(), "Can't create order. - Force Create Order: {$forceCreateOrder} | Order or charge status failed", - $orderInfo + $paymentOrder ); $message = $i18n->getDashboard( "Can't create payment. " . @@ -326,7 +324,7 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder) $this->logService->orderInfo( $platformOrder->getCode(), $e->getMessage(), - $orderInfo + $paymentOrder ); $exceptionHandler = new ErrorExceptionHandler(); $paymentOrder = new PaymentOrder(); @@ -378,8 +376,6 @@ public function extractPaymentOrderFromPlatformOrder( $order->addPayment($payment); } - $orderInfo = $this->getOrderInfo($platformOrder); - /* This block was commented out because this validation is still problematic in the woocommerce module. TODO: we will need to make the module work with this code block. @@ -416,17 +412,6 @@ public function extractPaymentOrderFromPlatformOrder( return $order; } - /** - * @param PlatformOrderInterface $platformOrder - * @return \stdClass - */ - public function getOrderInfo(PlatformOrderInterface $platformOrder) - { - $orderInfo = new \stdClass(); - $orderInfo->grandTotal = $platformOrder->getGrandTotal(); - return $orderInfo; - } - private function responseHasNoChargesOrFailed($response) { return !isset($response['status']) || diff --git a/vendor/pagarme/ecommerce-module-core/src/Middle/Client.php b/vendor/pagarme/ecommerce-module-core/src/Middle/Client.php index e4644997..9943cc46 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Middle/Client.php +++ b/vendor/pagarme/ecommerce-module-core/src/Middle/Client.php @@ -10,13 +10,16 @@ */ abstract class Client { + const BASE_URI = 'https://hubapi.pagar.me/'; + const DEFAULT_RESOURCE = 'core/v1'; + public $client; abstract public function getHubToken(); - public function __construct() + public function __construct($resource = self::DEFAULT_RESOURCE) { Configuration::$basicAuthPassword = ''; - Configuration::$BASEURI = 'https://hubapi.pagar.me/core/v1'; + Configuration::$BASEURI = self::BASE_URI . $resource; $this->client = $this->services(); } private function auth() diff --git a/vendor/pagarme/ecommerce-module-core/src/Middle/Proxy/TdsTokenProxy.php b/vendor/pagarme/ecommerce-module-core/src/Middle/Proxy/TdsTokenProxy.php new file mode 100644 index 00000000..3f91f3d0 --- /dev/null +++ b/vendor/pagarme/ecommerce-module-core/src/Middle/Proxy/TdsTokenProxy.php @@ -0,0 +1,28 @@ +client = $auth->services(); + } + + public function getTdsToken($environment, $accountId) + { + return $this->client->getTdsToken()->getToken( + $environment, + $accountId + ); + } + +} diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Address.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Address.php index 7a0b7bde..a692f65a 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Address.php +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Address.php @@ -78,7 +78,7 @@ public function setNumber($number) $this->number = substr($numberWithoutLineBreaks, 0, 15); - if (empty($this->number)) { + if (empty($this->number) && ($this->number === null || !is_numeric(trim($this->number)))) { $inputName = $this->i18n->getDashboard('number'); $message = $this->i18n->getDashboard( diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php index 6fd08da8..707110df 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Customer.php @@ -171,12 +171,12 @@ public function setAddress(?Address $address) } /** - * Specify data which should be serialized to JSON - * @link https://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ + * Specify data which should be serialized to JSON + * @link https://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ #[\ReturnTypeWillChange] public function jsonSerialize() { @@ -209,7 +209,7 @@ public function getTypeValue() public function getAddressToSDK() { if ($this->getAddress() !== null) { - return $this->getAddress()->convertToSDKRequest(); + return $this->getAddress()->convertToSDKRequest(); } return null; } @@ -217,7 +217,7 @@ public function getAddressToSDK() public function getPhonesToSDK() { if ($this->getPhones() !== null) { - return $this->getPhones()->convertToSDKRequest(); + return $this->getPhones()->convertToSDKRequest(); } return null; } diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Order.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Order.php index 5fba2ce4..c78e2856 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Order.php +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Order.php @@ -2,6 +2,8 @@ namespace Pagarme\Core\Payment\Aggregates; +use Pagarme\Core\Payment\Aggregates\Payments\AbstractCreditCardPayment; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\AuthenticationStatusEnum; use PagarmeCoreApiLib\Models\CreateOrderRequest; use Pagarme\Core\Kernel\Abstractions\AbstractEntity; use Pagarme\Core\Kernel\Services\LocalizationService; @@ -119,6 +121,7 @@ public function getPayments() public function addPayment(AbstractPayment $payment) { $this->validatePaymentInvariants($payment); + $this->addAdditionalSettingsForPaymentInvariants($payment); $this->blockOverPaymentAttempt($payment); $payment->setOrder($this); @@ -235,6 +238,37 @@ private function validateSavedCreditCardPayment(SavedCreditCardPayment $payment) } } + /** + * @param AbstractPayment $payment + * @return void + */ + private function addAdditionalSettingsForPaymentInvariants(AbstractPayment $payment) + { + $parentClass = get_parent_class($payment); + + if ($parentClass === AbstractCreditCardPayment::class) { + $this->addThreeDSAntiFraudInfo($payment); + } + } + + /** + * @param AbstractCreditCardPayment $payment + * @return void + */ + private function addThreeDSAntiFraudInfo(AbstractCreditCardPayment $payment) + { + $authentication = $payment->getAuthentication(); + if (empty($authentication)) { + return; + } + + $antiFraudEnabled = true; + if (in_array($authentication->getStatus(), AuthenticationStatusEnum::doesNotNeedToUseAntifraudStatuses())) { + $antiFraudEnabled = false; + } + $this->setAntifraudEnabled($antiFraudEnabled); + } + /** * @return bool */ @@ -372,7 +406,7 @@ private function fixRoundedValuesInCharges(&$orderRequest){ } $orderSplitData = $this->getSplitData(); - + $wrongValuesPerRecipient = $this->getRecipientWrongValuesMap($orderRequest, $orderSplitData); if (!$wrongValuesPerRecipient){ @@ -380,7 +414,7 @@ private function fixRoundedValuesInCharges(&$orderRequest){ } $orderRequest = $this->fixRoundedValues($wrongValuesPerRecipient, $orderRequest); - + return $orderRequest; } @@ -395,7 +429,7 @@ private function getRecipientWrongValuesMap($orderRequest, $splitData){ $sellerId = $sellerData['pagarmeId']; $sellerCommission = $sellerData['commission']; - $map[$sellerId] = $sellerCommission; + $map[$sellerId] = $sellerCommission; } diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php index 0383a24e..c2fcf176 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/AbstractCreditCardPayment.php @@ -2,6 +2,7 @@ namespace Pagarme\Core\Payment\Aggregates\Payments; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\Authentication; use PagarmeCoreApiLib\Models\CreateCardRequest; use PagarmeCoreApiLib\Models\CreateCreditCardPaymentRequest; use Pagarme\Core\Kernel\Abstractions\AbstractModuleCoreSetup as MPSetup; @@ -12,6 +13,7 @@ use Pagarme\Core\Kernel\ValueObjects\CardBrand; use Pagarme\Core\Payment\ValueObjects\AbstractCardIdentifier; use Pagarme\Core\Payment\ValueObjects\PaymentMethod; +use PagarmeCoreApiLib\Models\CreatePaymentAuthenticationRequest; abstract class AbstractCreditCardPayment extends AbstractPayment { @@ -27,6 +29,8 @@ abstract class AbstractCreditCardPayment extends AbstractPayment protected $capture; /** @var AbstractCardIdentifier */ protected $identifier; + /** @var Authentication|null */ + protected $authentication; public function __construct() @@ -193,6 +197,31 @@ public function setBrand(CardBrand $brand) $this->brand = $brand; } + /** + * @return Authentication|null + */ + public function getAuthentication() + { + return $this->authentication; + } + + /** + * @param Authentication $authentication + * @return void + */ + public function setAuthentication($authentication) + { + $this->authentication = $authentication; + } + + /** + * @return CreatePaymentAuthenticationRequest + */ + public function getAuthenticationSDK() + { + return $this->authentication->convertToSDKRequest(); + } + #[\ReturnTypeWillChange] public function jsonSerialize() { @@ -203,6 +232,9 @@ public function jsonSerialize() $obj->statementDescriptor = $this->statementDescriptor; $obj->capture = $this->capture; $obj->identifier = $this->identifier; + if (!empty($this->authentication)) { + $obj->authentication = $this->authentication; + } return $obj; } @@ -231,6 +263,9 @@ protected function convertToPrimitivePaymentRequest() $cardRequest->installments = $this->getInstallments(); $cardRequest->recurrenceCycle = $this->getRecurrenceCycle(); $cardRequest->statementDescriptor = $this->getStatementDescriptor(); + if (!empty($this->getAuthentication())) { + $cardRequest->authentication = $this->getAuthenticationSDK(); + } return $cardRequest; } diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/Authentication/Authentication.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/Authentication/Authentication.php new file mode 100644 index 00000000..7ba150fa --- /dev/null +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/Authentication/Authentication.php @@ -0,0 +1,137 @@ +type; + } + + /** + * @param string $type + * @return void + */ + public function setType(string $type) + { + $this->type = $type; + } + + /** + * @return ThreeDSecure + */ + public function getThreeDSecure() + { + return $this->threeDSecure; + } + + /** + * @param ThreeDSecure $threeDSecure + * @return void + */ + public function setThreeDSecure(ThreeDSecure $threeDSecure) + { + $this->threeDSecure = $threeDSecure; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $status + * @return void + */ + public function setStatus(string $status) + { + $this->status = $status; + } + + /** + * @return CreateThreeDSecureRequest + */ + public function getThreeDSecureSDK() + { + return $this->threeDSecure->convertToSDKRequest(); + } + + /** + * @return CreatePaymentAuthenticationRequest + */ + public function convertToSDKRequest() + { + $authenticationRequest = new CreatePaymentAuthenticationRequest(); + $authenticationRequest->type = $this->getType(); + if (self::isThreeDSecureType($this)) { + $authenticationRequest->threedSecure = $this->getThreeDSecureSDK(); + } + return $authenticationRequest; + } + + /** + * @return mixed + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $obj = parent::jsonSerialize(); + + $obj->type = $this->getType(); + $obj->transactionId = $this->getThreeDSecure(); + return $obj; + } + + /** + * @param stdClass $object + * @return self + */ + public static function createFromStdClass(stdClass $object) + { + $authentication = new self(); + $authentication->setType($object->type); + $authentication->setStatus($object->status); + if (self::isThreeDSecureType($authentication)) { + $authentication->setThreeDSecure(ThreeDSecure::createFromStdClass($object->threeDSecure)); + } + return $authentication; + } + + /** + * @param Authentication $authentication + * @return bool + */ + private static function isThreeDSecureType(Authentication $authentication) + { + return $authentication->getType() === ThreeDSecure::TYPE; + } +} diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/Authentication/AuthenticationStatusEnum.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/Authentication/AuthenticationStatusEnum.php new file mode 100644 index 00000000..831680cd --- /dev/null +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Payments/Authentication/AuthenticationStatusEnum.php @@ -0,0 +1,80 @@ +mpi; + } + + /** + * @param string $mpi + * @return void + */ + public function setMpi(string $mpi) + { + $this->mpi = $mpi; + } + + /** + * @return string + */ + public function getTransactionId() + { + return $this->transactionId; + } + + /** + * @param string $transactionId + * @return void + */ + public function setTransactionId(string $transactionId) + { + $this->transactionId = $transactionId; + } + + /** + * @return CreateThreeDSecureRequest + */ + public function convertToSDKRequest() + { + $threeDSecureRequest = new CreateThreeDSecureRequest(); + $threeDSecureRequest->mpi = $this->getMpi(); + $threeDSecureRequest->transactionId = $this->getTransactionId(); + + return $threeDSecureRequest; + } + + /** + * @return mixed + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $obj = parent::jsonSerialize(); + + $obj->mpi = $this->getMpi(); + $obj->transactionId = $this->getTransactionId(); + return $obj; + } + + /** + * @param stdClass $object + * @return self + */ + public static function createFromStdClass(stdClass $object) + { + $threeDSecure = new self(); + $threeDSecure->setMpi($object->mpi); + $threeDSecure->setTransactionId($object->transactionId); + return $threeDSecure; + } +} diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Shipping.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Shipping.php index c0ca66e3..9e2ce697 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Shipping.php +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Aggregates/Shipping.php @@ -86,12 +86,12 @@ public function setAddress(?Address $address) } /** - * Specify data which should be serialized to JSON - * @link https://php.net/manual/en/jsonserializable.jsonserialize.php - * @return mixed data which can be serialized by json_encode, - * which is a value of any type other than a resource. - * @since 5.4.0 - */ + * Specify data which should be serialized to JSON + * @link https://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ #[\ReturnTypeWillChange] public function jsonSerialize() { diff --git a/vendor/pagarme/ecommerce-module-core/src/Payment/Factories/PaymentFactory.php b/vendor/pagarme/ecommerce-module-core/src/Payment/Factories/PaymentFactory.php index d90cef2d..312835a5 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Payment/Factories/PaymentFactory.php +++ b/vendor/pagarme/ecommerce-module-core/src/Payment/Factories/PaymentFactory.php @@ -7,8 +7,8 @@ use Pagarme\Core\Kernel\Services\InstallmentService; use Pagarme\Core\Kernel\ValueObjects\CardBrand; use Pagarme\Core\Kernel\ValueObjects\Id\CustomerId; -use Pagarme\Core\Payment\Aggregates\Customer; use Pagarme\Core\Payment\Aggregates\Payments\AbstractCreditCardPayment; +use Pagarme\Core\Payment\Aggregates\Payments\Authentication\Authentication; use Pagarme\Core\Payment\Aggregates\Payments\BoletoPayment; use Pagarme\Core\Payment\Aggregates\Payments\NewCreditCardPayment; use Pagarme\Core\Payment\Aggregates\Payments\NewDebitCardPayment; @@ -19,7 +19,6 @@ use Pagarme\Core\Payment\ValueObjects\BoletoBank; use Pagarme\Core\Payment\ValueObjects\CardId; use Pagarme\Core\Payment\ValueObjects\CardToken; -use Pagarme\Core\Payment\ValueObjects\CustomerType; use Pagarme\Core\Payment\ValueObjects\PaymentMethod; use Pagarme\Core\Payment\Aggregates\Payments\SavedDebitCardPayment; @@ -127,6 +126,9 @@ private function createBasePayments( $payment->setAmount($cardData->amount); $payment->setInstallments($cardData->installments); $payment->setRecurrenceCycle($cardData->recurrenceCycle ?? null); + if (!empty($cardData->authentication)) { + $payment->setAuthentication(Authentication::createFromStdClass($cardData->authentication)); + } //setting amount with interest if (strcmp($cardDataIndex, \Pagarme\Core\Kernel\ValueObjects\PaymentMethod::VOUCHER)) { diff --git a/vendor/pagarme/ecommerce-module-core/src/Recurrence/Services/SubscriptionService.php b/vendor/pagarme/ecommerce-module-core/src/Recurrence/Services/SubscriptionService.php index 208ffd3d..ac21b25d 100644 --- a/vendor/pagarme/ecommerce-module-core/src/Recurrence/Services/SubscriptionService.php +++ b/vendor/pagarme/ecommerce-module-core/src/Recurrence/Services/SubscriptionService.php @@ -54,17 +54,16 @@ public function createSubscriptionAtPagarme(PlatformOrderInterface $platformOrde { try { $orderService = new OrderService(); - $orderInfo = $orderService->getOrderInfo($platformOrder); - $this->logService->orderInfo( - $platformOrder->getCode(), - 'Creating order.', - $orderInfo - ); $this->setPlatformOrderPending($platformOrder); //build PaymentOrder based on platformOrder $order = $orderService->extractPaymentOrderFromPlatformOrder($platformOrder); + $this->logService->orderInfo( + $platformOrder->getCode(), + 'Creating order.', + $order + ); $subscription = $this->extractSubscriptionDataFromOrder($order); $this->setDiscountCycleSubscription($subscription, $platformOrder); diff --git a/vendor/pagarme/pagarmecoreapi/src/Controllers/TdsTokenController.php b/vendor/pagarme/pagarmecoreapi/src/Controllers/TdsTokenController.php new file mode 100644 index 00000000..3ae4f152 --- /dev/null +++ b/vendor/pagarme/pagarmecoreapi/src/Controllers/TdsTokenController.php @@ -0,0 +1,95 @@ + $accountId, + 'environment' => $environment + ]); + + //validate and preprocess url + $_queryUrl = APIHelper::cleanUrl(Configuration::$BASEURI. $_queryBuilder); + + //prepare headers + $_headers = array ( + 'user-agent' => BaseController::USER_AGENT, + 'Accept' => 'application/json' + ); + //set HTTP basic auth parameters + Request::auth(Configuration::$basicAuthUserName, Configuration::$basicAuthPassword); + + //call on-before Http callback + $_httpRequest = new HttpRequest(HttpMethod::GET, $_headers, $_queryUrl); + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnBeforeRequest($_httpRequest); + } + + //and invoke the API call request to fetch the response + $response = Request::get($_queryUrl, $_headers); + + $_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body); + $_httpContext = new HttpContext($_httpRequest, $_httpResponse); + + //call on-after Http callback + if ($this->getHttpCallBack() != null) { + $this->getHttpCallBack()->callOnAfterRequest($_httpContext); + } + + //handle errors defined at the API level + $this->validateResponse($_httpResponse, $_httpContext); + + $mapper = $this->getJsonMapper(); + + return $mapper->mapClass($response->body, 'PagarmeCoreApiLib\\Models\\GetTdsTokenResponse'); + } +} diff --git a/vendor/pagarme/pagarmecoreapi/src/Models/GetTdsTokenResponse.php b/vendor/pagarme/pagarmecoreapi/src/Models/GetTdsTokenResponse.php new file mode 100644 index 00000000..9a0ef37d --- /dev/null +++ b/vendor/pagarme/pagarmecoreapi/src/Models/GetTdsTokenResponse.php @@ -0,0 +1,41 @@ +tdsToken = func_get_arg(0); + } + } + + /** + * Encode this object to JSON + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + $json = array(); + $json['tds_token'] = $this->tdsToken; + return $json; + } +} diff --git a/vendor/pagarme/pagarmecoreapi/src/PagarmeCoreApiClient.php b/vendor/pagarme/pagarmecoreapi/src/PagarmeCoreApiClient.php index 17780298..a8199571 100644 --- a/vendor/pagarme/pagarmecoreapi/src/PagarmeCoreApiClient.php +++ b/vendor/pagarme/pagarmecoreapi/src/PagarmeCoreApiClient.php @@ -105,11 +105,19 @@ public function getTransactions() return Controllers\TransactionsController::getInstance(); } /** - * Singleton access to Transactions controller + * Singleton access to Accounts controller * @return Controllers\AccountsController The *Singleton* instance */ public function getAccounts() { return Controllers\AccountsController::getInstance(); } + /** + * Singleton access to Tds Tokens controller + * @return Controllers\TdsTokenController The *Singleton* instance + */ + public function getTdsToken() + { + return Controllers\TdsTokenController::getInstance(); + } } diff --git a/webpack.config.js b/webpack.config.js index 6c751adc..3ccbb043 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,17 +1,18 @@ -const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); -const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' ); +const defaultConfig = require('@wordpress/scripts/config/webpack.config'); +const DependencyExtractionWebpackPlugin = require('@woocommerce/dependency-extraction-webpack-plugin'); module.exports = { - ...defaultConfig, - plugins: [ - ...defaultConfig.plugins.filter( - (plugin) => - plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' - ), - new DependencyExtractionWebpackPlugin(), - ], - entry: { - pix: './assets/javascripts/front/reactCheckout/payments/pix/index.js', - billet: './assets/javascripts/front/reactCheckout/payments/billet/index.js', - }, -}; \ No newline at end of file + ...defaultConfig, + plugins: [ + ...defaultConfig.plugins.filter( + (plugin) => + plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' + ), + new DependencyExtractionWebpackPlugin(), + ], + entry: { + pix: './assets/javascripts/front/reactCheckout/payments/Pix/index.js', + billet: './assets/javascripts/front/reactCheckout/payments/Billet/index.js', + credit_card: './assets/javascripts/front/reactCheckout/payments/CreditCard/index.js', + }, +}; diff --git a/woo-pagarme-payments.php b/woo-pagarme-payments.php index 6f510fbe..5be4c2d3 100644 --- a/woo-pagarme-payments.php +++ b/woo-pagarme-payments.php @@ -128,7 +128,6 @@ function wcmpAddNoticeButton($buttons) return $html; } - function wcmpAdminNoticePhpVersion() { wcmpRenderAdminNoticeHtml(