PayPalCommerce
5 years ago
PayPalStandard
5 years ago
PaymentGateway.php
5 years ago
PaypalSettingPage.php
5 years ago
SettingPage.php
5 years ago
PaypalSettingPage.php
122 lines
| 1 | <?php |
| 2 | namespace Give\PaymentGateways; |
| 3 | |
| 4 | use Give\PaymentGateways\PayPalCommerce\PayPalCommerce; |
| 5 | use Give\PaymentGateways\PayPalCommerce\AdminSettingFields; |
| 6 | use Give\PaymentGateways\PayPalStandard\PayPalStandard; |
| 7 | use function give_get_current_setting_section as getCurrentSettingSection; |
| 8 | |
| 9 | /** |
| 10 | * Class PaypalSettingSection |
| 11 | * @package Give\PaymentGateways |
| 12 | * |
| 13 | * @sicne 2.9.0 |
| 14 | */ |
| 15 | class PaypalSettingPage implements SettingPage { |
| 16 | /** |
| 17 | * @var PayPalCommerce |
| 18 | */ |
| 19 | private $payPalCommerce; |
| 20 | |
| 21 | /** |
| 22 | * @var PayPalStandard |
| 23 | */ |
| 24 | private $paypalStandard; |
| 25 | |
| 26 | /** |
| 27 | * Register properties |
| 28 | * |
| 29 | * @param PayPalCommerce $payPalCommerce |
| 30 | * @param PayPalStandard $paypalStandard |
| 31 | * |
| 32 | * @since 2.9.0 |
| 33 | */ |
| 34 | public function __construct( PayPalCommerce $payPalCommerce, PayPalStandard $paypalStandard ) { |
| 35 | $this->payPalCommerce = $payPalCommerce; |
| 36 | $this->paypalStandard = $paypalStandard; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @inheritDoc |
| 41 | */ |
| 42 | public function boot() { |
| 43 | add_action( 'give_get_groups_paypal', [ $this, 'getGroups' ] ); |
| 44 | add_filter( 'give_get_settings_gateways', [ $this, 'registerPaypalSettings' ] ); |
| 45 | add_filter( 'give_get_sections_gateways', [ $this, 'registerPaypalSettingSection' ], 5 ); |
| 46 | |
| 47 | // Load custom setting fields. |
| 48 | $adminSettingFields = new AdminSettingFields(); |
| 49 | $adminSettingFields->boot(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @inheritDoc |
| 54 | */ |
| 55 | public function getId() { |
| 56 | return 'paypal'; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @inheritDoc |
| 61 | */ |
| 62 | public function getName() { |
| 63 | return esc_html__( 'PayPal', 'give' ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @inheritDoc |
| 68 | */ |
| 69 | public function getSettings() { |
| 70 | $settings[ $this->payPalCommerce->getId() ] = $this->payPalCommerce->getOptions(); |
| 71 | $settings[ $this->paypalStandard->getId() ] = $this->paypalStandard->getOptions(); |
| 72 | |
| 73 | return $settings; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get groups. |
| 78 | * |
| 79 | * @since 2.9.0 |
| 80 | * |
| 81 | * @return array |
| 82 | */ |
| 83 | public function getGroups() { |
| 84 | return [ |
| 85 | $this->payPalCommerce->getId() => $this->payPalCommerce->getName(), |
| 86 | $this->paypalStandard->getId() => $this->paypalStandard->getName(), |
| 87 | ]; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Register settings. |
| 92 | * |
| 93 | * @param array $settings |
| 94 | * |
| 95 | * @since 2.9.0 |
| 96 | * |
| 97 | * @return array |
| 98 | */ |
| 99 | public function registerPaypalSettings( $settings ) { |
| 100 | $currentSection = getCurrentSettingSection(); |
| 101 | |
| 102 | return $currentSection === $this->getId() ? |
| 103 | $this->getSettings() : |
| 104 | $settings; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Register setting section. |
| 109 | * |
| 110 | * @param array $sections |
| 111 | * |
| 112 | * @since 2.9.0 |
| 113 | * |
| 114 | * @return array |
| 115 | */ |
| 116 | public function registerPaypalSettingSection( $sections ) { |
| 117 | $sections[ $this->getId() ] = $this->getName(); |
| 118 | |
| 119 | return $sections; |
| 120 | } |
| 121 | } |
| 122 |