-
Notifications
You must be signed in to change notification settings - Fork 1
/
EED_Paypal_Smart_Buttons.module.php
91 lines (83 loc) · 2.58 KB
/
EED_Paypal_Smart_Buttons.module.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
<?php
use EventEspresso\core\exceptions\EntityNotFoundException;
/**
* Class EED_Paypal_Smart_Buttons
*
* Description
*
* @package Event Espresso
* @author Mike Nelson
* @since 1.0.0.p
*
*/
class EED_Paypal_Smart_Buttons extends EED_Module
{
public static function set_hooks()
{
}
public static function set_hooks_admin()
{
}
/**
* Gets the cart's current transaction or returns null
* @return EE_Transaction|void
*/
protected static function getCurrentTransaction()
{
$checkout = EED_Single_Page_Checkout::instance()->checkout;
if (! $checkout instanceof EE_Checkout) {
// we only want this JS during checkout
return null;
}
// fetch the current transaction
$current_transaction = EED_Single_Page_Checkout::instance()->transaction();
if (! $current_transaction instanceof EE_Transaction) {
return null;
}
return $current_transaction;
}
/**
* Gets the current paypal smart buttons payment method, based on the transaction
* @param $transaction
* @throws EE_Error
* @throws InvalidArgumentException
* @throws \EventEspresso\core\exceptions\InvalidDataTypeException
* @throws \EventEspresso\core\exceptions\InvalidInterfaceException
*/
protected static function getCurrentPaypalSmartButtonPM($transaction)
{
if (! $transaction) {
return null;
}
$applicable_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
$transaction,
EEM_Payment_Method::scope_cart
);
$paypal_smart_button_pm = null;
foreach ($applicable_payment_methods as $payment_method) {
if ($payment_method->type() === 'Paypal_Smart_Buttons') {
$paypal_smart_button_pm = $payment_method;
break;
}
}
if (! $paypal_smart_button_pm instanceof EE_Payment_Method) {
// if the paypal smart button isn't active, we don't need to run this JS at all
return null;
}
return $paypal_smart_button_pm;
}
/**
* run - initial module setup
* this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
*
* @access public
* @var WP $WP
* @return void
*/
public function run($WP)
{
// nothing to do here
}
}
// End of file EED_Paypal_Smart_Buttons.php
// Location: ${NAMESPACE}/EED_Paypal_Smart_Buttons.php