Skip to content

Commit

Permalink
Version 5.7.4 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiz authored Oct 4, 2022
2 parents f56505f + 510cf29 commit bb47e6d
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 114 deletions.
21 changes: 21 additions & 0 deletions assets/js/paystack-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ jQuery( function( $ ) {
templateSelection: formatPaystackPaymentIconDisplay
} );

$( '#woocommerce_paystack_test_secret_key, #woocommerce_paystack_live_secret_key' ).after(
'<button class="wc-paystack-toggle-secret" style="height: 30px; margin-left: 2px; cursor: pointer"><span class="dashicons dashicons-visibility"></span></button>'
);

$( '.wc-paystack-toggle-secret' ).on( 'click', function( event ) {
event.preventDefault();

let $dashicon = $( this ).closest( 'button' ).find( '.dashicons' );
let $input = $( this ).closest( 'tr' ).find( '.input-text' );
let inputType = $input.attr( 'type' );

if ( 'text' == inputType ) {
$input.attr( 'type', 'password' );
$dashicon.removeClass( 'dashicons-hidden' );
$dashicon.addClass( 'dashicons-visibility' );
} else {
$input.attr( 'type', 'text' );
$dashicon.removeClass( 'dashicons-visibility' );
$dashicon.addClass( 'dashicons-hidden' );
}
} );
}
};

Expand Down
2 changes: 1 addition & 1 deletion assets/js/paystack-admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions includes/class-wc-gateway-custom-paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function get_icon() {
*/
public function payment_scripts() {

if ( ! is_checkout_pay_page() ) {
if ( isset( $_GET['pay_for_order'] ) || ! is_checkout_pay_page() ) {
return;
}

Expand All @@ -437,9 +437,7 @@ public function payment_scripts() {

$order = wc_get_order( $order_id );

$payment_method = method_exists( $order, 'get_payment_method' ) ? $order->get_payment_method() : $order->payment_method;

if ( $this->id !== $payment_method ) {
if ( $this->id !== $order->get_payment_method() ) {
return;
}

Expand All @@ -457,15 +455,15 @@ public function payment_scripts() {

if ( is_checkout_pay_page() && get_query_var( 'order-pay' ) ) {

$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
$email = $order->get_billing_email();

$amount = $order->get_total() * 100;

$txnref = $order_id . '_' . time();

$the_order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$the_order_key = method_exists( $order, 'get_order_key' ) ? $order->get_order_key() : $order->order_key;
$currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->order_currency;
$the_order_id = $order->get_id();
$the_order_key = $order->get_order_key();
$currency = $order->get_currency();

if ( $the_order_id == $order_id && $the_order_key == $order_key ) {

Expand Down Expand Up @@ -526,10 +524,7 @@ public function payment_scripts() {

if ( $this->meta_name ) {

$first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
$last_name = method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name;

$paystack_params['meta_name'] = $first_name . ' ' . $last_name;
$paystack_params['meta_name'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();

}

Expand All @@ -541,9 +536,7 @@ public function payment_scripts() {

if ( $this->meta_phone ) {

$billing_phone = method_exists( $order, 'get_billing_phone' ) ? $order->get_billing_phone() : $order->billing_phone;

$paystack_params['meta_phone'] = $billing_phone;
$paystack_params['meta_phone'] = $order->get_billing_phone();

}

Expand Down Expand Up @@ -603,7 +596,7 @@ public function payment_scripts() {
}

/**
* Add Gateway to checkout page.
* Add custom gateways to the checkout page.
*
* @param $available_gateways
*
Expand Down
6 changes: 2 additions & 4 deletions includes/class-wc-gateway-paystack-subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ public function scheduled_subscription_payment( $amount_to_charge, $renewal_orde
*/
public function process_subscription_payment( $order, $amount ) {

$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$order_id = $order->get_id();

$auth_code = get_post_meta( $order_id, '_paystack_token', true );

if ( $auth_code ) {

$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;

$order_amount = $amount * 100;

$paystack_url = 'https://api.paystack.co/transaction/charge_authorization';
Expand All @@ -115,7 +113,7 @@ public function process_subscription_payment( $order, $amount ) {
$metadata['custom_fields'] = $this->get_custom_fields( $order_id );

$body = array(
'email' => $email,
'email' => $order->get_billing_email(),
'amount' => $order_amount,
'metadata' => $metadata,
'authorization_code' => $auth_code,
Expand Down
62 changes: 22 additions & 40 deletions includes/class-wc-gateway-paystack.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ public function __construct() {
*/
public function is_valid_for_use() {

if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paystack_supported_currencies', array( 'NGN', 'USD', 'ZAR', 'GHS', 'KES' ) ) ) ) {
if ( ! in_array( get_woocommerce_currency(), apply_filters( 'woocommerce_paystack_supported_currencies', array( 'NGN', 'USD', 'ZAR', 'GHS', 'KES', 'XOF' ) ) ) ) {

$this->msg = sprintf( __( 'Paystack does not support your store currency. Kindly set it to either NGN (&#8358), GHS (&#x20b5;), USD (&#36;), KES (KSh) or ZAR (R) <a href="%s">here</a>', 'woo-paystack' ), admin_url( 'admin.php?page=wc-settings&tab=general' ) );
$this->msg = sprintf( __( 'Paystack does not support your store currency. Kindly set it to either NGN (&#8358), GHS (&#x20b5;), USD (&#36;), KES (KSh), ZAR (R), or XOF (CFA) <a href="%s">here</a>', 'woo-paystack' ), admin_url( 'admin.php?page=wc-settings&tab=general' ) );

return false;

Expand Down Expand Up @@ -433,7 +433,7 @@ public function init_form_fields() {
),
'test_secret_key' => array(
'title' => __( 'Test Secret Key', 'woo-paystack' ),
'type' => 'text',
'type' => 'password',
'description' => __( 'Enter your Test Secret Key here', 'woo-paystack' ),
'default' => '',
),
Expand All @@ -445,7 +445,7 @@ public function init_form_fields() {
),
'live_secret_key' => array(
'title' => __( 'Live Secret Key', 'woo-paystack' ),
'type' => 'text',
'type' => 'password',
'description' => __( 'Enter your Live Secret Key here.', 'woo-paystack' ),
'default' => '',
),
Expand Down Expand Up @@ -643,7 +643,7 @@ public function payment_fields() {
*/
public function payment_scripts() {

if ( ! is_checkout_pay_page() ) {
if ( isset( $_GET['pay_for_order'] ) || ! is_checkout_pay_page() ) {
return;
}

Expand All @@ -656,9 +656,7 @@ public function payment_scripts() {

$order = wc_get_order( $order_id );

$payment_method = method_exists( $order, 'get_payment_method' ) ? $order->get_payment_method() : $order->payment_method;

if ( $this->id !== $payment_method ) {
if ( $this->id !== $order->get_payment_method() ) {
return;
}

Expand All @@ -676,12 +674,12 @@ public function payment_scripts() {

if ( is_checkout_pay_page() && get_query_var( 'order-pay' ) ) {

$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
$email = $order->get_billing_email();
$amount = $order->get_total() * 100;
$txnref = $order_id . '_' . time();
$the_order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$the_order_key = method_exists( $order, 'get_order_key' ) ? $order->get_order_key() : $order->order_key;
$currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->order_currency;
$the_order_id = $order->get_id();
$the_order_key = $order->get_order_key();
$currency = $order->get_currency();

if ( $the_order_id == $order_id && $the_order_key == $order_key ) {

Expand Down Expand Up @@ -714,10 +712,7 @@ public function payment_scripts() {

if ( $this->meta_name ) {

$first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
$last_name = method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name;

$paystack_params['meta_name'] = $first_name . ' ' . $last_name;
$paystack_params['meta_name'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();

}

Expand All @@ -729,9 +724,7 @@ public function payment_scripts() {

if ( $this->meta_phone ) {

$billing_phone = method_exists( $order, 'get_billing_phone' ) ? $order->get_billing_phone() : $order->billing_phone;

$paystack_params['meta_phone'] = $billing_phone;
$paystack_params['meta_phone'] = $order->get_billing_phone();

}

Expand Down Expand Up @@ -879,18 +872,16 @@ public function process_payment( $order_id ) {
public function process_redirect_payment_option( $order_id ) {

$order = wc_get_order( $order_id );
$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
$amount = $order->get_total() * 100;
$txnref = $order_id . '_' . time();
$currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->order_currency;
$callback_url = WC()->api_request_url( 'WC_Gateway_Paystack' );

$payment_channels = $this->get_gateway_payment_channels( $order );

$paystack_params = array(
'amount' => $amount,
'email' => $email,
'currency' => $currency,
'email' => $order->get_billing_email(),
'currency' => $order->get_currency(),
'reference' => $txnref,
'callback_url' => $callback_url,
);
Expand Down Expand Up @@ -962,9 +953,7 @@ public function process_token_payment( $token, $order_id ) {

$order = wc_get_order( $order_id );

$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;
$order_amount = method_exists( $order, 'get_total' ) ? $order->get_total() : $order->order_total;
$order_amount = $order_amount * 100;
$order_amount = $order->get_total() * 100;

$paystack_url = 'https://api.paystack.co/transaction/charge_authorization';

Expand All @@ -976,7 +965,7 @@ public function process_token_payment( $token, $order_id ) {
$metadata['custom_fields'] = $this->get_custom_fields( $order_id );

$body = array(
'email' => $email,
'email' => $order->get_billing_email(),
'amount' => $order_amount,
'metadata' => $metadata,
'authorization_code' => $token,
Expand Down Expand Up @@ -1007,7 +996,7 @@ public function process_token_payment( $token, $order_id ) {
}

$order_total = $order->get_total();
$order_currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->get_order_currency();
$order_currency = $order->get_currency();
$currency_symbol = get_woocommerce_currency_symbol( $order_currency );
$amount_paid = $paystack_response->data->amount / 100;
$paystack_ref = $paystack_response->data->reference;
Expand Down Expand Up @@ -1181,7 +1170,7 @@ public function verify_paystack_transaction() {
}

$order_total = $order->get_total();
$order_currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->get_order_currency();
$order_currency = $order->get_currency();
$currency_symbol = get_woocommerce_currency_symbol( $order_currency );
$amount_paid = $paystack_response->data->amount / 100;
$paystack_ref = $paystack_response->data->reference;
Expand Down Expand Up @@ -1310,7 +1299,7 @@ public function process_webhooks() {
exit;
}

$order_currency = method_exists( $order, 'get_currency' ) ? $order->get_currency() : $order->get_order_currency();
$order_currency = $order->get_currency();

$currency_symbol = get_woocommerce_currency_symbol( $order_currency );

Expand Down Expand Up @@ -1508,37 +1497,30 @@ public function get_custom_fields( $order_id ) {

if ( $this->meta_name ) {

$first_name = method_exists( $order, 'get_billing_first_name' ) ? $order->get_billing_first_name() : $order->billing_first_name;
$last_name = method_exists( $order, 'get_billing_last_name' ) ? $order->get_billing_last_name() : $order->billing_last_name;

$custom_fields[] = array(
'display_name' => 'Customer Name',
'variable_name' => 'customer_name',
'value' => $first_name . ' ' . $last_name,
'value' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
);

}

if ( $this->meta_email ) {

$email = method_exists( $order, 'get_billing_email' ) ? $order->get_billing_email() : $order->billing_email;

$custom_fields[] = array(
'display_name' => 'Customer Email',
'variable_name' => 'customer_email',
'value' => $email,
'value' => $order->get_billing_email(),
);

}

if ( $this->meta_phone ) {

$billing_phone = method_exists( $order, 'get_billing_phone' ) ? $order->get_billing_phone() : $order->billing_phone;

$custom_fields[] = array(
'display_name' => 'Customer Phone',
'variable_name' => 'customer_phone',
'value' => $billing_phone,
'value' => $order->get_billing_phone(),
);

}
Expand Down
Loading

0 comments on commit bb47e6d

Please sign in to comment.