Skip to content

Commit

Permalink
Release 3.4.2
Browse files Browse the repository at this point in the history
Release 3.4.2
  • Loading branch information
fabiano-mallmann authored Oct 31, 2024
2 parents 0abcc9d + 8c5abf3 commit 5e6fd1a
Show file tree
Hide file tree
Showing 49 changed files with 1,473 additions and 477 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Lint
runs-on: ubuntu-latest
container:
image: php:7.2-apache
image: php:7.1-apache
steps:
-
name: Checkout
Expand All @@ -39,7 +39,11 @@ jobs:
php composer.phar --version
-
name: Check PHP sintax
run: find . -name \*.php -exec php -l "{}" \;
run: |
find . -name \*.php -exec php -l "{}" \; | tee errors.log
if grep -q "Sintax errors:" errors.log; then
exit 1
fi
-
name: Install project dependences
run:
Expand Down
58 changes: 58 additions & 0 deletions assets/javascripts/front/checkout/checkoutFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* globals wc_pagarme_checkout */
/* jshint esversion: 6 */
const pagarmeCustomerFields = {
billingDocumentId: 'billing_document',
shippingDocumentId: 'shipping_document',
blocksBillingDocumentId: 'billing-address-document',
blocksShippingDocumentId: 'shipping-address-document',

documentMasks: [
'000.000.000-009999',
'00.000.000/0000-00'
],
documentMaskOptions: {
onKeyPress: function (document, e, field, options) {
const masks = pagarmeCustomerFields.documentMasks,
mask = document.length > 14 ? masks[1] : masks[0];
field.mask(mask, options);
}
},

applyDocumentMask() {
jQuery('#' + this.billingDocumentId).mask(this.documentMasks[0], this.documentMaskOptions);
jQuery('#' + this.shippingDocumentId).mask(this.documentMasks[0], this.documentMaskOptions);
jQuery('#' + this.blocksBillingDocumentId).mask(this.documentMasks[0], this.documentMaskOptions);
jQuery('#' + this.blocksShippingDocumentId).mask(this.documentMasks[0], this.documentMaskOptions);
},

addEventListener() {
jQuery(document.body).on('checkout_error', function () {
const documentFieldIds = [
pagarmeCustomerFields.billingDocumentId,
pagarmeCustomerFields.shippingDocumentId,
pagarmeCustomerFields.blocksBillingDocumentId,
pagarmeCustomerFields.blocksShippingDocumentId
];
jQuery.each(documentFieldIds, function () {
const documentField = '#' + this + '_field',
isDocumentEmpty = jQuery('.woocommerce-error li[data-id="' + this + '"]').length,
isDocumentInvalid = jQuery('.woocommerce-error li[data-pagarme-error="' + this + '"]').length;
if (isDocumentEmpty || isDocumentInvalid) {
jQuery(documentField).addClass('woocommerce-invalid');
} else {
jQuery(documentField).removeClass('woocommerce-invalid');
}
});
});
},

start: function () {
this.addEventListener();

setTimeout(function() {
pagarmeCustomerFields.applyDocumentMask();
}, 5000);
}
};

pagarmeCustomerFields.start();
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,46 @@ const { registerPaymentMethod } = window.wc.wcBlocksRegistry;

import PropTypes from "prop-types";
import Card from "../Card";
import PagarmeGooglePayComponent from "../GooglePay";
import useCreditCard from "./useCreditCard";
import pagarmeTokenStore from "../store/googlepay";
import { useSelect } from "@wordpress/data";

const backendConfig = wc.wcSettings.getSetting(
"woo-pagarme-payments-credit_card_data",
);
const googlePayBackendConfig = wc.wcSettings.getSetting(
"woo-pagarme-payments-googlepay_data",
);

const PagarmeCreditCardComponent = (props) => {
const googleCards = useSelect((select) => {
return select(pagarmeTokenStore).getToken();
});
const { emitResponse, eventRegistration } = props;
useCreditCard(backendConfig, emitResponse, eventRegistration);
const googleActive = googlePayBackendConfig.enabled;
const hasSubscriptionInCart = googlePayBackendConfig.hasSubscriptionInCart;

useCreditCard(backendConfig, emitResponse, eventRegistration, googleCards);
return (
<Card {...props} backendConfig={backendConfig} cardIndex={1} />
<div>
{googleActive && !hasSubscriptionInCart && (
<div>
<PagarmeGooglePayComponent {...props} />
<div className="pagarme_creditcard_divider">
<p>Ou pague com cartão</p>
</div>
</div>
)}
{!googleCards && (
<Card {...props} backendConfig={backendConfig} cardIndex={1} />
)}
</div>
);
};

const PagarmeCreditCardLabel = ({ components }) => {
const { PaymentMethodLabel } = components;

return <PaymentMethodLabel text={backendConfig.label} />;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import TokenizeException from "../Card/token/tokenizeException";
import tokenizeMultiCards from "../Card/token/tokenizeMultiCards";
import { useDispatch, useSelect } from "@wordpress/data";
import { useEffect } from "@wordpress/element";
import pagarmeTokenStore from "../store/googlepay";

const useCreditCard = (backendConfig, emitResponse, eventRegistration) => {
const useCreditCard = (backendConfig, emitResponse, eventRegistration, googleCards) => {
const { reset } = useDispatch(pagarmeCardsStore);

const { reset: resetGoogleToken } = useDispatch(pagarmeTokenStore);
const { onPaymentSetup } = eventRegistration;

const cards = useSelect((select) => {
Expand All @@ -21,6 +22,20 @@ const useCreditCard = (backendConfig, emitResponse, eventRegistration) => {
useEffect(() => {
return onPaymentSetup(async () => {
try {
if (googleCards) {
resetGoogleToken();
return {
type: emitResponse.responseTypes.SUCCESS,
meta: {
paymentMethodData: {
pagarme: JSON.stringify({
['googlepay']: {'googlepay': {['payload']: googleCards}}
}),
payment_method: 'googlepay',
},
},
};
}
let hasErrors = false;
if (typeof cards === 'object') {
hasErrors = Object.values(cards).some((card) => {
Expand Down Expand Up @@ -60,14 +75,13 @@ const useCreditCard = (backendConfig, emitResponse, eventRegistration) => {
if (e instanceof TokenizeException) {
errorMesage = e.message;
}

return {
type: emitResponse.responseTypes.ERROR,
message: errorMesage,
};
}
});
}, [onPaymentSetup, cards, backendConfig]);
}, [onPaymentSetup, cards, backendConfig, googleCards]);
};

export default useCreditCard;
58 changes: 14 additions & 44 deletions assets/javascripts/front/reactCheckout/payments/GooglePay/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import PropTypes from "prop-types";
import GooglePayButton from "@google-pay/button-react";
import useGooglepay from "./useGooglepay";
import { useDispatch, useSelect } from "@wordpress/data";
import { useDispatch } from "@wordpress/data";
import pagarmeTokenStore from "../store/googlepay"

const { registerPaymentMethod } = window.wc.wcBlocksRegistry;

const backendConfig = wc.wcSettings.getSetting(
"woo-pagarme-payments-googlepay_data",
);

const environment = backendConfig.isSandboxMode ? "TEST" : "PRODUCTION";
import validateBilling from "./validateBilling";

const PagarmeGooglePayComponent = (props) => {
const { emitResponse, eventRegistration } = props;

useGooglepay(emitResponse, eventRegistration, backendConfig);
const backendConfig = wc.wcSettings.getSetting(
"woo-pagarme-payments-googlepay_data",
);

const environment = backendConfig.isSandboxMode ? "TEST" : "PRODUCTION";
const billingAddress = props?.billing?.billingAddress;
const {
setToken
} = useDispatch(pagarmeTokenStore);

return (

<GooglePayButton
Expand All @@ -35,7 +28,7 @@ const PagarmeGooglePayComponent = (props) => {
type: "CARD",
parameters: {
allowedAuthMethods: ["PAN_ONLY"],
allowedCardNetworks: ["MASTERCARD", "VISA", "ELO"],
allowedCardNetworks: backendConfig.allowedGoogleBrands,
},
tokenizationSpecification: {
type: "PAYMENT_GATEWAY",
Expand All @@ -59,37 +52,14 @@ const PagarmeGooglePayComponent = (props) => {
},
}}
onLoadPaymentData={(paymentRequest) => {
let googleToken = paymentRequest.paymentMethodData.tokenizationData.token;
setToken(googleToken);
if(validateBilling(billingAddress)) {
let googleToken = paymentRequest.paymentMethodData.tokenizationData.token;
setToken(googleToken);
}
jQuery(".wc-block-components-checkout-place-order-button").click();
}}
/>
);

};

const PagarmeGooglePayLabel = ({ components }) => {
const { PaymentMethodLabel } = components;
return <PaymentMethodLabel text={backendConfig.label} />;
};

PagarmeGooglePayComponent.propTypes = {
emitResponse: PropTypes.object,
eventRegistration: PropTypes.object,
};

PagarmeGooglePayLabel.propTypes = {
components: PropTypes.object,
};


const pagarmeGooglePayPaymentMethod = {
name: backendConfig.name,
label: <PagarmeGooglePayLabel />,
content: <PagarmeGooglePayComponent />,
edit: <PagarmeGooglePayComponent />,
canMakePayment: () => true,
ariaLabel: backendConfig.ariaLabel,
};

registerPaymentMethod(pagarmeGooglePayPaymentMethod);
export default PagarmeGooglePayComponent;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

function validateBilling(billing) {

const requiredFields = [
'first_name',
'last_name',
'email',
'phone',
'address_1',
'city',
'postcode',
'state',
'country'
];
for (const field of requiredFields) {
if (!billing[field]) {
return false;
}
}
return true;
}

export default validateBilling;
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ const pagarmeTokenStore = createReduxStore("pagarme-googlepay", {
reducer(state = DEFAULT_STATE, action) {
switch (action.type) {
case "SET_PROPERTY_VALUE":
// console.log(action);
if (!action.propertyName) {
return state;
}
return {
...state,
[action.propertyName]: action.value,
[action.propertyName]: action.value
};
case "RESET":
return DEFAULT_STATE;
Expand Down
13 changes: 7 additions & 6 deletions assets/stylesheets/front/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,27 @@
font-style: italic;
}

#payment .pagarme_creditcard_divider {
.pagarme_creditcard_divider{
margin: 1em 0 0;
}

#payment .pagarme_creditcard_divider p {
.pagarme_creditcard_divider p {
display: flex;
flex-direction: row;
}

#payment .pagarme_creditcard_divider p:after ,
#payment .pagarme_creditcard_divider p:before {
.pagarme_creditcard_divider p:after,
.pagarme_creditcard_divider p:before {
content: "";
flex: 1 1;
border-bottom: 1px solid;
margin: auto;
}
#payment .pagarme_creditcard_divider p:after {
.pagarme_creditcard_divider p:after {
margin-left: 0.5em;
}
#payment .pagarme_creditcard_divider p:before {

.pagarme_creditcard_divider p:before {
margin-right: 0.5em;
}

Expand Down
2 changes: 1 addition & 1 deletion build/credit_card.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-data', 'wp-element'), 'version' => '568464aca724c57656dd');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-data', 'wp-element'), 'version' => '4df6da733d92f5ffc390');
2 changes: 1 addition & 1 deletion build/credit_card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pagarme/woocommerce-pagarme-payments",
"description": "Pagar.me module for Woocommerce",
"type": "wordpress-plugin",
"version": "3.4.0",
"version": "3.4.2",
"license": "GPL",
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 5e6fd1a

Please sign in to comment.