Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.
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
30 changes: 25 additions & 5 deletions includes/class-wc-pagarme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ public function generate_transaction_data( $order, $posted ) {
if ( class_exists( 'Extra_Checkout_Fields_For_Brazil' ) ) {
$wcbcf_settings = get_option( 'wcbcf_settings' );
if ( '0' !== $wcbcf_settings['person_type'] ) {
if ( ( '1' === $wcbcf_settings['person_type'] && '1' === $order->billing_persontype ) || '2' === $wcbcf_settings['person_type'] ) {
if ( ( '1' == $wcbcf_settings['person_type'] && '1' == $order->billing_persontype ) || '2' === $wcbcf_settings['person_type'] ) {
PC::debug( '1' == $wcbcf_settings['person_type'] && '1' == $order->billing_persontype );
$data['customer']['document_number'] = $this->only_numbers( $order->billing_cpf );
}

Expand Down Expand Up @@ -339,8 +340,13 @@ public function generate_transaction_data( $order, $posted ) {
}
}
} elseif ( 'pagarme-banking-ticket' === $this->gateway->id ) {
$data['payment_method'] = 'boleto';
$data['async'] = 'yes' === $this->gateway->async;
// Set expiration date
$num_days = (int)$this->gateway->boleto_expiration_date;
$expiration_date = $this->set_expiration_date($num_days);

$data['payment_method'] = 'boleto';
$data['async'] = 'yes' === $this->gateway->async;
$data['boleto_expiration_date'] = $expiration_date;
}

// Add filter for Third Party plugins.
Expand Down Expand Up @@ -610,7 +616,6 @@ protected function get_card_brand_name( $brand ) {
* @param array $data Order data.
*/
protected function save_order_meta_fields( $id, $data ) {

// Save transaction data.
$payment_data = array_map(
'sanitize_text_field',
Expand Down Expand Up @@ -864,4 +869,19 @@ public function process_order_status( $order, $status ) {
break;
}
}
}

/**
* Set expiration date based on current date + number of days set
* at the banking ticket settings page
*
* @param int $num_days number of days set at settings page
*/
public function set_expiration_date($num_days) {
$today = new DateTime('NOW');
$interval = new DateInterval('P' . $num_days . 'D');

$expiration_date = $today->add($interval);

return $expiration_date->format(DateTime::ISO8601);
}
}
41 changes: 35 additions & 6 deletions includes/class-wc-pagarme-banking-ticket-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public function __construct() {
$this->init_settings();

// Define user set variables.
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->api_key = $this->get_option( 'api_key' );
$this->encryption_key = $this->get_option( 'encryption_key' );
$this->debug = $this->get_option( 'debug' );
$this->async = $this->get_option( 'async' );
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->api_key = $this->get_option( 'api_key' );
$this->encryption_key = $this->get_option( 'encryption_key' );
$this->debug = $this->get_option( 'debug' );
$this->async = $this->get_option( 'async' );
$this->boleto_expiration_date = $this->get_option( 'boleto_expiration_date' );
$this->cancel_order = $this->get_option( 'enable_cancel_order' );

// Active logs.
if ( 'yes' === $this->debug ) {
Expand Down Expand Up @@ -126,6 +128,33 @@ public function init_form_fields() {
'description' => sprintf( __( 'If enabled the banking ticket url will appear in the order page, if disabled it will appear after the checkout process.', 'woocommerce-pagarme' ) ),
'default' => 'no',
),
'ticket_configs' => array(
'title' => __( 'Configurações do Boleto', 'woocommerce-pagarme' ),
'type' => 'title',
'description' => '',
),
'boleto_expiration_date' => array(
'title' => __( 'Definir a data de expiração do boleto', 'woocommerce-pagarme' ),
'type' => 'text',
'description' => sprintf( __( 'O número colocado neste campo será somado a data atual, assim seu boleto terá a data de expiração mudada para essa soma', 'woocommerce-pagarme' ) . '</a>' ),
'default' => '7',
'custom_attributes' => array(
'required' => 'required',
),
),
'enable_cancel_order' => array(
'title' => __( 'Habilitar cancelamento de pedido', 'woocommerce-pagarme' ),
'type' => 'checkbox',
'label' => __( 'Habilitar cancelamento', 'woocommerce-pagarme' ),
'default' => 'no',
'description' => sprintf( __( 'Habilitar cancelamento de pedido com número de dias definido em caso de não pagamento do boleto' , 'woocommerce-pagarme' ) ),
),
'cancel_order' => array(
'title' => __( 'Definir o número de dias para o cancelamento do pedido', 'woocommerce-pagarme' ),
'type' => 'text',
'description' => sprintf( __( 'Definir o número de dias para o cancelamento do pedido em caso de não pagamento do boleto', 'woocommerce-pagarme' ) ),
'default' => '',
),
'testing' => array(
'title' => __( 'Gateway Testing', 'woocommerce-pagarme' ),
'type' => 'title',
Expand Down