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

WIP: Atualização de endereço #31

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions woocommerce-imobanco/includes/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public function put( $path, $params )
{
return $this->request('PUT', $path, $params);
}

public function patch( $path, $params )
{
return $this->request('PATCH', $path, $params);
}
}
38 changes: 38 additions & 0 deletions woocommerce-imobanco/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,44 @@ function imopay_register_address($imopay_id, $data, $customer = null)
return $response;
}


function imopay_update_address($imopay_id, $data, $customer = null)
{
if (null == $customer) {
$customer = WC()->session->get('customer');
}

$request = new Request();
$response = $request->patch('addresses/'.$imopay_id.'/update_by_name_and_uf/', $data);

if (null == $response) {
throw new \Exception('O gateway de pagamentos não pôde ser acessado');
return;
}

if (isset($response->status_code)) {
if (isset($response->non_field_errors)) {
throw new \Exception($response->non_field_errors);
}

if (isset($response->payer[0])) {
throw new \Exception(str_replace('Este campo', 'O '.WOO_IMOPAY_PLUGIN_SETTINGS['field_labels']['payer'], $response->payer[0]));
}

if (isset($response->payment_method)) {
foreach($response->payment_method as $key => $item) {
throw new \Exception(str_replace('Este campo', 'O '.WOO_IMOPAY_PLUGIN_SETTINGS['field_labels'][$key], $item[0]));
}
}

return $response;
}

// imopay_save_address_id($imopay_id, $customer);

return $response;
}

function imopay_get_user_from_formdata()
{
if (empty($_POST)) {
Expand Down
21 changes: 14 additions & 7 deletions woocommerce-imobanco/includes/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ function imopay_integration_customer_actions($id) {
try {
imopay_update_user($payer_id, $data, $customer);
} catch (\Exception $e) {}
}
}

if (null == $address_id && null != $payer_id) {
if (isset($meta['billing_address_1'][0]) && !empty($meta['billing_address_1'][0])) {
try {
imopay_register_address($payer_id, imopay_get_address_from_formdata($payer_id), $customer);
} catch (\Exception $e) {}
if (null == $address_id) {
if (isset($meta['billing_address_1'][0]) && !empty($meta['billing_address_1'][0])) {
try {
imopay_register_address($payer_id, imopay_get_address_from_formdata($payer_id), $customer);
} catch (\Exception $e) {}
}
}
else{
try {
imopay_update_address($address_id, imopay_get_address_from_formdata($payer_id), $customer);
} catch (\Exception $e) {}
}
}
}


}
add_action('woocommerce_created_customer', 'imopay_integration_customer_actions');
add_action('woocommerce_update_customer', 'imopay_integration_customer_actions');
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-imobanco/woocommerce-imobanco.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: WooCommerce Imopay gateway
Plugin URI: https://www.imobanco.com.br/
Description: Plugin para utilizar o gateway de pagamento do Imopay
Version: 0.0.5a2
Version: 0.0.6a4
Author: Imobanco
Author URI: https://www.imobanco.com.br/
License: GPLv2 or later
Expand Down