@@ -14,67 +14,67 @@ |
||
14 | 14 | class EE_PMT_Paypal_Smart_Buttons extends EE_PMT_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param EE_Payment_Method $pm_instance |
|
19 | - * @return EE_PMT_Paypal_Smart_Buttons |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder().'EEG_Paypal_Smart_Buttons.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Smart_Buttons(); |
|
25 | - $this->_pretty_name = __("PayPal Smart Buttons", 'event_espresso'); |
|
26 | - $this->_default_description = __('If payment with PayPal is unsuccessful, please try an alternative method, or contact us.', 'event_espresso'); |
|
27 | - $this->_requires_https = true; |
|
28 | - parent::__construct($pm_instance); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @param EE_Payment_Method $pm_instance |
|
19 | + * @return EE_PMT_Paypal_Smart_Buttons |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder().'EEG_Paypal_Smart_Buttons.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Smart_Buttons(); |
|
25 | + $this->_pretty_name = __("PayPal Smart Buttons", 'event_espresso'); |
|
26 | + $this->_default_description = __('If payment with PayPal is unsuccessful, please try an alternative method, or contact us.', 'event_espresso'); |
|
27 | + $this->_requires_https = true; |
|
28 | + parent::__construct($pm_instance); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Gets the form for all the settings related to this payment method type |
|
35 | - * @return EE_Payment_Method_Form |
|
36 | - */ |
|
37 | - public function generate_new_settings_form() |
|
38 | - { |
|
39 | - $form = new PayPalSmartButtonSettingsForm( |
|
40 | - $this->get_help_tab_link() |
|
41 | - ); |
|
42 | - return $form; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Gets the form for all the settings related to this payment method type |
|
35 | + * @return EE_Payment_Method_Form |
|
36 | + */ |
|
37 | + public function generate_new_settings_form() |
|
38 | + { |
|
39 | + $form = new PayPalSmartButtonSettingsForm( |
|
40 | + $this->get_help_tab_link() |
|
41 | + ); |
|
42 | + return $form; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Creates the billing form for this payment method type |
|
48 | - * @param \EE_Transaction $transaction |
|
49 | - * @throws \EE_Error |
|
50 | - * @return EE_Billing_Info_Form |
|
51 | - */ |
|
52 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
53 | - { |
|
54 | - return new EE_Billing_Info_Form( |
|
55 | - $this->_pm_instance, |
|
56 | - array( |
|
57 | - 'subsections' => |
|
58 | - array( |
|
59 | - 'token' => new EE_Hidden_Input(), |
|
60 | - ) |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
46 | + /** |
|
47 | + * Creates the billing form for this payment method type |
|
48 | + * @param \EE_Transaction $transaction |
|
49 | + * @throws \EE_Error |
|
50 | + * @return EE_Billing_Info_Form |
|
51 | + */ |
|
52 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
53 | + { |
|
54 | + return new EE_Billing_Info_Form( |
|
55 | + $this->_pm_instance, |
|
56 | + array( |
|
57 | + 'subsections' => |
|
58 | + array( |
|
59 | + 'token' => new EE_Hidden_Input(), |
|
60 | + ) |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Adds the help tab |
|
68 | - * @see EE_PMT_Base::help_tabs_config() |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function help_tabs_config() |
|
72 | - { |
|
73 | - return array( |
|
74 | - $this->get_help_tab_name() => array( |
|
75 | - 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
76 | - 'filename' => 'payment_methods_overview_paypalpro' |
|
77 | - ), |
|
78 | - ); |
|
79 | - } |
|
66 | + /** |
|
67 | + * Adds the help tab |
|
68 | + * @see EE_PMT_Base::help_tabs_config() |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function help_tabs_config() |
|
72 | + { |
|
73 | + return array( |
|
74 | + $this->get_help_tab_name() => array( |
|
75 | + 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
76 | + 'filename' => 'payment_methods_overview_paypalpro' |
|
77 | + ), |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | */ |
37 | 37 | public function generate_new_settings_form() |
38 | 38 | { |
39 | - $form = new PayPalSmartButtonSettingsForm( |
|
39 | + $form = new PayPalSmartButtonSettingsForm( |
|
40 | 40 | $this->get_help_tab_link() |
41 | 41 | ); |
42 | 42 | return $form; |
@@ -24,165 +24,165 @@ |
||
24 | 24 | class PayPalSmartButtonSettingsForm extends EE_Payment_Method_Form |
25 | 25 | { |
26 | 26 | |
27 | - public function __construct($help_tab_link, array $options_array = array()) |
|
28 | - { |
|
29 | - $options_array = array_merge_recursive( |
|
30 | - $options_array, |
|
31 | - array( |
|
32 | - 'extra_meta_inputs' => array( |
|
33 | - 'client_id' => new EE_Text_Input( |
|
34 | - array( |
|
35 | - 'html_label_text' => sprintf( |
|
36 | - _x( |
|
37 | - 'PayPal REST API App Client ID %s', |
|
38 | - 'PayPal REST API App Client ID (help link)', |
|
39 | - 'event_espresso' |
|
40 | - ), |
|
41 | - $help_tab_link |
|
42 | - ), |
|
43 | - 'required' => true, |
|
44 | - ) |
|
45 | - ), |
|
46 | - 'secret' => new EE_Text_Input( |
|
47 | - array( |
|
48 | - 'html_label_text' => sprintf( |
|
49 | - _x( |
|
50 | - 'PayPal REST API App Secret %s', |
|
51 | - 'PayPal REST API App Secret (help link)', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - $help_tab_link |
|
55 | - ), |
|
56 | - 'required' => true, |
|
57 | - ) |
|
58 | - ), |
|
59 | - 'button_color' => new EE_Select_Input( |
|
60 | - array( |
|
61 | - '' => esc_html__('Default', 'event_espresso'), |
|
62 | - 'gold' => esc_html__('Gold', 'event_espresso'), |
|
63 | - 'blue' => esc_html__('Blue', 'event_espresso'), |
|
64 | - 'darkblue' => esc_html__('Dark Blue', 'event_espresso'), |
|
65 | - 'silver' => esc_html__('Silver', 'event_espresso'), |
|
66 | - 'black' => esc_html__('Black', 'event_espresso'), |
|
67 | - ), |
|
68 | - array( |
|
69 | - 'html_label_text' => esc_html__('Button Color', 'event_espresso'), |
|
70 | - 'default' => '', |
|
71 | - ) |
|
72 | - ), |
|
73 | - 'button_shape' => new EE_Select_Input( |
|
74 | - array( |
|
75 | - 'pill' => esc_html__('Pill (Recommended)', 'event_espresso'), |
|
76 | - 'rect' => esc_html__('Rectangular', 'event_espresso'), |
|
77 | - ), |
|
78 | - array( |
|
79 | - 'html_label_text' => esc_html__('Button Shape', 'event_espresso'), |
|
80 | - 'default' => 'pill', |
|
81 | - ) |
|
82 | - ), |
|
83 | - 'button_size' => new EE_Select_Input( |
|
84 | - array( |
|
85 | - 'medium' => esc_html__('Medium (250px by 35px)', 'event_espresso'), |
|
86 | - 'large' => esc_html__('Large (350px by 40px)', 'event_espresso'), |
|
87 | - 'responsive' => esc_html__('Responsive (fills the page)', 'event_espresso'), |
|
88 | - ), |
|
89 | - array( |
|
90 | - 'html_label_text' => esc_html__('Button Size', 'event_espresso'), |
|
91 | - 'default' => 'medium', |
|
92 | - ) |
|
93 | - ), |
|
94 | - // store the access token like other extra meta inputs |
|
95 | - // except hide it, because we don't ask users for it directly. We will retrieve it from |
|
96 | - // PayPal upon form submission |
|
97 | - 'access_token' => new EE_Hidden_Input() |
|
98 | - ), |
|
99 | - 'exclude' => array( |
|
100 | - 'PMD_button_url', |
|
101 | - ), |
|
102 | - ) |
|
103 | - ); |
|
104 | - parent::__construct($options_array); |
|
105 | - } |
|
27 | + public function __construct($help_tab_link, array $options_array = array()) |
|
28 | + { |
|
29 | + $options_array = array_merge_recursive( |
|
30 | + $options_array, |
|
31 | + array( |
|
32 | + 'extra_meta_inputs' => array( |
|
33 | + 'client_id' => new EE_Text_Input( |
|
34 | + array( |
|
35 | + 'html_label_text' => sprintf( |
|
36 | + _x( |
|
37 | + 'PayPal REST API App Client ID %s', |
|
38 | + 'PayPal REST API App Client ID (help link)', |
|
39 | + 'event_espresso' |
|
40 | + ), |
|
41 | + $help_tab_link |
|
42 | + ), |
|
43 | + 'required' => true, |
|
44 | + ) |
|
45 | + ), |
|
46 | + 'secret' => new EE_Text_Input( |
|
47 | + array( |
|
48 | + 'html_label_text' => sprintf( |
|
49 | + _x( |
|
50 | + 'PayPal REST API App Secret %s', |
|
51 | + 'PayPal REST API App Secret (help link)', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + $help_tab_link |
|
55 | + ), |
|
56 | + 'required' => true, |
|
57 | + ) |
|
58 | + ), |
|
59 | + 'button_color' => new EE_Select_Input( |
|
60 | + array( |
|
61 | + '' => esc_html__('Default', 'event_espresso'), |
|
62 | + 'gold' => esc_html__('Gold', 'event_espresso'), |
|
63 | + 'blue' => esc_html__('Blue', 'event_espresso'), |
|
64 | + 'darkblue' => esc_html__('Dark Blue', 'event_espresso'), |
|
65 | + 'silver' => esc_html__('Silver', 'event_espresso'), |
|
66 | + 'black' => esc_html__('Black', 'event_espresso'), |
|
67 | + ), |
|
68 | + array( |
|
69 | + 'html_label_text' => esc_html__('Button Color', 'event_espresso'), |
|
70 | + 'default' => '', |
|
71 | + ) |
|
72 | + ), |
|
73 | + 'button_shape' => new EE_Select_Input( |
|
74 | + array( |
|
75 | + 'pill' => esc_html__('Pill (Recommended)', 'event_espresso'), |
|
76 | + 'rect' => esc_html__('Rectangular', 'event_espresso'), |
|
77 | + ), |
|
78 | + array( |
|
79 | + 'html_label_text' => esc_html__('Button Shape', 'event_espresso'), |
|
80 | + 'default' => 'pill', |
|
81 | + ) |
|
82 | + ), |
|
83 | + 'button_size' => new EE_Select_Input( |
|
84 | + array( |
|
85 | + 'medium' => esc_html__('Medium (250px by 35px)', 'event_espresso'), |
|
86 | + 'large' => esc_html__('Large (350px by 40px)', 'event_espresso'), |
|
87 | + 'responsive' => esc_html__('Responsive (fills the page)', 'event_espresso'), |
|
88 | + ), |
|
89 | + array( |
|
90 | + 'html_label_text' => esc_html__('Button Size', 'event_espresso'), |
|
91 | + 'default' => 'medium', |
|
92 | + ) |
|
93 | + ), |
|
94 | + // store the access token like other extra meta inputs |
|
95 | + // except hide it, because we don't ask users for it directly. We will retrieve it from |
|
96 | + // PayPal upon form submission |
|
97 | + 'access_token' => new EE_Hidden_Input() |
|
98 | + ), |
|
99 | + 'exclude' => array( |
|
100 | + 'PMD_button_url', |
|
101 | + ), |
|
102 | + ) |
|
103 | + ); |
|
104 | + parent::__construct($options_array); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * @return bool|void |
|
110 | - * @throws \EE_Error |
|
111 | - */ |
|
112 | - public function _validate() |
|
113 | - { |
|
114 | - parent::_validate(); // TODO: Change the autogenerated stub |
|
115 | - //also, let's check the credentials are valid. |
|
116 | - $valid_data = $this->valid_data(); |
|
117 | - if (isset($valid_data['client_id'], $valid_data['secret'])) { |
|
118 | - $response = wp_remote_post( |
|
119 | - 'https://api.sandbox.paypal.com/v1/oauth2/token', |
|
120 | - array( |
|
121 | - 'headers' => array( |
|
122 | - 'Accept' => 'application/json', |
|
123 | - 'Authorization' => 'Basic ' . base64_encode($valid_data['client_id'] . ':' . $valid_data['secret']), |
|
124 | - ), |
|
125 | - 'body' => array( |
|
126 | - 'grant_type' => 'client_credentials', |
|
127 | - ), |
|
128 | - ) |
|
129 | - ); |
|
130 | - if (is_wp_error($response)) { |
|
131 | - /** |
|
132 | - * @var $response WP_Error |
|
133 | - */ |
|
134 | - $this->add_validation_error( |
|
135 | - esc_html( |
|
136 | - sprintf( |
|
137 | - _x( |
|
138 | - 'There was an error while validating your PayPal credentials. The error was: %1$s', |
|
139 | - 'There was an error while validating your PayPal credentials. The error was: (error message)', |
|
140 | - 'event_espresso' |
|
141 | - ), |
|
142 | - $response->get_error_message() |
|
143 | - ) |
|
144 | - ) |
|
145 | - ); |
|
146 | - } |
|
147 | - $response_body = wp_remote_retrieve_body($response); |
|
148 | - if( ! $response_body) { |
|
149 | - $this->add_validation_error( |
|
150 | - esc_html__( |
|
151 | - 'There was an error while validating your PayPal credentials. No response was received from PayPal', |
|
152 | - 'event_espresso' |
|
153 | - ) |
|
154 | - ); |
|
155 | - } |
|
156 | - $response_json = json_decode($response_body, true); |
|
157 | - if (! is_array($response_json)) { |
|
158 | - $this->add_validation_error( |
|
159 | - esc_html__('There was an error while validating your PayPal Credentials. No JSON body was received.', 'event_espresso') |
|
160 | - ); |
|
161 | - } |
|
162 | - if( isset($response_json['error'], $response_json['error_description'])) { |
|
163 | - $this->add_validation_error( |
|
164 | - esc_html( |
|
165 | - sprintf( |
|
166 | - _x( |
|
167 | - 'There was an error validating your PayPal credentials. %1$s (%2$s)', |
|
168 | - 'There was an error validating your PayPal credentials. Error message (error_code)', |
|
169 | - 'event_espresso' |
|
170 | - ), |
|
171 | - $response_json['error_description'], |
|
172 | - $response_json['error'] |
|
173 | - ) |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
178 | - if (isset($response_json['access_token'])) { |
|
179 | - $this->populate_defaults( |
|
180 | - array( |
|
181 | - 'access_token' => $response_json['access_token'] |
|
182 | - ) |
|
183 | - ); |
|
184 | - } |
|
185 | - } |
|
108 | + /** |
|
109 | + * @return bool|void |
|
110 | + * @throws \EE_Error |
|
111 | + */ |
|
112 | + public function _validate() |
|
113 | + { |
|
114 | + parent::_validate(); // TODO: Change the autogenerated stub |
|
115 | + //also, let's check the credentials are valid. |
|
116 | + $valid_data = $this->valid_data(); |
|
117 | + if (isset($valid_data['client_id'], $valid_data['secret'])) { |
|
118 | + $response = wp_remote_post( |
|
119 | + 'https://api.sandbox.paypal.com/v1/oauth2/token', |
|
120 | + array( |
|
121 | + 'headers' => array( |
|
122 | + 'Accept' => 'application/json', |
|
123 | + 'Authorization' => 'Basic ' . base64_encode($valid_data['client_id'] . ':' . $valid_data['secret']), |
|
124 | + ), |
|
125 | + 'body' => array( |
|
126 | + 'grant_type' => 'client_credentials', |
|
127 | + ), |
|
128 | + ) |
|
129 | + ); |
|
130 | + if (is_wp_error($response)) { |
|
131 | + /** |
|
132 | + * @var $response WP_Error |
|
133 | + */ |
|
134 | + $this->add_validation_error( |
|
135 | + esc_html( |
|
136 | + sprintf( |
|
137 | + _x( |
|
138 | + 'There was an error while validating your PayPal credentials. The error was: %1$s', |
|
139 | + 'There was an error while validating your PayPal credentials. The error was: (error message)', |
|
140 | + 'event_espresso' |
|
141 | + ), |
|
142 | + $response->get_error_message() |
|
143 | + ) |
|
144 | + ) |
|
145 | + ); |
|
146 | + } |
|
147 | + $response_body = wp_remote_retrieve_body($response); |
|
148 | + if( ! $response_body) { |
|
149 | + $this->add_validation_error( |
|
150 | + esc_html__( |
|
151 | + 'There was an error while validating your PayPal credentials. No response was received from PayPal', |
|
152 | + 'event_espresso' |
|
153 | + ) |
|
154 | + ); |
|
155 | + } |
|
156 | + $response_json = json_decode($response_body, true); |
|
157 | + if (! is_array($response_json)) { |
|
158 | + $this->add_validation_error( |
|
159 | + esc_html__('There was an error while validating your PayPal Credentials. No JSON body was received.', 'event_espresso') |
|
160 | + ); |
|
161 | + } |
|
162 | + if( isset($response_json['error'], $response_json['error_description'])) { |
|
163 | + $this->add_validation_error( |
|
164 | + esc_html( |
|
165 | + sprintf( |
|
166 | + _x( |
|
167 | + 'There was an error validating your PayPal credentials. %1$s (%2$s)', |
|
168 | + 'There was an error validating your PayPal credentials. Error message (error_code)', |
|
169 | + 'event_espresso' |
|
170 | + ), |
|
171 | + $response_json['error_description'], |
|
172 | + $response_json['error'] |
|
173 | + ) |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | + if (isset($response_json['access_token'])) { |
|
179 | + $this->populate_defaults( |
|
180 | + array( |
|
181 | + 'access_token' => $response_json['access_token'] |
|
182 | + ) |
|
183 | + ); |
|
184 | + } |
|
185 | + } |
|
186 | 186 | } |
187 | 187 | // End of file PayPalSmartButtonSettingsForm.php |
188 | 188 | // Location: EventEspresso\caffeinated\payment_methods\Paypal_Smart_Buttons\forms/PayPalSmartButtonSettingsForm.php |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | array( |
121 | 121 | 'headers' => array( |
122 | 122 | 'Accept' => 'application/json', |
123 | - 'Authorization' => 'Basic ' . base64_encode($valid_data['client_id'] . ':' . $valid_data['secret']), |
|
123 | + 'Authorization' => 'Basic '.base64_encode($valid_data['client_id'].':'.$valid_data['secret']), |
|
124 | 124 | ), |
125 | 125 | 'body' => array( |
126 | 126 | 'grant_type' => 'client_credentials', |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | ); |
146 | 146 | } |
147 | 147 | $response_body = wp_remote_retrieve_body($response); |
148 | - if( ! $response_body) { |
|
148 | + if ( ! $response_body) { |
|
149 | 149 | $this->add_validation_error( |
150 | 150 | esc_html__( |
151 | 151 | 'There was an error while validating your PayPal credentials. No response was received from PayPal', |
@@ -154,12 +154,12 @@ discard block |
||
154 | 154 | ); |
155 | 155 | } |
156 | 156 | $response_json = json_decode($response_body, true); |
157 | - if (! is_array($response_json)) { |
|
157 | + if ( ! is_array($response_json)) { |
|
158 | 158 | $this->add_validation_error( |
159 | 159 | esc_html__('There was an error while validating your PayPal Credentials. No JSON body was received.', 'event_espresso') |
160 | 160 | ); |
161 | 161 | } |
162 | - if( isset($response_json['error'], $response_json['error_description'])) { |
|
162 | + if (isset($response_json['error'], $response_json['error_description'])) { |
|
163 | 163 | $this->add_validation_error( |
164 | 164 | esc_html( |
165 | 165 | sprintf( |