gateway.'_toggle' => array(
'type' => 'checkbox',
'label' => __('Activate Cash On Delivery', 'formipay'),
'submenu' => __( 'Cash On Delivery', 'formipay' )
),
$this->gateway.'_settings_group' => array(
'type' => 'group_title',
'label' => __( 'General', 'formipay' ),
'description' => __( 'Set the rule of Cash On Delivery', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
'group' => 'started'
),
$this->gateway.'_label' => array(
'type' => 'text',
'label' => __('Label', 'formipay'),
'value' => __( 'COD', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_item_name' => array(
'type' => 'text',
'label' => __('Item Name', 'formipay'),
'value' => __( 'COD Fee', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_icon' => array(
'type' => 'image',
'label' => __('Icon', 'formipay'),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_fee_amount' => array(
'type' => 'number',
'label' => __('Fee Amount', 'formipay'),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_fee_type' => array(
'type' => 'select',
'label' => __('Fee Type', 'formipay'),
'options' => array(
'fixed' => __( 'Fixed Amount', 'formipay' ),
'percentage' => __( 'Percentage', 'formipay' )
),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
'group' => 'ended'
),
$this->gateway.'_details_group' => array(
'type' => 'group_title',
'label' => __( 'Instruction', 'formipay' ),
'description' => __( 'Set instruction to buyer how to pay with COD method.', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
'group' => 'started'
),
$this->gateway.'_instruction_thankyou' => array(
'type' => 'tinymce',
'label' => __( 'Thankyou Screen', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'hints' => array(
'product_name' => __( 'Product Name', 'formipay' ),
'order_id' => __( 'Order ID', 'formipay' ),
'grand_total' => __( 'Order Total', 'formipay' ),
'confirmation_page_link' => __( 'Confirmation Page Link', 'formipay' )
),
'value' => '
Please prepare your cash of {{grand_total}} and pay it to the courier who delivers your {{product_name}}.
',
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
),
$this->gateway.'_instruction_whatsapp' => array(
'type' => 'hint_textarea',
'label' => __( 'WhatsApp Message', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'hints' => array(
'product_name' => __( 'Product Name', 'formipay' ),
'order_id' => __( 'Order ID', 'formipay' ),
'grand_total' => __( 'Order Total', 'formipay' ),
'confirmation_page_link' => __( 'Confirmation Page Link', 'formipay' )
),
'value' => 'Please prepare your cash of {{grand_total}} and pay it to the courier who delivers your {{product_name}}.',
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
'group' => 'ended'
),
$this->gateway.'_confirmation_page_group' => array(
'type' => 'group_title',
'label' => __( 'Confirmation Page', 'formipay' ),
'description' => sprintf(
// translators: %s is the site URL.
__(
'Set confirmation page for buyer to confirm that they have receive the package and pay the order to courier.
Confirmation magic URL: %s/payment-confirm/cod/{{autogenerated_token}}
'
, 'formipay' ), site_url()),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
'group' => 'started'
),
$this->gateway.'_confirmation_page_content' => array(
'type' => 'tinymce',
'label' => __( 'Page Content', 'formipay' ),
'hints' => array(
'order_details' => __( 'Order Details', 'formipay' ),
'confirmation_form' => __( 'Confirmation Form', 'formipay' ),
),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_confirmation_page_width' => array(
'type' => 'number',
'label' => __( 'Page Width', 'formipay' ),
'value' => '600',
'description' => __( 'in pixel (px)', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_confirmation_table_alignment' => array(
'type' => 'radio',
'label' => __('Table Content Alignment', 'formipay'),
'value' => 'center',
'options' => array(
'left' => ' Left',
'center' => ' Center',
'right' => ' Right',
),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_confirmation_form_agreement' => array(
'type' => 'text',
'label' => __( 'Agreement', 'formipay' ),
'value' => __( 'I have receipt the package and pay as billed to the courier.', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
)
),
$this->gateway.'_confirmation_form_button' => array(
'type' => 'text',
'label' => __( 'Button Text', 'formipay' ),
'value' => __( 'Confirm', 'formipay' ),
'submenu' => __( 'Cash On Delivery', 'formipay' ),
'dependency' => array(
'key' => $this->gateway.'_toggle',
'value' => 'not_empty'
),
'group' => 'ended',
)
);
foreach($cod as $key => $value){
$settings[$key] = $value;
}
return $settings;
}
public function add_cod_setings($fields) {
$cod_settings = array(
$this->gateway.'_confirmation_notice_message_group' => array(
'type' => 'group_title',
'label' => __( 'Confirmation Notice Messages', 'formipay' ),
'description' => __( 'Set notice message on every condition about attempting to confirm the payment', 'formipay' ),
'submenu' => __( 'COD', 'formipay' ),
'group' => 'started'
),
$this->gateway.'_confirmation_update_to_status' => array(
'type' => 'select',
'label' => __( 'Change status order to', 'formipay' ),
'options' => formipay_order_status_list(),
'value' => 'payment-confirm',
'submenu' => __( 'COD', 'formipay' ),
),
$this->gateway.'_confirmation_message_success' => array(
'type' => 'hint_textarea',
'label' => __( 'Successfully Confirmed Message', 'formipay' ),
'hints' => array(
'order_id' => __('Order ID', 'formipay')
),
'value' => __('Successfully confirmed COD #{{order_id}}', 'formipay'),
'description' => __('When successfully change the order status to the preferred one', 'formipay'),
'submenu' => __( 'COD', 'formipay' ),
),
$this->gateway.'_confirmation_message_already_confirmed' => array(
'type' => 'hint_textarea',
'label' => __( 'Has Been Confirmed Message', 'formipay' ),
'hints' => array(
'order_id' => __('Order ID', 'formipay')
),
'value' => __('#{{order_id}} has been confirmed', 'formipay'),
'description' => __('When the order status has been the preferred one', 'formipay'),
'submenu' => __( 'COD', 'formipay' ),
),
$this->gateway.'_confirmation_message_error' => array(
'type' => 'hint_textarea',
'label' => __( 'Failed to Confirm Message', 'formipay' ),
'hints' => array(
'order_id' => __('Order ID', 'formipay'),
'system_error_message' => __('System Error Message', 'formipay')
),
'value' => __('Failed to proceed. Error: {{system_error_message}}', 'formipay'),
'description' => __('When error to change the order status to the preferred one', 'formipay'),
'submenu' => __( 'COD', 'formipay' ),
'group' => 'ended'
)
);
foreach($cod_settings as $key => $value){
$fields[$key] = $value;
}
return $fields;
}
public function add_gateway($gateways) {
$formipay_settings = get_option('formipay_settings');
if(isset($formipay_settings['cod_toggle']) && false !== $formipay_settings['cod_toggle']){
// $gateways['cod'] = __('Cash On Delivery', 'formipay');
$gateways[] = [
'id' => $this->gateway,
'gateway' => __( 'COD', 'formipay' ),
];
}
return $gateways;
}
public function set_frontend_logo($logo){
if($logo == false){
$logo = FORMIPAY_URL . 'public/assets/img/cod_default_icon.png';
}
return $logo;
}
public function add_fee($details, $form_id, $order_data){
if($order_data['payment_gateway'] == 'cod'){
$formipay_settings = get_option('formipay_settings');
$fee_amount = $formipay_settings['cod_fee_amount'];
$fee_type = $formipay_settings['cod_fee_type'];
if($fee_type == 'percentage'){
$grand_total = 0;
if(!empty($details)){
foreach($details as $detail){
$grand_total += $detail['subtotal'];
}
}
$fee_amount = $grand_total * floatval($fee_amount) / 100;
}
$details[] = [
'item' => $formipay_settings['cod_item_name'],
'amount' => $fee_amount,
'subtotal' => $fee_amount
];
}
return $details;
}
public function render_payment_details($render, $form_id, $order_data, $submit_action_type) {
if($order_data['payment_gateway'] == 'cod'){
$render = '';
$formipay_settings = get_option('formipay_settings');
$render .= ($submit_action_type == 'thankyou') ? '' : '';
$replacements = [
'{{product_name}}' => get_the_title($form_id),
'{{order_id}}' => $order_data['id'],
'{{grand_total}}' => formipay_price_format($order_data['total'], $form_id),
'{{confirmation_page_link}}' => site_url('/payment-confirm/'.$this->gateway.'/'.base64_encode($form_id.':::'.$order_data['id']))
];
$render .= strtr( $formipay_settings['cod_instruction_'.$submit_action_type], $replacements );
$render .= ($submit_action_type == 'thankyou') ? '
' : '';
}
return $render;
}
public function check_parse_query() {
global $wp_query;
$formipay_settings = get_option('formipay_settings');
if(is_admin()) :
return;
endif;
if(
!is_admin() &&
is_array($wp_query->query) &&
array_key_exists('formipay-payment-confirm', $wp_query->query) &&
true === boolval($wp_query->query['formipay-payment-confirm']) &&
array_key_exists('gateway', $wp_query->query) &&
'cod' === $wp_query->query['gateway']
) :
$token = explode(':::', base64_decode($wp_query->query['formipay-token']));
$form_id = $token[0];
$order_id = $token[1];
$thankyou_slug = 'thankyou';
if(!empty($formipay_settings['thankyou_link'])){
$thankyou_slug = $formipay_settings['thankyou_link'];
}
$order = formipay_get_order($order_id);
if($order['payment_gateway'] !== 'cod'){
wp_safe_redirect( site_url('/'.$thankyou_slug.'/'.$wp_query->query['formipay-token']) );
}
$button_background_color = json_decode(formipay_get_post_meta($form_id, 'button_bg_color'), true );
$button_text_color = json_decode(formipay_get_post_meta($form_id, 'button_text_color'), true );
$button_border_color = json_decode( formipay_get_post_meta($form_id, 'button_border_color'), true );
get_header();
?>
$form_id,
'order_id' => $order_id,
'status' => 'payment-confirm',
'payment_gateway' => 'cod'
]);
wp_send_json( [
'success' => boolval($update['valid']),
'data' => [
'message' => $update['message'],
'icon' => (boolval($update['valid']) == true) ? 'success' : 'info'
]
] );
}
// Nonce is invalid, handle the error
wp_send_json_error([
'message' => 'Security check failed. Please try again.',
'icon' => 'error'
]);
}
public function add_order_shortcodes($shortcodes, $form_id, $order_data, $submit_action_type) {
if($order_data['payment_gateway'] == $this->gateway){
$confirmation_page_link = site_url('/payment-confirm/'.$this->gateway.'/'.base64_encode($form_id.':::'.$order_data['id']));
$shortcodes['payment_confirmation_form'] = 'C.O.D Confirmation';
}
return $shortcodes;
}
public function process_payment($order_data) {
return $order_data;
}
}