Skip to content

Commit 610cae5

Browse files
authored
Version 5.8.0 Release (#90)
2 parents a34c22b + c8281fb commit 610cae5

15 files changed

Lines changed: 19064 additions & 66 deletions

.gitignore

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,59 @@
1+
2+
# Operating System files
13
.DS_Store
2-
.idea
4+
Thumbs.db
5+
6+
# IDE files
7+
.idea
8+
.vscode/*
9+
project.xml
10+
project.properties
11+
.project
12+
.settings*
13+
*.sublime-project
14+
*.sublime-workspace
15+
.sublimelinterrc
16+
17+
# Sass
18+
.sass-cache/
19+
20+
# Logs
21+
logs/
22+
23+
# Environment files
24+
wp-cli.local.yml
25+
yarn-error.log
26+
npm-debug.log
27+
.pnpm-debug.log
28+
29+
# Build files
30+
*.sql
31+
*.swp
32+
*.zip
33+
34+
# Built packages
35+
build/
36+
build-module/
37+
build-style/
38+
build-types/
39+
dist/
40+
41+
# Project files
42+
node_modules/
43+
vendor/
44+
45+
# TypeScript files
46+
tsconfig.tsbuildinfo
47+
48+
# wp-env config
49+
.wp-env.override.json
50+
51+
# Unit tests
52+
tmp/
53+
54+
# Composer
55+
vendor/
56+
bin/composer/**/vendor/
57+
lib/vendor/
58+
contributors.md
59+
contributors.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php return array('dependencies' => array('wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '56849d74fd092513b4dd');

assets/js/blocks/frontend/blocks.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-wc-gateway-custom-paystack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public function payment_scripts() {
445445

446446
wp_enqueue_script( 'jquery' );
447447

448-
wp_enqueue_script( 'paystack', 'https://js.paystack.co/v1/inline.js', array( 'jquery' ), WC_PAYSTACK_VERSION, false );
448+
wp_enqueue_script( 'paystack', 'https://js.paystack.co/v2/inline.js', array( 'jquery' ), WC_PAYSTACK_VERSION, false );
449449

450450
wp_enqueue_script( 'wc_paystack', plugins_url( 'assets/js/paystack' . $suffix . '.js', WC_PAYSTACK_MAIN_FILE ), array( 'jquery', 'paystack' ), WC_PAYSTACK_VERSION, false );
451451

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
4+
use Automattic\WooCommerce\StoreApi\Payments\PaymentContext;
5+
use Automattic\WooCommerce\StoreApi\Payments\PaymentResult;
6+
7+
final class WC_Gateway_Paystack_Blocks_Support extends AbstractPaymentMethodType {
8+
9+
/**
10+
* Payment method name/id/slug.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'paystack';
15+
16+
/**
17+
* Initializes the payment method type.
18+
*/
19+
public function initialize() {
20+
$this->settings = get_option( 'woocommerce_paystack_settings', array() );
21+
22+
add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'failed_payment_notice' ), 8, 2 );
23+
}
24+
25+
/**
26+
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
27+
*
28+
* @return boolean
29+
*/
30+
public function is_active() {
31+
$payment_gateways_class = WC()->payment_gateways();
32+
$payment_gateways = $payment_gateways_class->payment_gateways();
33+
return $payment_gateways['paystack']->is_available();
34+
}
35+
36+
/**
37+
* Returns an array of scripts/handles to be registered for this payment method.
38+
*
39+
* @return array
40+
*/
41+
public function get_payment_method_script_handles() {
42+
$script_asset_path = plugins_url( '/assets/js/blocks/frontend/blocks.asset.php', WC_PAYSTACK_MAIN_FILE );
43+
$script_asset = file_exists( $script_asset_path )
44+
? require $script_asset_path
45+
: array(
46+
'dependencies' => array(),
47+
'version' => WC_PAYSTACK_VERSION,
48+
);
49+
50+
$script_url = plugins_url( '/assets/js/blocks/frontend/blocks.js', WC_PAYSTACK_MAIN_FILE );
51+
52+
wp_register_script(
53+
'wc-paystack-blocks',
54+
$script_url,
55+
$script_asset['dependencies'],
56+
$script_asset['version'],
57+
true
58+
);
59+
60+
if ( function_exists( 'wp_set_script_translations' ) ) {
61+
wp_set_script_translations( 'wc-paystack-blocks', 'woo-paystack', );
62+
}
63+
64+
return array( 'wc-paystack-blocks' );
65+
}
66+
67+
/**
68+
* Returns an array of key=>value pairs of data made available to the payment methods script.
69+
*
70+
* @return array
71+
*/
72+
public function get_payment_method_data() {
73+
$payment_gateways_class = WC()->payment_gateways();
74+
$payment_gateways = $payment_gateways_class->payment_gateways();
75+
$gateway = $payment_gateways['paystack'];
76+
77+
return array(
78+
'title' => $this->get_setting( 'title' ),
79+
'description' => $this->get_setting( 'description' ),
80+
'supports' => array_filter( $gateway->supports, array( $gateway, 'supports' ) ),
81+
'allow_saved_cards' => $gateway->saved_cards && is_user_logged_in(),
82+
'logo_url' => array( $payment_gateways['paystack']->get_logo_url() ),
83+
);
84+
}
85+
86+
/**
87+
* Add failed payment notice to the payment details.
88+
*
89+
* @param PaymentContext $context Holds context for the payment.
90+
* @param PaymentResult $result Result object for the payment.
91+
*/
92+
public function failed_payment_notice( PaymentContext $context, PaymentResult &$result ) {
93+
if ( 'paystack' === $context->payment_method ) {
94+
add_action(
95+
'wc_gateway_paystack_process_payment_error',
96+
function( $failed_notice ) use ( &$result ) {
97+
$payment_details = $result->payment_details;
98+
$payment_details['errorMessage'] = wp_strip_all_tags( $failed_notice );
99+
$result->set_payment_details( $payment_details );
100+
}
101+
);
102+
}
103+
}
104+
}

includes/class-wc-gateway-paystack-subscriptions.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ public function __construct() {
2323
}
2424
}
2525

26-
/**
27-
* Check if an order contains a subscription.
28-
*
29-
* @param int $order_id WC Order ID.
30-
*
31-
* @return bool
32-
*/
33-
public function order_contains_subscription( $order_id ) {
34-
35-
return function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) );
36-
37-
}
38-
3926
/**
4027
* Process a trial subscription order with 0 total.
4128
*
@@ -131,6 +118,7 @@ public function process_subscription_payment( $order, $amount ) {
131118
'metadata' => $metadata,
132119
'authorization_code' => $auth_code,
133120
'reference' => $txnref,
121+
'currency' => $order->get_currency(),
134122
);
135123

136124
$args = array(

includes/class-wc-gateway-paystack.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ public function process_token_payment( $token, $order_id ) {
986986
'metadata' => $metadata,
987987
'authorization_code' => $auth_code,
988988
'reference' => $txnref,
989+
'currency' => $order->get_currency(),
989990
);
990991

991992
$args = array(
@@ -1099,8 +1100,9 @@ function_exists( 'wc_reduce_stock_levels' ) ? wc_reduce_stock_levels( $order_id
10991100

11001101
wc_add_notice( $failed_notice, 'error' );
11011102

1102-
return false;
1103+
do_action( 'wc_gateway_paystack_process_payment_error', $failed_notice, $order );
11031104

1105+
return false;
11041106
}
11051107
}
11061108
} else {
@@ -1786,4 +1788,37 @@ private function get_paystack_transaction( $paystack_txn_ref ) {
17861788

17871789
return false;
17881790
}
1791+
1792+
/**
1793+
* Get Paystack payment icon URL.
1794+
*/
1795+
public function get_logo_url() {
1796+
1797+
$base_location = wc_get_base_location();
1798+
1799+
if ( 'GH' === $base_location['country'] ) {
1800+
$url = WC_HTTPS::force_https_url( plugins_url( 'assets/images/paystack-gh.png', WC_PAYSTACK_MAIN_FILE ) );
1801+
} elseif ( 'ZA' === $base_location['country'] ) {
1802+
$url = WC_HTTPS::force_https_url( plugins_url( 'assets/images/paystack-za.png', WC_PAYSTACK_MAIN_FILE ) );
1803+
} elseif ( 'KE' === $base_location['country'] ) {
1804+
$url = WC_HTTPS::force_https_url( plugins_url( 'assets/images/paystack-ke.png', WC_PAYSTACK_MAIN_FILE ) );
1805+
} else {
1806+
$url = WC_HTTPS::force_https_url( plugins_url( 'assets/images/paystack-wc.png', WC_PAYSTACK_MAIN_FILE ) );
1807+
}
1808+
1809+
return apply_filters( 'wc_paystack_gateway_icon_url', $url, $this->id );
1810+
}
1811+
1812+
/**
1813+
* Check if an order contains a subscription.
1814+
*
1815+
* @param int $order_id WC Order ID.
1816+
*
1817+
* @return bool
1818+
*/
1819+
public function order_contains_subscription( $order_id ) {
1820+
1821+
return function_exists( 'wcs_order_contains_subscription' ) && ( wcs_order_contains_subscription( $order_id ) || wcs_order_contains_renewal( $order_id ) );
1822+
1823+
}
17891824
}

0 commit comments

Comments
 (0)