class-wc-payments-subscriptions.php
3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Class WC_Payments_Subscriptions.
*
* @package WooCommerce\Payments
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* Class for loading WooCommerce Payments Subscriptions.
*/
class WC_Payments_Subscriptions {
/**
* Instance of WC_Payments_Product_Service, created in init function.
*
* @var WC_Payments_Product_Service
*/
private static $product_service;
/**
* Instance of WC_Payments_Invoice_Service, created in init function.
*
* @var WC_Payments_Invoice_Service
*/
private static $invoice_service;
/**
* Instance of WC_Payments_Subscription_Service, created in init function.
*
* @var WC_Payments_Subscription_Service
*/
private static $subscription_service;
/**
* Instance of WC_Payments_Subscriptions_Event_Handler, created in init function.
*
* @var WC_Payments_Subscriptions_Event_Handler
*/
private static $event_handler;
/**
* Initialize WooCommerce Payments subscriptions. (Stripe Billing)
*
* @param WC_Payments_API_Client $api_client WCPay API client.
* @param WC_Payments_Customer_Service $customer_service WCPay Customer Service.
* @param WC_Payment_Gateway_WCPay $gateway WCPay Payment Gateway.
* @param WC_Payments_Account $account WC_Payments_Account.
*/
public static function init( WC_Payments_API_Client $api_client, WC_Payments_Customer_Service $customer_service, WC_Payment_Gateway_WCPay $gateway, WC_Payments_Account $account ) {
// Load Services.
include_once __DIR__ . '/class-wc-payments-product-service.php';
include_once __DIR__ . '/class-wc-payments-invoice-service.php';
include_once __DIR__ . '/class-wc-payments-subscription-service.php';
include_once __DIR__ . '/class-wc-payments-subscription-change-payment-method-handler.php';
include_once __DIR__ . '/class-wc-payments-subscriptions-plugin-notice-manager.php';
include_once __DIR__ . '/class-wc-payments-subscriptions-empty-state-manager.php';
self::$product_service = new WC_Payments_Product_Service( $api_client );
self::$invoice_service = new WC_Payments_Invoice_Service( $api_client, self::$product_service, $gateway );
self::$subscription_service = new WC_Payments_Subscription_Service( $api_client, $customer_service, self::$product_service, self::$invoice_service );
// Load the subscription and invoice incoming event handler.
include_once __DIR__ . '/class-wc-payments-subscriptions-event-handler.php';
self::$event_handler = new WC_Payments_Subscriptions_Event_Handler( self::$invoice_service, self::$subscription_service );
new WC_Payments_Subscription_Change_Payment_Method_Handler();
new WC_Payments_Subscriptions_Plugin_Notice_Manager();
new WC_Payments_Subscriptions_Empty_State_Manager( $account );
// Load the Subscriptions Onboarding class.
include_once __DIR__ . '/class-wc-payments-subscriptions-onboarding-handler.php';
new WC_Payments_Subscriptions_Onboarding_Handler( $account );
include_once __DIR__ . '/class-wc-payments-subscription-minimum-amount-handler.php';
new WC_Payments_Subscription_Minimum_Amount_Handler( $api_client );
}
/**
* Get the Event Handler class instance.
*
* @return WC_Payments_Subscriptions_Event_Handler
*/
public static function get_event_handler() {
return self::$event_handler;
}
/**
* Returns the the product service instance.
*
* @return WC_Payments_Product_Service The product service object.
*/
public static function get_product_service() {
return self::$product_service;
}
/**
* Returns the the invoice service instance.
*
* @return WC_Payments_Invoice_Service
*/
public static function get_invoice_service() {
return self::$invoice_service;
}
/**
* Returns the the subscription service instance.
*
* @return WC_Payments_Subscription_Service
*/
public static function get_subscription_service() {
return self::$subscription_service;
}
}