From c82bed0904a308a5e708e3023597433ef53c8878 Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Sat, 8 Aug 2020 20:35:26 -0300 Subject: [PATCH 1/8] getenv variaveis de ambiente --- woocommerce-imobanco/woocommerce-imobanco.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/woocommerce-imobanco/woocommerce-imobanco.php b/woocommerce-imobanco/woocommerce-imobanco.php index 85c3a41..5cf72d3 100644 --- a/woocommerce-imobanco/woocommerce-imobanco.php +++ b/woocommerce-imobanco/woocommerce-imobanco.php @@ -2,7 +2,7 @@ /* Plugin Name: WooCommerce Imopay gateway Plugin URI: https://www.imobanco.com.br/ -Description: Plugin para utilizar o gateway de pagamento do Imopay +Description: Plugin para utilizar o gateway de pagamento do Imopay. V1.0 Version: 0.0.2 Author: Imobanco Author URI: https://www.imobanco.com.br/ @@ -11,21 +11,26 @@ namespace WoocommerceImobanco; +var_dump(getenv('WOO_IMOPAY_API_KEY')); +die; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } +if(!defined('WOO_IMOPAY_ENVIRONMENT')) { + define('WOO_IMOPAY_ENVIRONMENT', getenv('WOO_IMOPAY_ENVIRONMENT')); +} + if (!defined('WOO_IMOPAY_SELLER_ID')) { define('WOO_IMOPAY_SELLER_ID', getenv('WOO_IMOPAY_SELLER_ID')); -} +} if (!defined('WOO_IMOPAY_API_KEY')) { define('WOO_IMOPAY_API_KEY', getenv('WOO_IMOPAY_API_KEY')); - -} +} if (!defined('WOO_IMOPAY_API_URL')) { - define('WOO_IMOPAY_API_URL', 'production' == WOO_IMOPAY_ENVIRONMENT ? 'https://34.196.253.77/' : 'http://test.imopay.com.br'); + define('WOO_IMOPAY_API_URL', getenv('WOO_IMOPAY_API_URL') ? getenv('WOO_IMOPAY_API_URL') : ('production' == WOO_IMOPAY_ENVIRONMENT ? 'https://34.196.253.77/' : 'http://test.imopay.com.br') ); } define('WOO_IMOPAY_PLUGIN_DIR', plugin_dir_path(__FILE__)); @@ -33,19 +38,19 @@ define('WOO_IMOPAY_PLUGIN_URL', plugin_dir_url(__FILE__)); if (!defined('WOO_IMOPAY_CREDITCARD_ORDER_DESCRIPTION')) { - define('WOO_IMOPAY_CREDITCARD_ORDER_DESCRIPTION', get_bloginfo('name'). ' - Pedido no cartão de crédito'); + define('WOO_IMOPAY_CREDITCARD_ORDER_DESCRIPTION', getenv('WOO_IMOPAY_CREDITCARD_ORDER_DESCRIPTION') ? getenv('WOO_IMOPAY_CREDITCARD_ORDER_DESCRIPTION') : get_bloginfo('name'). ' - Pedido no cartão de crédito'); } if (!defined('WOO_IMOPAY_BILLET_ORDER_DESCRIPTION')) { - define('WOO_IMOPAY_BILLET_ORDER_DESCRIPTION', get_bloginfo('name'). ' - Pedido no boleto'); + define('WOO_IMOPAY_BILLET_ORDER_DESCRIPTION', getenv('WOO_IMOPAY_BILLET_ORDER_DESCRIPTION') ? getenv('WOO_IMOPAY_BILLET_ORDER_DESCRIPTION') : get_bloginfo('name'). ' - Pedido no boleto'); } if (!defined('WOO_IMOPAY_EXPIRATION_DATE_INCREMENT')) { - define('WOO_IMOPAY_EXPIRATION_DATE_INCREMENT', '+3 days'); + define('WOO_IMOPAY_EXPIRATION_DATE_INCREMENT', getenv('WOO_IMOPAY_EXPIRATION_DATE_INCREMENT') ? getenv('WOO_IMOPAY_EXPIRATION_DATE_INCREMENT') : '+3 days'); } if (!defined('WOO_IMOPAY_LIMIT_DATE_INCREMENT')) { - define('WOO_IMOPAY_LIMIT_DATE_INCREMENT', '+7 days'); + define('WOO_IMOPAY_LIMIT_DATE_INCREMENT', getenv('WOO_IMOPAY_LIMIT_DATE_INCREMENT') ? getenv('WOO_IMOPAY_LIMIT_DATE_INCREMENT') : '+7 days'); } define('WOO_IMOPAY_PLUGIN_SETTINGS', [ From 465bb9eaeaad529cbb8ac881b6c2cb93fbe90627 Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Sat, 8 Aug 2020 21:10:05 -0300 Subject: [PATCH 2/8] removendo die de debug --- woocommerce-imobanco/woocommerce-imobanco.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/woocommerce-imobanco/woocommerce-imobanco.php b/woocommerce-imobanco/woocommerce-imobanco.php index 5cf72d3..1cf86aa 100644 --- a/woocommerce-imobanco/woocommerce-imobanco.php +++ b/woocommerce-imobanco/woocommerce-imobanco.php @@ -11,8 +11,6 @@ namespace WoocommerceImobanco; -var_dump(getenv('WOO_IMOPAY_API_KEY')); -die; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } From 29b63c568382cf4d1e6b5889f91801d7cea2b385 Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Mon, 10 Aug 2020 23:22:10 -0300 Subject: [PATCH 3/8] Adicionada busca por CPF/CNPJ para atualizar caso exista. --- woocommerce-imobanco/includes/functions.php | 2 +- woocommerce-imobanco/includes/hooks.php | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/woocommerce-imobanco/includes/functions.php b/woocommerce-imobanco/includes/functions.php index cdadcca..849c6eb 100644 --- a/woocommerce-imobanco/includes/functions.php +++ b/woocommerce-imobanco/includes/functions.php @@ -87,7 +87,7 @@ function imopay_update_user($imopay_id, $data, $customer = null) return $response; } - //imopay_save_user_id($imopay_id, $customer); + imopay_save_user_id($imopay_id, $customer); return $response; } diff --git a/woocommerce-imobanco/includes/hooks.php b/woocommerce-imobanco/includes/hooks.php index 172e2cc..39ac332 100644 --- a/woocommerce-imobanco/includes/hooks.php +++ b/woocommerce-imobanco/includes/hooks.php @@ -27,9 +27,19 @@ function imopay_integration_customer_actions($id) { if (null == $imopay_id) { // usuário ainda não preencheu o endereço - try { - imopay_register_user($data, $customer); - } catch (\Exception $e) {} + + // busca por usuário + $request = new \WoocommerceImobanco\Request(); + $search = $request->post('buyers/search/', ['cpf_cnpj' => $data['cpf_cnpj']]); + + if (isset($search->id)) { + $imopay_id = $search->id; + imopay_update_user($imopay_id, $data, $customer); + } else { + try { + imopay_register_user($data, $customer); + } catch (\Exception $e) {} + } } else { try { imopay_update_user($imopay_id, $data, $customer); @@ -67,7 +77,9 @@ function imopay_neighborhood_required_rule( $fields ) { return $fields; } - +// add_action('init', function() { +// print_r(get_user_meta(59)); die; +// }); /** * On order created */ From 97e941eab5664493a696ab40914c8be0180e5acd Mon Sep 17 00:00:00 2001 From: Rodrigo Castro Date: Tue, 11 Aug 2020 10:37:01 -0300 Subject: [PATCH 4/8] Update woocommerce-imobanco/woocommerce-imobanco.php --- woocommerce-imobanco/woocommerce-imobanco.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce-imobanco/woocommerce-imobanco.php b/woocommerce-imobanco/woocommerce-imobanco.php index 1cf86aa..7080120 100644 --- a/woocommerce-imobanco/woocommerce-imobanco.php +++ b/woocommerce-imobanco/woocommerce-imobanco.php @@ -28,7 +28,7 @@ } if (!defined('WOO_IMOPAY_API_URL')) { - define('WOO_IMOPAY_API_URL', getenv('WOO_IMOPAY_API_URL') ? getenv('WOO_IMOPAY_API_URL') : ('production' == WOO_IMOPAY_ENVIRONMENT ? 'https://34.196.253.77/' : 'http://test.imopay.com.br') ); + define('WOO_IMOPAY_API_URL', getenv('WOO_IMOPAY_API_URL') ? getenv('WOO_IMOPAY_API_URL') : ('prod' == WOO_IMOPAY_ENVIRONMENT ? 'https://34.196.253.77/' : 'http://test.imopay.com.br') ); } define('WOO_IMOPAY_PLUGIN_DIR', plugin_dir_path(__FILE__)); From 23474b80e0382af07c1d3dbe23658d1a71d64c94 Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Tue, 11 Aug 2020 23:47:41 -0300 Subject: [PATCH 5/8] =?UTF-8?q?Corre=C3=A7ao=20resposta=20erro=20boleto,?= =?UTF-8?q?=20fluxo=20de=20notifica=C3=A7ao=20de=20status=20completo=20e?= =?UTF-8?q?=20integrado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- woocommerce-imobanco/includes/Request.php | 31 +++++++++++++----- woocommerce-imobanco/includes/api.php | 32 ++++++++++++++++--- woocommerce-imobanco/includes/billet.php | 7 ++++ woocommerce-imobanco/woocommerce-imobanco.php | 4 +-- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/woocommerce-imobanco/includes/Request.php b/woocommerce-imobanco/includes/Request.php index a906a69..b943f58 100644 --- a/woocommerce-imobanco/includes/Request.php +++ b/woocommerce-imobanco/includes/Request.php @@ -5,13 +5,25 @@ class Request { private function request($method, $path, $params = []) { $ch = curl_init(); - if ('test' == WOO_IMOPAY_ENVIRONMENT) { - curl_setopt($ch, CURLOPT_VERBOSE, true); - } - $url = WOO_IMOPAY_API_URL . '/' . $path; - if (substr($path, -1) != '/') { - $url .= '/'; + // if ('test' == WOO_IMOPAY_ENVIRONMENT) { + // curl_setopt($ch, CURLOPT_VERBOSE, true); + // } + + $url = $path; + $headers = []; + + if (strpos($path, 'http://') === false && strpos($path, 'https://') === false ) { + // testa se a URL absoluta foi enviada + $url = WOO_IMOPAY_API_URL . '/' . $path; + + if (substr($path, -1) != '/') { + $url .= '/'; + } + + $headers = ['Authorization: Api-Key '.WOO_IMOPAY_API_KEY, 'Accept:application/json', 'Content-Type: application/json']; + + //error_log(json_encode($headers)); } $method = strtolower($method); @@ -20,7 +32,7 @@ private function request($method, $path, $params = []) { if ('post' == $method) curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Length: '.strlen($postfields)]); + $headers[] = 'Content-Length: '.strlen($postfields); } else { if (strpos($url, '?') !== false) { $url .= '&'; @@ -30,7 +42,9 @@ private function request($method, $path, $params = []) { $url .= http_build_query($params); } - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Api-Key '.WOO_IMOPAY_API_KEY, 'Accept:application/json', 'Content-Type: application/json']); + if (!empty($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method)); @@ -40,6 +54,7 @@ private function request($method, $path, $params = []) { curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); + error_log('Request URL: '.$url. ' - Method: '.$method.' - Response: '. $response); curl_close($ch); diff --git a/woocommerce-imobanco/includes/api.php b/woocommerce-imobanco/includes/api.php index 4619238..73c5921 100644 --- a/woocommerce-imobanco/includes/api.php +++ b/woocommerce-imobanco/includes/api.php @@ -3,7 +3,7 @@ add_action( 'rest_api_init', function () { register_rest_route( 'imobanco/v1', '/order/update', array( - 'methods' => 'GET', + 'methods' => 'POST', 'callback' => 'woo_imobanco_update_order', )); @@ -11,8 +11,31 @@ function woo_imobanco_update_order($params) { - $id = $params->get_param('id'); - $status = $params->get_param('status'); + $request = new \WoocommerceImobanco\Request(); + error_log('NOTIFICATION INPUT: '. file_get_contents('php://input')); + + try { + $content = json_decode(file_get_contents('php://input')); + } catch (\Exception $e) { + + error_log($e->getMessage() . file_get_contents('php://input')); + return; + } + + // confirmação de notificação + if ($content->Type == 'SubscriptionConfirmation') { + // request de confimação no aws + error_log($request->get($content->SubscribeURL)); + return; + + } + + if ($content->Type == 'Notification') { + $id = json_decode($content->Message)->imopay_transaction_id; + error_log('Notification received '.$id); + } else { + return; + } $order = wc_get_orders([ 'post_type' => 'shop_order', @@ -36,9 +59,8 @@ function woo_imobanco_update_order($params) { 'charged_back' => 'wc-refundedd' ]; - if (isset($order[0]) && $id && $status) + if (isset($order[0]) && $id) { - $request = new \WoocommerceImobanco\Request(); $response = $request->get("transactions/{$id}"); if ($response) { diff --git a/woocommerce-imobanco/includes/billet.php b/woocommerce-imobanco/includes/billet.php index 1d29521..a021c91 100644 --- a/woocommerce-imobanco/includes/billet.php +++ b/woocommerce-imobanco/includes/billet.php @@ -206,6 +206,13 @@ public function process_payment( $order_id ) { // pagamento aprovado + error_log('BILLET RESPONSE '. json_encode($response)); + + if (!isset($response->id)) { + wc_add_notice('Ocorreu um erro ao tentar realizar o pagamento via boletos com o gateway. tente novamente', 'error'); + return false; + } + update_post_meta($order_id, '_imopay_order_id', $response->id ); update_post_meta($order_id, '_imopay_billet', json_encode($response->payment_method) ); diff --git a/woocommerce-imobanco/woocommerce-imobanco.php b/woocommerce-imobanco/woocommerce-imobanco.php index 1cf86aa..388b459 100644 --- a/woocommerce-imobanco/woocommerce-imobanco.php +++ b/woocommerce-imobanco/woocommerce-imobanco.php @@ -21,14 +21,14 @@ if (!defined('WOO_IMOPAY_SELLER_ID')) { define('WOO_IMOPAY_SELLER_ID', getenv('WOO_IMOPAY_SELLER_ID')); - } + if (!defined('WOO_IMOPAY_API_KEY')) { define('WOO_IMOPAY_API_KEY', getenv('WOO_IMOPAY_API_KEY')); } if (!defined('WOO_IMOPAY_API_URL')) { - define('WOO_IMOPAY_API_URL', getenv('WOO_IMOPAY_API_URL') ? getenv('WOO_IMOPAY_API_URL') : ('production' == WOO_IMOPAY_ENVIRONMENT ? 'https://34.196.253.77/' : 'http://test.imopay.com.br') ); + define('WOO_IMOPAY_API_URL', getenv('WOO_IMOPAY_API_URL') ? getenv('WOO_IMOPAY_API_URL') : ('prod' == WOO_IMOPAY_ENVIRONMENT ? 'https://34.196.253.77/' : 'http://test.imopay.com.br') ); } define('WOO_IMOPAY_PLUGIN_DIR', plugin_dir_path(__FILE__)); From 3771121c67f4baaa9b17385d8dda200501f44235 Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Tue, 18 Aug 2020 22:07:58 -0300 Subject: [PATCH 6/8] =?UTF-8?q?Enviando=20metadata=20e=20reference=5Fid=20?= =?UTF-8?q?na=20requisi=C3=A7ao=20de=20transa=C3=A7ao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- woocommerce-imobanco/includes/billet.php | 14 +++++++++++++- woocommerce-imobanco/includes/creditcard.php | 12 ++++++++++++ woocommerce-imobanco/woocommerce-imobanco.php | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/woocommerce-imobanco/includes/billet.php b/woocommerce-imobanco/includes/billet.php index a021c91..e476e5e 100644 --- a/woocommerce-imobanco/includes/billet.php +++ b/woocommerce-imobanco/includes/billet.php @@ -176,7 +176,19 @@ public function process_payment( $order_id ) { 'payment_method' => [ 'expiration_date' => date('Y-m-d', strtotime(WOO_IMOPAY_EXPIRATION_DATE_INCREMENT)), 'limit_date' => date('Y-m-d', strtotime(WOO_IMOPAY_LIMIT_DATE_INCREMENT)), - ] + ], + 'reference_id' => $order_id, + 'metadata' => [ + 'woocommerce' => json_encode([ + 'order' => [ + 'customer_id' => $customer, + 'order_key' => $order->get_data() ['order_key'], + 'customer_user_agent' => $order->get_data() ['customer_user_agent'], + 'cart_hash' => $order->get_data() ['cart_hash'] + ], + 'blogname' => get_bloginfo('name') + ]) + ] ]; // request API imopay diff --git a/woocommerce-imobanco/includes/creditcard.php b/woocommerce-imobanco/includes/creditcard.php index dde4aa6..059652a 100644 --- a/woocommerce-imobanco/includes/creditcard.php +++ b/woocommerce-imobanco/includes/creditcard.php @@ -179,6 +179,18 @@ public function process_payment( $order_id ) { 'expiration_month' => $_POST['expiration_month'], 'expiration_year' => $_POST['expiration_year'], 'security_code' => $_POST['security_code'] + ], + 'reference_id' => $order_id, + 'metadata' => [ + 'woocommerce' => json_encode([ + 'order' => [ + 'customer_id' => $customer, + 'order_key' => $order->get_data() ['order_key'], + 'customer_user_agent' => $order->get_data() ['customer_user_agent'], + 'cart_hash' => $order->get_data() ['cart_hash'] + ], + 'blogname' => get_bloginfo('name') + ]) ] ]; diff --git a/woocommerce-imobanco/woocommerce-imobanco.php b/woocommerce-imobanco/woocommerce-imobanco.php index 388b459..8678b76 100644 --- a/woocommerce-imobanco/woocommerce-imobanco.php +++ b/woocommerce-imobanco/woocommerce-imobanco.php @@ -73,6 +73,12 @@ ] ]); +// // somente para testes, remove os dados do imopay do banco do woocommerce +// add_action('init' , function() { +// delete_user_meta(60, '_imopay_user_id' ); +// delete_user_meta(60, '_imopay_address_id' ); +// }); + require WOO_IMOPAY_PLUGIN_DIR . 'includes/functions.php'; require WOO_IMOPAY_PLUGIN_DIR . 'includes/Request.php'; require WOO_IMOPAY_PLUGIN_DIR . 'includes/hooks.php'; From 44424c686845f3720b4fc1fb794e182110447c9e Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Sat, 22 Aug 2020 17:37:26 -0300 Subject: [PATCH 7/8] =?UTF-8?q?Removendo=20json=5Fencode=20do=20metadata?= =?UTF-8?q?=20da=20transa=C3=A7ao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- woocommerce-imobanco/includes/billet.php | 4 ++-- woocommerce-imobanco/includes/creditcard.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/woocommerce-imobanco/includes/billet.php b/woocommerce-imobanco/includes/billet.php index e476e5e..324420e 100644 --- a/woocommerce-imobanco/includes/billet.php +++ b/woocommerce-imobanco/includes/billet.php @@ -179,7 +179,7 @@ public function process_payment( $order_id ) { ], 'reference_id' => $order_id, 'metadata' => [ - 'woocommerce' => json_encode([ + 'woocommerce' => [ 'order' => [ 'customer_id' => $customer, 'order_key' => $order->get_data() ['order_key'], @@ -187,7 +187,7 @@ public function process_payment( $order_id ) { 'cart_hash' => $order->get_data() ['cart_hash'] ], 'blogname' => get_bloginfo('name') - ]) + ] ] ]; diff --git a/woocommerce-imobanco/includes/creditcard.php b/woocommerce-imobanco/includes/creditcard.php index 059652a..9396162 100644 --- a/woocommerce-imobanco/includes/creditcard.php +++ b/woocommerce-imobanco/includes/creditcard.php @@ -182,7 +182,7 @@ public function process_payment( $order_id ) { ], 'reference_id' => $order_id, 'metadata' => [ - 'woocommerce' => json_encode([ + 'woocommerce' => [ 'order' => [ 'customer_id' => $customer, 'order_key' => $order->get_data() ['order_key'], @@ -190,7 +190,7 @@ public function process_payment( $order_id ) { 'cart_hash' => $order->get_data() ['cart_hash'] ], 'blogname' => get_bloginfo('name') - ]) + ] ] ]; From e48d4192e919a9a40513bb79f5eee1060e59c28a Mon Sep 17 00:00:00 2001 From: ibrunodev Date: Tue, 22 Sep 2020 00:13:58 -0300 Subject: [PATCH 8/8] =?UTF-8?q?Corre=C3=A7oes=20das=20tarefas=20pendentes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- woocommerce-imobanco/includes/api.php | 2 +- woocommerce-imobanco/includes/creditcard.php | 27 ++++++++++++++++++- .../includes/forms/creditcard_form.php | 22 +++++++++++++++ woocommerce-imobanco/includes/functions.php | 17 +++++++++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/woocommerce-imobanco/includes/api.php b/woocommerce-imobanco/includes/api.php index 73c5921..6df4035 100644 --- a/woocommerce-imobanco/includes/api.php +++ b/woocommerce-imobanco/includes/api.php @@ -31,7 +31,7 @@ function woo_imobanco_update_order($params) { } if ($content->Type == 'Notification') { - $id = json_decode($content->Message)->imopay_transaction_id; + $id = json_decode($content->Message)->imopay_id; error_log('Notification received '.$id); } else { return; diff --git a/woocommerce-imobanco/includes/creditcard.php b/woocommerce-imobanco/includes/creditcard.php index 9396162..494f2f4 100644 --- a/woocommerce-imobanco/includes/creditcard.php +++ b/woocommerce-imobanco/includes/creditcard.php @@ -116,6 +116,27 @@ public function payment_fields(){ echo wpautop( wptexturize( $description ) ); } + $total = WC()->cart->cart_contents_total + WC()->cart->tax_total; + $min_installment_value = 0; // preencher com 0 se não quiser limitar + // todo: preencher no painel + + // taxas de parcelamento por parcela em % (sem o caractere %) + $installments = [ + 0, // 1x, ex: 0 + 0, // 2x, ex: 3 + 0, // 3x, ex: 5 + 0, // ... + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, // 12x + // todo: preencher via painel + ]; + require WOO_IMOPAY_PLUGIN_DIR . 'includes/forms/creditcard_form.php'; } @@ -178,7 +199,11 @@ public function process_payment( $order_id ) { 'card_number' => $_POST['card_number'], 'expiration_month' => $_POST['expiration_month'], 'expiration_year' => $_POST['expiration_year'], - 'security_code' => $_POST['security_code'] + 'security_code' => $_POST['security_code'], + 'installment_plan' => [ + 'number_installments' => $_POST['installment'], + 'mode' => 'interest_free' + ] ], 'reference_id' => $order_id, 'metadata' => [ diff --git a/woocommerce-imobanco/includes/forms/creditcard_form.php b/woocommerce-imobanco/includes/forms/creditcard_form.php index 53f4d44..2c1a012 100644 --- a/woocommerce-imobanco/includes/forms/creditcard_form.php +++ b/woocommerce-imobanco/includes/forms/creditcard_form.php @@ -20,5 +20,27 @@ +
+ + + +
+
\ No newline at end of file diff --git a/woocommerce-imobanco/includes/functions.php b/woocommerce-imobanco/includes/functions.php index 849c6eb..69dbf8f 100644 --- a/woocommerce-imobanco/includes/functions.php +++ b/woocommerce-imobanco/includes/functions.php @@ -99,6 +99,17 @@ function imopay_register_address($imopay_id, $data, $customer = null) } $request = new Request(); + + $meta = get_user_meta($customer); + $response = $request->post('addresses/get_by_document/', [ + 'cpf_cnpj' => $meta['billing_cpf'] ?? $meta['billing_cnpj'] + ]); + + if (isset($response->id)) { + imopay_save_address_id($response->id, $customer); + return $response; + } + $data['owner'] = $imopay_id; $response = $request->post('addresses/create_by_name_and_uf', $data); @@ -133,14 +144,18 @@ function imopay_get_address_from_formdata($imopay_id) return []; } - return [ + $data = [ 'owner' => $imopay_id, 'uf' => $_POST['billing_state'], 'city' => ucwords(strtolower($_POST['billing_city'])), 'neighborhood' => $_POST['billing_neighborhood'], 'street' => $_POST['billing_address_1'], 'zip_code' => str_replace('-', '', trim($_POST['billing_postcode'])), + 'number' => $_POST['billing_number'], + 'complement' => $_POST['billing_address_2'] ?? '' ]; + + return $data; } function imopay_save_user_id($id, $customer = null)