Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adicionado status PAYMENT_REVIEW para novos pedidos e habilitado rotina de checagem de status de pedidos por padrão #309

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
f7d8ef3
Adicionado status PAYMENT_REVIEW para novos pedidos e habilitado roti…
eneiasramos Jun 13, 2022
56d7088
Adicionado status PAID para pedidos que foram pagos
eneiasramos Jun 14, 2022
b11e879
Ajustado algumas configurações padrão em config.xml
eneiasramos Jun 14, 2022
8a8d3c2
Atualizado modulo RicardoMartins_PagSeguro: alterado atributo padrão …
eneiasramos Jun 16, 2022
5f8876b
Atualizado modulo RicardoMartins_PagSeguro: adicionado suporte a hash…
eneiasramos Jun 16, 2022
a3e6324
Adicionado suporte a pagamento via API
eneiasramos Jun 17, 2022
fe248c1
Ajustado validação para suporte a hash de email
eneiasramos Jun 17, 2022
8698dd7
Adicionado elvis operator para status PAID (em caso de não-configurad…
eneiasramos Jun 17, 2022
1391af2
Adicionado rotina para obter sessionID via API para ser utilizado no …
eneiasramos Aug 14, 2022
b9f0337
Adicionado campo de instruções de pagamento para cartão de crédito
eneiasramos Aug 14, 2022
073d8ff
Adicionado constante CODE para comparar metódo de pagamento
eneiasramos Aug 18, 2022
b367223
Ajustado notificationURL em RicardoMartins_PagSeguro_Helper_Internal:…
eneiasramos Aug 20, 2022
b2ef0bf
Merge branch 'master' into eneiasramos
eneiasramos Dec 15, 2022
974bbfa
Merge branch 'r-martins:master' into eneiasramos
eneiasramos Sep 27, 2023
8ac1985
Atualizado configurações para address_telephone_attribute => cellphon…
eneiasramos Sep 27, 2023
428c24d
Adicionado validação para celular e removido config para dob
eneiasramos Sep 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/code/community/RicardoMartins/PagSeguro/Block/Form/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
class RicardoMartins_PagSeguro_Block_Form_Cc extends Mage_Payment_Block_Form_Cc
{
protected $_instructions = null;

/**
* Set block template
*/
Expand Down Expand Up @@ -162,4 +164,13 @@ public function getCurrentCustomerDocument()

return "";
}

protected function getInstructions()
{
if (is_null($this->_instructions)) {
$this->_instructions = $this->getMethod()->getInstructions();
}

return $this->_instructions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getCreditCardApiCallParams(Mage_Sales_Model_Order $order, $payme
'extraAmount' => $extraAmount,
'notificationURL' => Mage::getUrl(
'ricardomartins_pagseguro/notification',
array('_secure' => true, '_nosid' => $noSID)
array('_store' => $order->getStoreId(), '_secure' => true, '_nosid' => $noSID)
),
);
$params = array_merge($params, $pHelper->getItemsParams($order));
Expand Down
10 changes: 8 additions & 2 deletions app/code/community/RicardoMartins/PagSeguro/Helper/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ protected function _extractPhone($phone)
$phone = substr($phone, 1, strlen($phone));
}

$originalPhone = $phone;
$originalPhone = $phone = substr($phone, -11);

$phone = preg_replace('/^(\d{2})(\d{7,9})$/', '$1-$2', $phone);

Expand Down Expand Up @@ -724,7 +724,13 @@ public function getPaymentHash($param=null)
$registry = ($isAdmin)?$registry->get('PsPayment'):$registry->getData('PsPayment');

if (!$registry) {
return false;
$session = Mage::getSingleton('api/session');

if (!$session->isLoggedIn()) {
return false;
}

$registry = $session->getData('PsPayment');
}

$registry = unserialize($registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ protected function _confirmPayment($payment, $notification)

$order->addStatusHistoryComment
(
sprintf('Fatura #%s criada com sucesso.', $invoice->getIncrementId())
sprintf('Fatura #%s criada com sucesso.', $invoice->getIncrementId()),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se passar como false ele não mudará o status do pedido depois da fatura criada. Não consigo ver sentido neste ser o comportamento padrão. Pedidos com fatura gerada viram Processing (ou outro status associado como padrao pro Processing).

Mage::getStoreConfig('payment/rm_pagsecuro_cc/paid_status') ?: false
);
}
}
Expand Down
15 changes: 15 additions & 0 deletions app/code/community/RicardoMartins/PagSeguro/Model/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @package RicardoMartins_PagSeguro
* @copyright Copyright (c) 2022 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/

class RicardoMartins_PagSeguro_Model_Api extends Mage_Api_Model_Resource_Abstract
{
public function sessionId()
{
return Mage::helper('ricardomartins_pagseguro')->getSessionId();
}
}

17 changes: 16 additions & 1 deletion app/code/community/RicardoMartins/PagSeguro/Model/Payment/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*/
class RicardoMartins_PagSeguro_Model_Payment_Cc extends RicardoMartins_PagSeguro_Model_Abstract
{
protected $_code = 'rm_pagseguro_cc';
const CODE = 'rm_pagseguro_cc';

protected $_code = self::CODE;
protected $_formBlockType = 'ricardomartins_pagseguro/form_cc';
protected $_infoBlockType = 'ricardomartins_pagseguro/form_info_cc';
protected $_isGateway = true;
Expand Down Expand Up @@ -75,6 +77,12 @@ public function assignData($data)
$data = new Varien_Object($data);
}

$session = Mage::getSingleton('api/session');

if ($session->isLoggedIn()) {
$session->setData('PsPayment', serialize($data->getData('PsPayment')));
}

$info = $this->getInfoInstance();

$info->setAdditionalInformation('sender_hash', $this->_pHelper->getPaymentHash('sender_hash'));
Expand Down Expand Up @@ -316,6 +324,8 @@ protected function _order($payment, $amount, $ccIdx)
{
$order = $payment->getOrder();

$order->setState(Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW, true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nem todo pagamento começa como Payment review. Isso poderia confundir o comprador. Ex: Pedido com Boleto deve entrar como Pending e não review. Review só ocorre no caso de análise de fraude de um pagamento realizado/capturado com sucesso.


if ($this->isMultiCardPayment($payment)) {
$cardData = $payment->getAdditionalInformation("cc" . $ccIdx);
$payment->setData("_current_card_index", $ccIdx);
Expand Down Expand Up @@ -1302,4 +1312,9 @@ public function recalculateInstallmentsAndPlaceOrder($payment, $amount)
Mage::throwException($e->getMessage());
}
}

public function getInstructions()
{
return trim($this->getConfigData('instructions'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function toOptionArray()
{
$options = array(
array('value' => 'md5', 'label' => 'MD5'),
array('value' => 'sha256', 'label' => 'SHA256')
array('value' => 'sha256', 'label' => 'SHA256'),
array('value' => 'sha512', 'label' => 'SHA512'),
);

return $options;
Expand Down
15 changes: 13 additions & 2 deletions app/code/community/RicardoMartins/PagSeguro/Model/Source/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RicardoMartins_PagSeguro_Model_Source_Hash
public function toOptionArray()
{
$options = array();
if(!function_exists('hash') || !in_array('sha256',hash_algos()) || !in_array('md5',hash_algos())){
if ($this->_noHashable()) {
$options[] = array('value'=>0, 'label'=>'Não suportado no seu ambiente.');
return $options;
}
Expand All @@ -32,12 +32,23 @@ public function toOptionArray()
*/
public function toArray()
{
if(!function_exists('hash') || !in_array('sha256',hash_algos()) || !in_array('md5',hash_algos())){
if ($this->_noHashable()) {
return array(
0 => Mage::helper('adminhtml')->__('No')
);
}

return Mage::getModel('adminhtml/system_config_source_yesno')->toArray();
}

/**
* @return bool
*/
private function _noHashable()
{
return !function_exists('hash')
|| !in_array('sha512',hash_algos())
|| !in_array('sha256',hash_algos())
|| !in_array('md5',hash_algos());
}
}
39 changes: 39 additions & 0 deletions app/code/community/RicardoMartins/PagSeguro/etc/api.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
/**
* @package RicardoMartins_PagSeguro
* @copyright Copyright (c) 2022 Gamuza Technologies (http://www.gamuza.com.br/)
* @author Eneias Ramos de Melo <[email protected]>
*/
-->

<config>
<api>
<resources>
<ricardomartins_pagseguro translate="title" module="ricardomartins_pagseguro">
<model>ricardomartins_pagseguro/api</model>
<title>RicardoMartins PagSeguro API</title>
<acl>ricardomartins_pagseguro</acl>
<methods>
<session_id translate="title" module="ricardomartins_pagseguro">
<title>Get session ID to process card token.</title>
<acl>ricardomartins_pagseguro/session_id</acl>
<method>sessionId</method>
</session_id>
</methods>
</ricardomartins_pagseguro>
</resources>
<acl>
<resources>
<ricardomartins_pagseguro translate="title" module="ricardomartins_pagseguro">
<title>RicardoMartins PagSeguro API</title>
<sort_order>0</sort_order>
<session_id translate="title" module="ricardomartins_pagseguro">
<title>Session ID</title>
</session_id>
</ricardomartins_pagseguro>
</resources>
</acl>
</api>
</config>

17 changes: 11 additions & 6 deletions app/code/community/RicardoMartins/PagSeguro/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<active>0</active>
<title>Cartão de Crédito - via PagSeguro UOL</title>
<order_status>pending</order_status>
<paid_status>paid</paid_status>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A alteração do status do pedido se dá definindo o status padrão para aquele state. A maioria dos módulos de pagamento usa isso como padrão.
Porque um pedido via Pagseguro + Cartão de credito passaria a usar outro status?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É muito útil para integrações de pedidos, caso seja necessário utilizar um status personalizado para pedidos pagos.

Ou para visualizações de pedidos no admin personalizadas como o do Toluca Store.

Adicionei um fallback para utilizar o status atual caso um novo não for configurado 8698dd7

<allowspecific>0</allowspecific>
<flag>42x20</flag>
<payment_action>order</payment_action>
Expand All @@ -182,18 +183,21 @@
<!--<specificcountry>BR</specificcountry>-->
<group_restriction>0</group_restriction>
<info_brl>1</info_brl>
<total_installments>0</total_installments>
<show_total>1</show_total>
<installment_limit>1</installment_limit>
<force_installments_selection>0</force_installments_selection>
<installments_product>0</installments_product>
<installments_product_message>Parcele em até {num_parcelas}x de R${valor_parcela} (Total R${valor_total}) com PagSeguro UOL.</installments_product_message>
<sort_order>1</sort_order>
</rm_pagseguro_cc>
<rm_pagseguro>
<customer_cpf_attribute>taxvat</customer_cpf_attribute>
<address_telephone_attribute>telephone</address_telephone_attribute>
<customer_cpf_attribute>customer|taxvat</customer_cpf_attribute>
<address_telephone_attribute>cellphone</address_telephone_attribute>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não temos atributo cellphone por padrão. (pelo menos nao no openmage 20.0.13 que estou usando pra teste)

<address_street_attribute>street_1</address_street_attribute>
<address_number_attribute>street_2</address_number_attribute>
<address_neighborhood_attribute>street_2</address_neighborhood_attribute>
<address_complement_attribute>street_3</address_complement_attribute>
<address_neighborhood_attribute>street_4</address_neighborhood_attribute>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boa. Não sei como deixei isso passar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aconteceu meu caro :)

<notification_url_nosid>1</notification_url_nosid>
<ws_url>https://ws.pagseguro.uol.com.br/v2/</ws_url>
<ws_url_app>https://ws.ricardomartins.net.br/pspro/v7/wspagseguro/v2/</ws_url_app>
<js_url>https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.directpayment.js</js_url>
Expand All @@ -204,8 +208,9 @@
<jsdelivr_enabled>1</jsdelivr_enabled>
<jsdelivr_minify>1</jsdelivr_minify>
<stc_mirror>1</stc_mirror>
<updater_enabled>0</updater_enabled>
<send_status_change_email>0</send_status_change_email>
<updater_enabled>1</updater_enabled>
<send_invoice_email>1</send_invoice_email>
<send_status_change_email>1</send_status_change_email>
</rm_pagseguro>
<rm_pagseguro_kiosk>
<active>0</active>
Expand Down
19 changes: 18 additions & 1 deletion app/code/community/RicardoMartins/PagSeguro/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</order_status>
<paid_status translate="label">
<label>Paid Order Status</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_order_status</source_model>
<sort_order>22</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</paid_status>
<flag>
<label>Tamanho da bandeira do cartão</label>
<frontend_type>select</frontend_type>
Expand Down Expand Up @@ -506,12 +515,20 @@
<allowspecific>1</allowspecific>
</depends>
</specificcountry>
<instructions translate="label" module="Payment">
<label>Instructions</label>
<frontend_type>textarea</frontend_type>
<sort_order>220</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</instructions>
<multicc_active translate="label,comment" module="Payment">
<label>Enable 2 cards payment</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<backend_model>ricardomartins_pagseguro/system_config_backend_validateMultiCc</backend_model>
<sort_order>220</sort_order>
<sort_order>230</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ $multiCcEnabled = Mage::helper('ricardomartins_pagseguro')->isMultiCcEnabled();
</div>
</li>
*/ ?>
<?php if ($this->getInstructions()): ?>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O que o motivou a ter instruções adicionais pra pedidos com cartão? (curiosidade)

<li>
<div class="<?php echo $_code; ?>-instructions-content agreement-content">
<?php echo nl2br($this->getInstructions()) ?>
</div>
</li>
<?php endif; ?>
<?php if ($multiCcEnabled):?>
<li>
<label for="multicc"><?php echo __('Pay with 2 cards')?></label>
Expand Down
3 changes: 2 additions & 1 deletion app/locale/pt_BR/RicardoMartins_PagSeguro.csv
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@
"invalid security field","código de segurança inválido"
"PagSeguro: Payment with two credit cards is only available in the application model. Authorize your account for free to enable it.","PagSeguro: Pagamento com dois cartões só está disponível no modelo de aplicação. Autorize sua conta gratuitamente."
"Not applicable","Não aplicável"
"Show Download PDF Button","Mostrar Botão de Download em PDF"
"Show Download PDF Button","Mostrar Botão de Download em PDF"
"Paid Order Status","Status Pago do Pedido"