-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbp-plugin-woocommerce-api2.php
162 lines (140 loc) · 6.32 KB
/
bp-plugin-woocommerce-api2.php
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Plugin Name: Better Payment WooCommerce Extension
* Plugin URI: https://github.com/better-payment/bp-plugin-woocommerce-api2
* Description: Better Payment plugin to implement payment methods using API2
* Version: 1.3.0
* Author: Better Payment
* Author URI: https://betterpayment.de
* Text Domain: bp-plugin-woocommerce-api2
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! class_exists( 'WC_BetterPayment_Plugin' ) ) {
class WC_BetterPayment_Plugin {
/**
* Construct the plugin.
*/
public function __construct() {
// Checks if WooCommerce is installed.
add_action('admin_notices', function () {
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$message = __('Better Payment WooCommerce Extension requires Woocommerce plugin to be activated', 'bp-plugin-woocommerce-api2');
echo "<div class='notice notice-error'><p>$message</p></div>";
}
});
add_action( 'plugins_loaded', array( $this, 'init' ) );
add_action( 'before_woocommerce_init', array( $this, 'declare_cart_checkout_blocks_compatibility' ) );
add_action( 'woocommerce_blocks_loaded', array( $this, 'betterpayment_blocks_support' ) );
}
/**
* Initialize the plugin.
*/
public function init() {
// Include our integration class.
include_once 'includes/integration.php';
// Register the integration.
add_filter( 'woocommerce_integrations', array( $this, 'add_integration' ) );
// Include payment methods
include_once 'includes/payment-gateways/abstract-betterpayment-gateway.php';
include_once 'includes/payment-gateways/credit-card.php';
include_once 'includes/payment-gateways/paypal.php';
include_once 'includes/payment-gateways/paydirekt.php';
include_once 'includes/payment-gateways/giropay.php';
include_once 'includes/payment-gateways/sofort.php';
include_once 'includes/payment-gateways/request-to-pay.php';
include_once 'includes/payment-gateways/aiia-pay.php';
include_once 'includes/payment-gateways/ideal.php';
include_once 'includes/payment-gateways/sepa-direct-debit.php';
include_once 'includes/payment-gateways/sepa-direct-debit-b2b.php';
include_once 'includes/payment-gateways/invoice.php';
include_once 'includes/payment-gateways/invoice-b2b.php';
include_once 'includes/payment-gateways/apple-pay.php';
// Register payment methods
add_filter('woocommerce_payment_gateways', array($this, 'add_betterpayment_gateways'));
// Include helpers
include_once 'includes/helpers/config-reader.php';
// Include custom endpoints
include_once 'includes/api/webhook.php';
include_once 'includes/api/apple-pay-session.php';
include_once 'includes/api/betterpayment-payment-request.php';
// Load translations
load_plugin_textdomain( 'bp-plugin-woocommerce-api2', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Add a new integration to WooCommerce.
*
* @param Array of integrations.
*/
public function add_integration($integrations) {
$integrations[] = 'BetterPayment_Plugin_Integration';
return $integrations;
}
/**
* Add a new payment methods to WooCommerce.
*
* @param Array of methods.
*/
public function add_betterpayment_gateways($methods) {
$methods[] = 'BetterPayment_Credit_Card';
$methods[] = 'BetterPayment_PayPal';
$methods[] = 'BetterPayment_Paydirekt';
$methods[] = 'BetterPayment_Giropay';
$methods[] = 'BetterPayment_Sofort';
$methods[] = 'BetterPayment_Request_To_Pay';
$methods[] = 'BetterPayment_Aiia_Pay';
$methods[] = 'BetterPayment_Ideal';
$methods[] = 'BetterPayment_Sepa_Direct_Debit';
$methods[] = 'BetterPayment_Sepa_Direct_Debit_B2B';
$methods[] = 'BetterPayment_Invoice';
$methods[] = 'BetterPayment_Invoice_B2B';
$methods[] = 'BetterPayment_Apple_Pay';
return $methods;
}
public function declare_cart_checkout_blocks_compatibility() {
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
}
}
public function betterpayment_blocks_support() {
if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
include_once 'includes/blocks/payments/aiia-pay.php';
include_once 'includes/blocks/payments/credit-card.php';
include_once 'includes/blocks/payments/giropay.php';
include_once 'includes/blocks/payments/ideal.php';
include_once 'includes/blocks/payments/paydirekt.php';
include_once 'includes/blocks/payments/paypal.php';
include_once 'includes/blocks/payments/request-to-pay.php';
include_once 'includes/blocks/payments/sofort.php';
include_once 'includes/blocks/payments/invoice.php';
include_once 'includes/blocks/payments/invoice-b2b.php';
include_once 'includes/blocks/payments/sepa-direct-debit.php';
include_once 'includes/blocks/payments/sepa-direct-debit-b2b.php';
include_once 'includes/blocks/payments/apple-pay.php';
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) {
$payment_method_registry->register( new BetterPayment_AiiaPay_Block() );
$payment_method_registry->register( new BetterPayment_Credit_Card_Block() );
$payment_method_registry->register( new BetterPayment_Giropay_Block() );
$payment_method_registry->register( new BetterPayment_Ideal_Block() );
$payment_method_registry->register( new BetterPayment_Paydirekt_Block() );
$payment_method_registry->register( new BetterPayment_PayPal_Block() );
$payment_method_registry->register( new BetterPayment_RequestToPay_Block() );
$payment_method_registry->register( new BetterPayment_Sofort_Block() );
$payment_method_registry->register( new BetterPayment_Invoice_Block() );
$payment_method_registry->register( new BetterPayment_Invoice_B2B_Block() );
$payment_method_registry->register( new BetterPayment_Sepa_Direct_Debit_Block() );
$payment_method_registry->register( new BetterPayment_Sepa_Direct_Debit_B2B_Block() );
$payment_method_registry->register( new BetterPayment_ApplePay_Block() );
}
);
}
}
}
}
$WC_BetterPayment_Plugin = new WC_BetterPayment_Plugin();