Skip to content
This repository was archived by the owner on Jan 10, 2022. It is now read-only.

Commit de7a11a

Browse files
committed
Switch to integration dependencies.
1 parent 3624860 commit de7a11a

2 files changed

Lines changed: 70 additions & 30 deletions

File tree

src/Extension.php

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Pronamic\WordPress\Pay\Extensions\WPeCommerce;
1212

13+
use Pronamic\WordPress\Pay\AbstractPluginIntegration;
1314
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
1415
use Pronamic\WordPress\Pay\Extensions\WPeCommerce\Gateways\Gateway;
1516
use Pronamic\WordPress\Pay\Payments\Payment;
@@ -22,10 +23,10 @@
2223
* Company: Pronamic
2324
*
2425
* @author Remco Tolsma
25-
* @version 2.0.4
26+
* @version 2.1.1
2627
* @since 1.0.0
2728
*/
28-
class Extension extends \Pronamic\WordPress\Pay\AbstractPluginIntegration {
29+
class Extension extends AbstractPluginIntegration {
2930
/**
3031
* Slug
3132
*
@@ -41,34 +42,41 @@ class Extension extends \Pronamic\WordPress\Pay\AbstractPluginIntegration {
4142
const OPTION_PRONAMIC_PAYMENT_METHOD = 'pronamic_pay_pronamic_wpsc_payment_method';
4243

4344
/**
44-
* Construct WP eCommerce extension.
45-
*
46-
* @param array $args Arguments.
45+
* Construct Ninja Forms plugin integration.
4746
*/
48-
public function __construct( $args = array() ) {
49-
parent::__construct( $args );
47+
public function __construct() {
48+
parent::__construct();
49+
50+
// Dependencies.
51+
$dependencies = $this->get_dependencies();
5052

51-
self::bootstrap();
53+
$dependencies->add( new WPeCommerceDependency() );
5254
}
5355

5456
/**
55-
* Bootstrap
57+
* Setup.
5658
*/
57-
public static function bootstrap() {
59+
public function setup() {
60+
\add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( $this, 'source_description' ), 10, 2 );
61+
62+
// Check if dependencies are met and integration is active.
63+
if ( ! $this->is_active() ) {
64+
return;
65+
}
66+
5867
// Add gateways.
59-
add_filter( 'wpsc_merchants_modules', array( __CLASS__, 'merchants_modules' ) );
68+
\add_filter( 'wpsc_merchants_modules', array( $this, 'merchants_modules' ) );
6069

6170
// Save gateway options.
62-
add_action( 'wpsc_submit_gateway_options', array( __CLASS__, 'submit_gateway_options' ) );
71+
\add_action( 'wpsc_submit_gateway_options', array( $this, 'submit_gateway_options' ) );
6372

6473
// Update payment status.
65-
add_action( 'pronamic_payment_status_update_' . self::SLUG, array( __CLASS__, 'status_update' ), 10, 2 );
74+
\add_action( 'pronamic_payment_status_update_' . self::SLUG, array( $this, 'status_update' ), 10, 2 );
6675

6776
// Filters.
68-
add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( __CLASS__, 'redirect_url' ), 10, 2 );
69-
add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( __CLASS__, 'source_text' ), 10, 2 );
70-
add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( __CLASS__, 'source_description' ), 10, 2 );
71-
add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( __CLASS__, 'source_url' ), 10, 2 );
77+
\add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( $this, 'redirect_url' ), 10, 2 );
78+
\add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( $this, 'source_text' ), 10, 2 );
79+
\add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( $this, 'source_url' ), 10, 2 );
7280
}
7381

7482
/**
@@ -78,7 +86,7 @@ public static function bootstrap() {
7886
*
7987
* @return array
8088
*/
81-
public static function merchants_modules( $gateways = array() ) {
89+
public function merchants_modules( $gateways = array() ) {
8290
global $nzshpcrt_gateways, $num, $wpsc_gateways, $gateway_checkout_form_fields;
8391

8492
$classes = array(
@@ -174,7 +182,7 @@ public static function merchants_modules( $gateways = array() ) {
174182
/**
175183
* Process gateway options submit.
176184
*/
177-
public static function submit_gateway_options() {
185+
public function submit_gateway_options() {
178186
// Get gateways.
179187
$gateways = self::merchants_modules();
180188

@@ -194,19 +202,14 @@ public static function submit_gateway_options() {
194202
* @param Payment $payment Payment.
195203
* @param bool $can_redirect Whether or not to redirect.
196204
*/
197-
public static function status_update( Payment $payment, $can_redirect = false ) {
205+
public function status_update( Payment $payment, $can_redirect = false ) {
198206
$merchant = new Gateway( $payment->get_source_id() );
199207

200208
switch ( $payment->status ) {
201209
case PaymentStatus::CANCELLED:
202210
$merchant->set_purchase_processed_by_purchid( WPeCommerce::PURCHASE_STATUS_INCOMPLETE_SALE );
203211

204212
break;
205-
206-
case PaymentStatus::EXPIRED:
207-
case PaymentStatus::FAILURE:
208-
break;
209-
210213
case PaymentStatus::SUCCESS:
211214
/*
212215
* Transactions results
@@ -220,7 +223,8 @@ public static function status_update( Payment $payment, $can_redirect = false )
220223
$merchant->set_purchase_processed_by_purchid( WPeCommerce::PURCHASE_STATUS_ACCEPTED_PAYMENT );
221224

222225
break;
223-
226+
case PaymentStatus::EXPIRED:
227+
case PaymentStatus::FAILURE:
224228
case PaymentStatus::OPEN:
225229
default:
226230
break;
@@ -235,7 +239,7 @@ public static function status_update( Payment $payment, $can_redirect = false )
235239
*
236240
* @return string
237241
*/
238-
public static function redirect_url( $url, Payment $payment ) {
242+
public function redirect_url( $url, Payment $payment ) {
239243
// URL arguments.
240244
$args = array(
241245
'sessionid' => $payment->get_meta( 'wpsc_session_id' ),
@@ -290,7 +294,7 @@ public static function redirect_url( $url, Payment $payment ) {
290294
*
291295
* @return string
292296
*/
293-
public static function source_text( $text, Payment $payment ) {
297+
public function source_text( $text, Payment $payment ) {
294298
$text = __( 'WP e-Commerce', 'pronamic_ideal' ) . '<br />';
295299

296300
$text .= sprintf(
@@ -317,7 +321,7 @@ public static function source_text( $text, Payment $payment ) {
317321
*
318322
* @return string
319323
*/
320-
public static function source_description( $description, Payment $payment ) {
324+
public function source_description( $description, Payment $payment ) {
321325
return __( 'WP e-Commerce Purchase', 'pronamic_ideal' );
322326
}
323327

@@ -329,7 +333,7 @@ public static function source_description( $description, Payment $payment ) {
329333
*
330334
* @return string
331335
*/
332-
public static function source_url( $url, Payment $payment ) {
336+
public function source_url( $url, Payment $payment ) {
333337
$url = add_query_arg(
334338
array(
335339
'page' => 'wpsc-purchase-logs',

src/WPeCommerceDependency.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* WP eCommerce Dependency
4+
*
5+
* @author Pronamic <info@pronamic.eu>
6+
* @copyright 2005-2020 Pronamic
7+
* @license GPL-3.0-or-later
8+
* @package Pronamic\WordPress\Pay\Extensions\WPeCommerce
9+
*/
10+
11+
namespace Pronamic\WordPress\Pay\Extensions\WPeCommerce;
12+
13+
use Pronamic\WordPress\Pay\Dependencies\Dependency;
14+
15+
/**
16+
* WP eCommerce Dependency
17+
*
18+
* @author Reüel van der Steege
19+
* @version 2.1.1
20+
* @since 2.1.1
21+
*/
22+
class WPeCommerceDependency extends Dependency {
23+
/**
24+
* Is met.
25+
*
26+
* @link
27+
* @return bool True if dependency is met, false otherwise.
28+
*/
29+
public function is_met() {
30+
if ( ! \class_exists( '\WP_eCommerce' ) ) {
31+
return false;
32+
}
33+
34+
return true;
35+
}
36+
}

0 commit comments

Comments
 (0)