@@ -16,53 +16,53 @@ |
||
16 | 16 | */ |
17 | 17 | class SettingsForm extends PayPalSettingsForm |
18 | 18 | { |
19 | - /** |
|
20 | - * SettingsForm constructor. |
|
21 | - * |
|
22 | - * @param array $options_array |
|
23 | - * @param string $help_tab_link |
|
24 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
25 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
26 | - * @throws \InvalidArgumentException |
|
27 | - */ |
|
28 | - public function __construct(array $options_array = array(), $help_tab_link) |
|
29 | - { |
|
30 | - $options_array = array_replace_recursive( |
|
31 | - array( |
|
32 | - 'extra_meta_inputs' => array( |
|
33 | - 'request_shipping_addr' => new EE_Yes_No_Input( |
|
34 | - array( |
|
35 | - 'html_label_text' => sprintf( |
|
36 | - esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
37 | - $help_tab_link |
|
38 | - ), |
|
39 | - 'html_help_text' => esc_html__( |
|
40 | - // @codingStandardsIgnoreStart |
|
41 | - 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
42 | - // @codingStandardsIgnoreEnd |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - 'required' => true, |
|
46 | - 'default' => false, |
|
47 | - ) |
|
48 | - ), |
|
49 | - 'image_url' => new EE_Admin_File_Uploader_Input( |
|
50 | - array( |
|
51 | - 'html_label_text' => sprintf( |
|
52 | - esc_html__('Image URL %s', 'event_espresso'), |
|
53 | - $help_tab_link |
|
54 | - ), |
|
55 | - 'html_help_text' => esc_html__( |
|
56 | - 'Used for your business/personal logo on the PayPal page', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - 'required' => false, |
|
60 | - ) |
|
61 | - ), |
|
62 | - ) |
|
63 | - ), |
|
64 | - $options_array |
|
65 | - ); |
|
66 | - parent::__construct($options_array, $help_tab_link); |
|
67 | - } |
|
19 | + /** |
|
20 | + * SettingsForm constructor. |
|
21 | + * |
|
22 | + * @param array $options_array |
|
23 | + * @param string $help_tab_link |
|
24 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
25 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
26 | + * @throws \InvalidArgumentException |
|
27 | + */ |
|
28 | + public function __construct(array $options_array = array(), $help_tab_link) |
|
29 | + { |
|
30 | + $options_array = array_replace_recursive( |
|
31 | + array( |
|
32 | + 'extra_meta_inputs' => array( |
|
33 | + 'request_shipping_addr' => new EE_Yes_No_Input( |
|
34 | + array( |
|
35 | + 'html_label_text' => sprintf( |
|
36 | + esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
37 | + $help_tab_link |
|
38 | + ), |
|
39 | + 'html_help_text' => esc_html__( |
|
40 | + // @codingStandardsIgnoreStart |
|
41 | + 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
42 | + // @codingStandardsIgnoreEnd |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + 'required' => true, |
|
46 | + 'default' => false, |
|
47 | + ) |
|
48 | + ), |
|
49 | + 'image_url' => new EE_Admin_File_Uploader_Input( |
|
50 | + array( |
|
51 | + 'html_label_text' => sprintf( |
|
52 | + esc_html__('Image URL %s', 'event_espresso'), |
|
53 | + $help_tab_link |
|
54 | + ), |
|
55 | + 'html_help_text' => esc_html__( |
|
56 | + 'Used for your business/personal logo on the PayPal page', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + 'required' => false, |
|
60 | + ) |
|
61 | + ), |
|
62 | + ) |
|
63 | + ), |
|
64 | + $options_array |
|
65 | + ); |
|
66 | + parent::__construct($options_array, $help_tab_link); |
|
67 | + } |
|
68 | 68 | } |
@@ -15,89 +15,89 @@ |
||
15 | 15 | class EE_PMT_Paypal_Express extends EE_PMT_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * EE_PMT_Paypal_Express constructor. |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Express(); |
|
18 | + /** |
|
19 | + * EE_PMT_Paypal_Express constructor. |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Express(); |
|
25 | 25 | |
26 | - $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | - $this->_template_path = $this->file_folder() . 'templates' . DS; |
|
28 | - $this->_default_description = esc_html__( |
|
29 | - // @codingStandardsIgnoreStart |
|
30 | - 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | - // @codingStandardsIgnoreEnd |
|
32 | - 'event_espresso' |
|
33 | - ); |
|
34 | - $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png'; |
|
26 | + $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | + $this->_template_path = $this->file_folder() . 'templates' . DS; |
|
28 | + $this->_default_description = esc_html__( |
|
29 | + // @codingStandardsIgnoreStart |
|
30 | + 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | + // @codingStandardsIgnoreEnd |
|
32 | + 'event_espresso' |
|
33 | + ); |
|
34 | + $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png'; |
|
35 | 35 | |
36 | - parent::__construct($pm_instance); |
|
37 | - } |
|
36 | + parent::__construct($pm_instance); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Adds the help tab. |
|
42 | - * |
|
43 | - * @see EE_PMT_Base::help_tabs_config() |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function help_tabs_config() |
|
47 | - { |
|
48 | - return array( |
|
49 | - $this->get_help_tab_name() => array( |
|
50 | - 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | - 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
40 | + /** |
|
41 | + * Adds the help tab. |
|
42 | + * |
|
43 | + * @see EE_PMT_Base::help_tabs_config() |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function help_tabs_config() |
|
47 | + { |
|
48 | + return array( |
|
49 | + $this->get_help_tab_name() => array( |
|
50 | + 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | + 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Gets the form for all the settings related to this payment method type. |
|
59 | - * |
|
60 | - * @return EE_Payment_Method_Form |
|
61 | - */ |
|
62 | - public function generate_new_settings_form() |
|
63 | - { |
|
64 | - return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | - } |
|
57 | + /** |
|
58 | + * Gets the form for all the settings related to this payment method type. |
|
59 | + * |
|
60 | + * @return EE_Payment_Method_Form |
|
61 | + */ |
|
62 | + public function generate_new_settings_form() |
|
63 | + { |
|
64 | + return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Creates a billing form for this payment method type. |
|
70 | - * |
|
71 | - * @param \EE_Transaction $transaction |
|
72 | - * @return \EE_Billing_Info_Form |
|
73 | - */ |
|
74 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | - { |
|
76 | - if ($this->_pm_instance->debug_mode()) { |
|
77 | - $form = new EE_Billing_Info_Form( |
|
78 | - $this->_pm_instance, |
|
79 | - array( |
|
80 | - 'name' => 'paypal_express_Info_Form', |
|
81 | - 'subsections' => array( |
|
82 | - 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | - array( |
|
84 | - 'layout_strategy' => new EE_Template_Layout( |
|
85 | - array( |
|
86 | - 'layout_template_file' => $this->_template_path |
|
87 | - . 'paypal_express_debug_info.template.php', |
|
88 | - 'template_args' => array( |
|
89 | - 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | - ) |
|
91 | - ) |
|
92 | - ) |
|
93 | - ) |
|
94 | - ) |
|
95 | - ) |
|
96 | - ) |
|
97 | - ); |
|
98 | - return $form; |
|
99 | - } |
|
68 | + /** |
|
69 | + * Creates a billing form for this payment method type. |
|
70 | + * |
|
71 | + * @param \EE_Transaction $transaction |
|
72 | + * @return \EE_Billing_Info_Form |
|
73 | + */ |
|
74 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | + { |
|
76 | + if ($this->_pm_instance->debug_mode()) { |
|
77 | + $form = new EE_Billing_Info_Form( |
|
78 | + $this->_pm_instance, |
|
79 | + array( |
|
80 | + 'name' => 'paypal_express_Info_Form', |
|
81 | + 'subsections' => array( |
|
82 | + 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | + array( |
|
84 | + 'layout_strategy' => new EE_Template_Layout( |
|
85 | + array( |
|
86 | + 'layout_template_file' => $this->_template_path |
|
87 | + . 'paypal_express_debug_info.template.php', |
|
88 | + 'template_args' => array( |
|
89 | + 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | + ) |
|
91 | + ) |
|
92 | + ) |
|
93 | + ) |
|
94 | + ) |
|
95 | + ) |
|
96 | + ) |
|
97 | + ); |
|
98 | + return $form; |
|
99 | + } |
|
100 | 100 | |
101 | - return false; |
|
102 | - } |
|
101 | + return false; |
|
102 | + } |
|
103 | 103 | } |
@@ -17,164 +17,164 @@ |
||
17 | 17 | */ |
18 | 18 | class PayPalSettingsForm extends EE_Payment_Method_Form |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string of HTML being the help tab link |
|
22 | - */ |
|
23 | - protected $helpTabLink; |
|
20 | + /** |
|
21 | + * @var string of HTML being the help tab link |
|
22 | + */ |
|
23 | + protected $helpTabLink; |
|
24 | 24 | |
25 | - public function __construct(array $options_array = array(), $help_tab_link) |
|
26 | - { |
|
27 | - $this->helpTabLink = $help_tab_link; |
|
28 | - $options_array = array_replace_recursive( |
|
29 | - array( |
|
30 | - 'extra_meta_inputs' => array( |
|
31 | - 'api_username' => new EE_Text_Input( |
|
32 | - array( |
|
33 | - 'html_label_text' => sprintf( |
|
34 | - esc_html__('API Username %s', 'event_espresso'), |
|
35 | - $help_tab_link |
|
36 | - ), |
|
37 | - 'required' => true, |
|
38 | - ) |
|
39 | - ), |
|
40 | - 'api_password' => new EE_Text_Input( |
|
41 | - array( |
|
42 | - 'html_label_text' => sprintf( |
|
43 | - esc_html__('API Password %s', 'event_espresso'), |
|
44 | - $help_tab_link |
|
45 | - ), |
|
46 | - 'required' => true, |
|
47 | - ) |
|
48 | - ), |
|
49 | - 'api_signature' => new EE_Text_Input( |
|
50 | - array( |
|
51 | - 'html_label_text' => sprintf( |
|
52 | - esc_html__('API Signature %s', 'event_espresso'), |
|
53 | - $help_tab_link |
|
54 | - ), |
|
55 | - 'required' => true, |
|
56 | - ) |
|
57 | - ), |
|
58 | - ) |
|
59 | - )); |
|
60 | - parent::__construct($options_array); |
|
61 | - } |
|
25 | + public function __construct(array $options_array = array(), $help_tab_link) |
|
26 | + { |
|
27 | + $this->helpTabLink = $help_tab_link; |
|
28 | + $options_array = array_replace_recursive( |
|
29 | + array( |
|
30 | + 'extra_meta_inputs' => array( |
|
31 | + 'api_username' => new EE_Text_Input( |
|
32 | + array( |
|
33 | + 'html_label_text' => sprintf( |
|
34 | + esc_html__('API Username %s', 'event_espresso'), |
|
35 | + $help_tab_link |
|
36 | + ), |
|
37 | + 'required' => true, |
|
38 | + ) |
|
39 | + ), |
|
40 | + 'api_password' => new EE_Text_Input( |
|
41 | + array( |
|
42 | + 'html_label_text' => sprintf( |
|
43 | + esc_html__('API Password %s', 'event_espresso'), |
|
44 | + $help_tab_link |
|
45 | + ), |
|
46 | + 'required' => true, |
|
47 | + ) |
|
48 | + ), |
|
49 | + 'api_signature' => new EE_Text_Input( |
|
50 | + array( |
|
51 | + 'html_label_text' => sprintf( |
|
52 | + esc_html__('API Signature %s', 'event_espresso'), |
|
53 | + $help_tab_link |
|
54 | + ), |
|
55 | + 'required' => true, |
|
56 | + ) |
|
57 | + ), |
|
58 | + ) |
|
59 | + )); |
|
60 | + parent::__construct($options_array); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Tests the the PayPal API credentials work ok |
|
65 | - * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string |
|
66 | - */ |
|
67 | - protected function checkForCredentialsErrors() |
|
68 | - { |
|
69 | - $request_params = array( |
|
70 | - 'METHOD' => 'GetBalance', |
|
71 | - 'VERSION' => '204.0', |
|
72 | - 'USER' => urlencode($this->get_input_value('api_username')), |
|
73 | - 'PWD' => urlencode($this->get_input_value('api_password')), |
|
74 | - 'SIGNATURE' => urlencode($this->get_input_value('api_signature')), |
|
75 | - ); |
|
76 | - $gateway_url = $this->get_input_value('PMD_debug_mode') |
|
77 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
78 | - : 'https://api-3t.paypal.com/nvp'; |
|
79 | - // Request Customer Details. |
|
80 | - $response = wp_remote_post( |
|
81 | - $gateway_url, |
|
82 | - array( |
|
83 | - 'method' => 'POST', |
|
84 | - 'timeout' => 45, |
|
85 | - 'httpversion' => '1.1', |
|
86 | - 'cookies' => array(), |
|
87 | - 'headers' => array(), |
|
88 | - 'body' => http_build_query($request_params, '', '&'), |
|
89 | - ) |
|
90 | - ); |
|
91 | - if (is_wp_error($response) || empty($response['body'])) { |
|
92 | - // If we got here then there was an error in this request. |
|
93 | - // maybe is turned off. We don't know the credentials are invalid |
|
94 | - EE_Error::add_error( |
|
95 | - sprintf( |
|
96 | - esc_html__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'), |
|
97 | - $response->get_error_message() |
|
98 | - ), |
|
99 | - __FILE__, |
|
100 | - __FUNCTION__, |
|
101 | - __LINE__ |
|
102 | - ); |
|
103 | - } |
|
104 | - $response_args = array(); |
|
105 | - parse_str(urldecode($response['body']), $response_args); |
|
63 | + /** |
|
64 | + * Tests the the PayPal API credentials work ok |
|
65 | + * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string |
|
66 | + */ |
|
67 | + protected function checkForCredentialsErrors() |
|
68 | + { |
|
69 | + $request_params = array( |
|
70 | + 'METHOD' => 'GetBalance', |
|
71 | + 'VERSION' => '204.0', |
|
72 | + 'USER' => urlencode($this->get_input_value('api_username')), |
|
73 | + 'PWD' => urlencode($this->get_input_value('api_password')), |
|
74 | + 'SIGNATURE' => urlencode($this->get_input_value('api_signature')), |
|
75 | + ); |
|
76 | + $gateway_url = $this->get_input_value('PMD_debug_mode') |
|
77 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
78 | + : 'https://api-3t.paypal.com/nvp'; |
|
79 | + // Request Customer Details. |
|
80 | + $response = wp_remote_post( |
|
81 | + $gateway_url, |
|
82 | + array( |
|
83 | + 'method' => 'POST', |
|
84 | + 'timeout' => 45, |
|
85 | + 'httpversion' => '1.1', |
|
86 | + 'cookies' => array(), |
|
87 | + 'headers' => array(), |
|
88 | + 'body' => http_build_query($request_params, '', '&'), |
|
89 | + ) |
|
90 | + ); |
|
91 | + if (is_wp_error($response) || empty($response['body'])) { |
|
92 | + // If we got here then there was an error in this request. |
|
93 | + // maybe is turned off. We don't know the credentials are invalid |
|
94 | + EE_Error::add_error( |
|
95 | + sprintf( |
|
96 | + esc_html__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'), |
|
97 | + $response->get_error_message() |
|
98 | + ), |
|
99 | + __FILE__, |
|
100 | + __FUNCTION__, |
|
101 | + __LINE__ |
|
102 | + ); |
|
103 | + } |
|
104 | + $response_args = array(); |
|
105 | + parse_str(urldecode($response['body']), $response_args); |
|
106 | 106 | |
107 | - if (empty($response_args['ACK'])) { |
|
108 | - EE_Error::add_error( |
|
109 | - esc_html__('Your PayPal credentials could not be verified. Part of their response was missing.', 'event_espresso'), |
|
110 | - __FILE__, |
|
111 | - __FUNCTION__, |
|
112 | - __LINE__ |
|
113 | - ); |
|
114 | - } |
|
115 | - if (in_array( |
|
116 | - $response_args['ACK'], |
|
117 | - array( |
|
118 | - 'Success', |
|
119 | - 'SuccessWithWarning' |
|
120 | - ), |
|
121 | - true |
|
122 | - ) |
|
123 | - ) { |
|
124 | - return ''; |
|
125 | - } else { |
|
126 | - return sprintf( |
|
127 | - esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'), |
|
128 | - isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'), |
|
129 | - isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0 |
|
130 | - ); |
|
131 | - } |
|
132 | - } |
|
107 | + if (empty($response_args['ACK'])) { |
|
108 | + EE_Error::add_error( |
|
109 | + esc_html__('Your PayPal credentials could not be verified. Part of their response was missing.', 'event_espresso'), |
|
110 | + __FILE__, |
|
111 | + __FUNCTION__, |
|
112 | + __LINE__ |
|
113 | + ); |
|
114 | + } |
|
115 | + if (in_array( |
|
116 | + $response_args['ACK'], |
|
117 | + array( |
|
118 | + 'Success', |
|
119 | + 'SuccessWithWarning' |
|
120 | + ), |
|
121 | + true |
|
122 | + ) |
|
123 | + ) { |
|
124 | + return ''; |
|
125 | + } else { |
|
126 | + return sprintf( |
|
127 | + esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'), |
|
128 | + isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'), |
|
129 | + isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0 |
|
130 | + ); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Gets the HTML to show the link to the help tab |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - protected function helpTabLink() |
|
139 | - { |
|
140 | - return $this->helpTabLink; |
|
141 | - } |
|
134 | + /** |
|
135 | + * Gets the HTML to show the link to the help tab |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + protected function helpTabLink() |
|
139 | + { |
|
140 | + return $this->helpTabLink; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Does the normal validation, but also verifies the PayPal API credentials work. |
|
145 | - * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips) |
|
146 | - * on each of the inputs that could be the cause of the problem. |
|
147 | - * @throws EntityNotFoundException |
|
148 | - */ |
|
149 | - public function _validate() |
|
150 | - { |
|
151 | - parent::_validate(); |
|
152 | - $credentials_message = $this->checkForCredentialsErrors(); |
|
153 | - if ($credentials_message !== '') { |
|
154 | - $this->add_validation_error($credentials_message); |
|
155 | - $this->get_input('PMD_debug_mode')->add_validation_error( |
|
156 | - esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso') |
|
157 | - ); |
|
158 | - $this->get_input('api_username')->add_validation_error( |
|
159 | - sprintf( |
|
160 | - esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'), |
|
161 | - $this->helpTabLink() |
|
162 | - ) |
|
163 | - ); |
|
164 | - $this->get_input('api_password')->add_validation_error( |
|
165 | - sprintf( |
|
166 | - esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'), |
|
167 | - $this->helpTabLink() |
|
168 | - ) |
|
169 | - ); |
|
170 | - $this->get_input('api_signature')->add_validation_error( |
|
171 | - sprintf( |
|
172 | - esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'), |
|
173 | - $this->helpTabLink() |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
143 | + /** |
|
144 | + * Does the normal validation, but also verifies the PayPal API credentials work. |
|
145 | + * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips) |
|
146 | + * on each of the inputs that could be the cause of the problem. |
|
147 | + * @throws EntityNotFoundException |
|
148 | + */ |
|
149 | + public function _validate() |
|
150 | + { |
|
151 | + parent::_validate(); |
|
152 | + $credentials_message = $this->checkForCredentialsErrors(); |
|
153 | + if ($credentials_message !== '') { |
|
154 | + $this->add_validation_error($credentials_message); |
|
155 | + $this->get_input('PMD_debug_mode')->add_validation_error( |
|
156 | + esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso') |
|
157 | + ); |
|
158 | + $this->get_input('api_username')->add_validation_error( |
|
159 | + sprintf( |
|
160 | + esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'), |
|
161 | + $this->helpTabLink() |
|
162 | + ) |
|
163 | + ); |
|
164 | + $this->get_input('api_password')->add_validation_error( |
|
165 | + sprintf( |
|
166 | + esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'), |
|
167 | + $this->helpTabLink() |
|
168 | + ) |
|
169 | + ); |
|
170 | + $this->get_input('api_signature')->add_validation_error( |
|
171 | + sprintf( |
|
172 | + esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'), |
|
173 | + $this->helpTabLink() |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | // End of file PayPalSettingsForm.php |
@@ -14,148 +14,148 @@ |
||
14 | 14 | class EE_PMT_Paypal_Pro extends EE_PMT_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param EE_Payment_Method $pm_instance |
|
19 | - * @return EE_PMT_Paypal_Pro |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Pro(); |
|
25 | - $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
26 | - $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
27 | - $this->_requires_https = true; |
|
28 | - parent::__construct($pm_instance); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
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 | - return new SettingsForm(array(), $this->get_help_tab_link()); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Creates the billing form for this payment method type |
|
45 | - * @param \EE_Transaction $transaction |
|
46 | - * @throws \EE_Error |
|
47 | - * @return EE_Billing_Info_Form |
|
48 | - */ |
|
49 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
50 | - { |
|
51 | - $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
52 | - // if allowed types is a string or empty array or null... |
|
53 | - if (empty($allowed_types)) { |
|
54 | - $allowed_types = array(); |
|
55 | - } |
|
56 | - |
|
57 | - $billing_form = new EE_Billing_Attendee_Info_Form( |
|
58 | - $this->_pm_instance, |
|
59 | - array( |
|
60 | - 'name'=> 'Paypal_Pro_Billing_Form', |
|
61 | - // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
62 | - 'subsections'=>array( |
|
63 | - 'credit_card'=>new EE_Credit_Card_Input( |
|
64 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
65 | - ), |
|
66 | - 'credit_card_type'=>new EE_Select_Input( |
|
67 | - // the options are set dynamically |
|
68 | - array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
69 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
70 | - ), |
|
71 | - 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
72 | - true, |
|
73 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
74 | - ), |
|
75 | - 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
76 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
77 | - ), |
|
78 | - 'cvv'=>new EE_CVV_Input( |
|
79 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
80 | - ), |
|
81 | - ) |
|
82 | - ) |
|
83 | - ); |
|
84 | - return $this->apply_billing_form_debug_settings($billing_form); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * apply_billing_form_debug_settings |
|
91 | - * applies debug data to the form |
|
92 | - * |
|
93 | - * @param \EE_Billing_Info_Form $billing_form |
|
94 | - * @return \EE_Billing_Info_Form |
|
95 | - */ |
|
96 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
97 | - { |
|
98 | - if ($this->_pm_instance->debug_mode()) { |
|
99 | - $billing_form->add_subsections( |
|
100 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
101 | - 'credit_card' |
|
102 | - ); |
|
103 | - $billing_form->add_subsections( |
|
104 | - array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
105 | - 'first_name' |
|
106 | - ); |
|
107 | - $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
108 | - $billing_form->get_input('exp_year')->set_default(2018); |
|
109 | - $billing_form->get_input('cvv')->set_default('115'); |
|
110 | - } |
|
111 | - return $billing_form; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns an array of all the payment cards possibly supported by paypal pro. |
|
118 | - * Keys are their values, values are their pretty names. |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public static function card_types_supported() |
|
122 | - { |
|
123 | - return array( |
|
124 | - 'Visa'=> __("Visa", 'event_espresso'), |
|
125 | - 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
126 | - 'Amex'=> __("American Express", 'event_espresso'), |
|
127 | - 'Discover'=> __("Discover", 'event_espresso') |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Adds the help tab |
|
135 | - * @see EE_PMT_Base::help_tabs_config() |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public function help_tabs_config() |
|
139 | - { |
|
140 | - return array( |
|
141 | - $this->get_help_tab_name() => array( |
|
142 | - 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
143 | - 'filename' => 'payment_methods_overview_paypalpro' |
|
144 | - ), |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Overrides parent's _get_billing_values_from_form because we want to |
|
150 | - * get the country's 2-character ISO code, not the name like most gateways |
|
151 | - * @param EE_Billing_Info_Form $billing_form |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - protected function _get_billing_values_from_form($billing_form) |
|
155 | - { |
|
156 | - $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
157 | - $billing_values['country'] = $billing_form->get_input_value('country'); |
|
158 | - $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
159 | - return $billing_values; |
|
160 | - } |
|
17 | + /** |
|
18 | + * @param EE_Payment_Method $pm_instance |
|
19 | + * @return EE_PMT_Paypal_Pro |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Pro(); |
|
25 | + $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
26 | + $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
27 | + $this->_requires_https = true; |
|
28 | + parent::__construct($pm_instance); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
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 | + return new SettingsForm(array(), $this->get_help_tab_link()); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Creates the billing form for this payment method type |
|
45 | + * @param \EE_Transaction $transaction |
|
46 | + * @throws \EE_Error |
|
47 | + * @return EE_Billing_Info_Form |
|
48 | + */ |
|
49 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
50 | + { |
|
51 | + $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
52 | + // if allowed types is a string or empty array or null... |
|
53 | + if (empty($allowed_types)) { |
|
54 | + $allowed_types = array(); |
|
55 | + } |
|
56 | + |
|
57 | + $billing_form = new EE_Billing_Attendee_Info_Form( |
|
58 | + $this->_pm_instance, |
|
59 | + array( |
|
60 | + 'name'=> 'Paypal_Pro_Billing_Form', |
|
61 | + // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
62 | + 'subsections'=>array( |
|
63 | + 'credit_card'=>new EE_Credit_Card_Input( |
|
64 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
65 | + ), |
|
66 | + 'credit_card_type'=>new EE_Select_Input( |
|
67 | + // the options are set dynamically |
|
68 | + array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
69 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
70 | + ), |
|
71 | + 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
72 | + true, |
|
73 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
74 | + ), |
|
75 | + 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
76 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
77 | + ), |
|
78 | + 'cvv'=>new EE_CVV_Input( |
|
79 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
80 | + ), |
|
81 | + ) |
|
82 | + ) |
|
83 | + ); |
|
84 | + return $this->apply_billing_form_debug_settings($billing_form); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * apply_billing_form_debug_settings |
|
91 | + * applies debug data to the form |
|
92 | + * |
|
93 | + * @param \EE_Billing_Info_Form $billing_form |
|
94 | + * @return \EE_Billing_Info_Form |
|
95 | + */ |
|
96 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
97 | + { |
|
98 | + if ($this->_pm_instance->debug_mode()) { |
|
99 | + $billing_form->add_subsections( |
|
100 | + array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
101 | + 'credit_card' |
|
102 | + ); |
|
103 | + $billing_form->add_subsections( |
|
104 | + array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
105 | + 'first_name' |
|
106 | + ); |
|
107 | + $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
108 | + $billing_form->get_input('exp_year')->set_default(2018); |
|
109 | + $billing_form->get_input('cvv')->set_default('115'); |
|
110 | + } |
|
111 | + return $billing_form; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns an array of all the payment cards possibly supported by paypal pro. |
|
118 | + * Keys are their values, values are their pretty names. |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public static function card_types_supported() |
|
122 | + { |
|
123 | + return array( |
|
124 | + 'Visa'=> __("Visa", 'event_espresso'), |
|
125 | + 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
126 | + 'Amex'=> __("American Express", 'event_espresso'), |
|
127 | + 'Discover'=> __("Discover", 'event_espresso') |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Adds the help tab |
|
135 | + * @see EE_PMT_Base::help_tabs_config() |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public function help_tabs_config() |
|
139 | + { |
|
140 | + return array( |
|
141 | + $this->get_help_tab_name() => array( |
|
142 | + 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
143 | + 'filename' => 'payment_methods_overview_paypalpro' |
|
144 | + ), |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Overrides parent's _get_billing_values_from_form because we want to |
|
150 | + * get the country's 2-character ISO code, not the name like most gateways |
|
151 | + * @param EE_Billing_Info_Form $billing_form |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + protected function _get_billing_values_from_form($billing_form) |
|
155 | + { |
|
156 | + $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
157 | + $billing_values['country'] = $billing_form->get_input_value('country'); |
|
158 | + $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
159 | + return $billing_values; |
|
160 | + } |
|
161 | 161 | } |
@@ -18,32 +18,32 @@ |
||
18 | 18 | */ |
19 | 19 | class SettingsForm extends PayPalSettingsForm |
20 | 20 | { |
21 | - /** |
|
22 | - * SettingsForm constructor. |
|
23 | - * |
|
24 | - * @param array $options_array |
|
25 | - * @param string $help_tab_link |
|
26 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
27 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
28 | - * @throws \InvalidArgumentException |
|
29 | - */ |
|
30 | - public function __construct(array $options_array = array(), $help_tab_link) |
|
31 | - { |
|
32 | - $options_array = array_replace_recursive( |
|
33 | - array( |
|
34 | - 'extra_meta_inputs' => array( |
|
35 | - 'credit_card_types' => new EE_Checkbox_Multi_Input( |
|
36 | - EE_PMT_Paypal_Pro::card_types_supported(), |
|
37 | - array( |
|
38 | - 'html_label_text' => __('Card Types Supported', 'event_espresso'), |
|
39 | - 'required' => true ) |
|
40 | - ), |
|
41 | - ) |
|
42 | - ), |
|
43 | - $options_array |
|
44 | - ); |
|
45 | - parent::__construct($options_array, $help_tab_link); |
|
46 | - } |
|
21 | + /** |
|
22 | + * SettingsForm constructor. |
|
23 | + * |
|
24 | + * @param array $options_array |
|
25 | + * @param string $help_tab_link |
|
26 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
27 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
28 | + * @throws \InvalidArgumentException |
|
29 | + */ |
|
30 | + public function __construct(array $options_array = array(), $help_tab_link) |
|
31 | + { |
|
32 | + $options_array = array_replace_recursive( |
|
33 | + array( |
|
34 | + 'extra_meta_inputs' => array( |
|
35 | + 'credit_card_types' => new EE_Checkbox_Multi_Input( |
|
36 | + EE_PMT_Paypal_Pro::card_types_supported(), |
|
37 | + array( |
|
38 | + 'html_label_text' => __('Card Types Supported', 'event_espresso'), |
|
39 | + 'required' => true ) |
|
40 | + ), |
|
41 | + ) |
|
42 | + ), |
|
43 | + $options_array |
|
44 | + ); |
|
45 | + parent::__construct($options_array, $help_tab_link); |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | // End of file SettingsForm.php |
49 | 49 | // Location: EventEspresso\caffeinated\payment_methods\PayPal_Pro\forms/SettingsForm.php |
@@ -11,598 +11,598 @@ |
||
11 | 11 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var $_paypal_api_username string |
|
16 | - */ |
|
17 | - protected $_username = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var $_password string |
|
21 | - */ |
|
22 | - protected $_password = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_signature string |
|
26 | - */ |
|
27 | - protected $_signature = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | - */ |
|
32 | - protected $_credit_card_types = null; |
|
33 | - |
|
34 | - protected $_currencies_supported = array( |
|
35 | - 'USD', |
|
36 | - 'GBP', |
|
37 | - 'CAD', |
|
38 | - 'AUD', |
|
39 | - 'BRL', |
|
40 | - 'CHF', |
|
41 | - 'CZK', |
|
42 | - 'DKK', |
|
43 | - 'EUR', |
|
44 | - 'HKD', |
|
45 | - 'HUF', |
|
46 | - 'ILS', |
|
47 | - 'JPY', |
|
48 | - 'MXN', |
|
49 | - 'MYR', |
|
50 | - 'NOK', |
|
51 | - 'NZD', |
|
52 | - 'PHP', |
|
53 | - 'PLN', |
|
54 | - 'SEK', |
|
55 | - 'SGD', |
|
56 | - 'THB', |
|
57 | - 'TRY', |
|
58 | - 'TWD', |
|
59 | - 'RUB', |
|
60 | - 'INR', |
|
61 | - ); |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EEI_Payment $payment |
|
67 | - * @param array $billing_info { |
|
68 | - * @type string $credit_card |
|
69 | - * @type string $credit_card_type |
|
70 | - * @type string $exp_month always 2 characters |
|
71 | - * @type string $exp_year always 4 characters |
|
72 | - * @type string $cvv |
|
73 | - * } |
|
74 | - * @see parent::do_direct_payment for more info |
|
75 | - * @return EE_Payment|EEI_Payment |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function do_direct_payment($payment, $billing_info = null) |
|
79 | - { |
|
80 | - $transaction = $payment->transaction(); |
|
81 | - if (! $transaction instanceof EEI_Transaction) { |
|
82 | - throw new EE_Error( |
|
83 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - $primary_registrant = $transaction->primary_registration(); |
|
87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | - throw new EE_Error( |
|
89 | - esc_html__( |
|
90 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | - 'event_espresso' |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - $attendee = $primary_registrant->attendee(); |
|
96 | - if (! $attendee instanceof EEI_Attendee) { |
|
97 | - throw new EE_Error( |
|
98 | - esc_html__( |
|
99 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | - 'event_espresso' |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | - $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | - // charge for the full amount. Show itemized list |
|
107 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | - $item_num = 1; |
|
109 | - $total_line_item = $transaction->total_line_item(); |
|
110 | - $order_items = array(); |
|
111 | - foreach ($total_line_item->get_items() as $line_item) { |
|
112 | - // ignore line items with a quantity of 0 |
|
113 | - if ($line_item->quantity() == 0) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - $item = array( |
|
117 | - // Item Name. 127 char max. |
|
118 | - 'l_name' => substr( |
|
119 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | - 0, |
|
121 | - 127 |
|
122 | - ), |
|
123 | - // Item description. 127 char max. |
|
124 | - 'l_desc' => substr( |
|
125 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | - 0, |
|
127 | - 127 |
|
128 | - ), |
|
129 | - // Cost of individual item. |
|
130 | - 'l_amt' => $line_item->unit_price(), |
|
131 | - // Item Number. 127 char max. |
|
132 | - 'l_number' => $item_num++, |
|
133 | - // Item quantity. Must be any positive integer. |
|
134 | - 'l_qty' => $line_item->quantity(), |
|
135 | - // Item's sales tax amount. |
|
136 | - 'l_taxamt' => '', |
|
137 | - // eBay auction number of item. |
|
138 | - 'l_ebayitemnumber' => '', |
|
139 | - // eBay transaction ID of purchased item. |
|
140 | - 'l_ebayitemauctiontxnid' => '', |
|
141 | - // eBay order ID for the item. |
|
142 | - 'l_ebayitemorderid' => '', |
|
143 | - ); |
|
144 | - // add to array of all items |
|
145 | - array_push($order_items, $item); |
|
146 | - } |
|
147 | - $item_amount = $total_line_item->get_items_total(); |
|
148 | - $tax_amount = $total_line_item->get_total_tax(); |
|
149 | - } else { |
|
150 | - $order_items = array(); |
|
151 | - $item_amount = $payment->amount(); |
|
152 | - $tax_amount = 0; |
|
153 | - array_push($order_items, array( |
|
154 | - // Item Name. 127 char max. |
|
155 | - 'l_name' => substr( |
|
156 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | - 0, |
|
158 | - 127 |
|
159 | - ), |
|
160 | - // Item description. 127 char max. |
|
161 | - 'l_desc' => substr( |
|
162 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | - 0, |
|
164 | - 127 |
|
165 | - ), |
|
166 | - // Cost of individual item. |
|
167 | - 'l_amt' => $payment->amount(), |
|
168 | - // Item Number. 127 char max. |
|
169 | - 'l_number' => 1, |
|
170 | - // Item quantity. Must be any positive integer. |
|
171 | - 'l_qty' => 1, |
|
172 | - )); |
|
173 | - } |
|
174 | - // Populate data arrays with order data. |
|
175 | - $DPFields = array( |
|
176 | - // How you want to obtain payment ? |
|
177 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | - 'paymentaction' => 'Sale', |
|
180 | - // Required. IP address of the payer's browser. |
|
181 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | - 'returnfmfdetails' => '1', |
|
184 | - ); |
|
185 | - $CCDetails = array( |
|
186 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | - // If Maestro or Solo, the currency code must be GBP. |
|
188 | - // In addition, either start date or issue number must be specified. |
|
189 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | - // Required. Credit card number. No spaces or punctuation. |
|
191 | - 'acct' => $billing_info['credit_card'], |
|
192 | - // Required. Credit card expiration date. Format is MMYYYY |
|
193 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | - 'cvv2' => $billing_info['cvv'], |
|
196 | - ); |
|
197 | - $PayerInfo = array( |
|
198 | - // Email address of payer. |
|
199 | - 'email' => $billing_info['email'], |
|
200 | - // Unique PayPal customer ID for payer. |
|
201 | - 'payerid' => '', |
|
202 | - // Status of payer. Values are verified or unverified |
|
203 | - 'payerstatus' => '', |
|
204 | - // Payer's business name. |
|
205 | - 'business' => '', |
|
206 | - ); |
|
207 | - $PayerName = array( |
|
208 | - // Payer's salutation. 20 char max. |
|
209 | - 'salutation' => '', |
|
210 | - // Payer's first name. 25 char max. |
|
211 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | - // Payer's middle name. 25 char max. |
|
213 | - 'middlename' => '', |
|
214 | - // Payer's last name. 25 char max. |
|
215 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | - // Payer's suffix. 12 char max. |
|
217 | - 'suffix' => '', |
|
218 | - ); |
|
219 | - $BillingAddress = array( |
|
220 | - // Required. First street address. |
|
221 | - 'street' => $billing_info['address'], |
|
222 | - // Second street address. |
|
223 | - 'street2' => $billing_info['address2'], |
|
224 | - // Required. Name of City. |
|
225 | - 'city' => $billing_info['city'], |
|
226 | - // Required. Name of State or Province. |
|
227 | - 'state' => substr($billing_info['state'], 0, 40), |
|
228 | - // Required. Country code. |
|
229 | - 'countrycode' => $billing_info['country'], |
|
230 | - // Required. Postal code of payer. |
|
231 | - 'zip' => $billing_info['zip'], |
|
232 | - ); |
|
233 | - // check if the registration info contains the needed fields for paypal pro |
|
234 | - // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | - $use_registration_address_info = true; |
|
237 | - } else { |
|
238 | - $use_registration_address_info = false; |
|
239 | - } |
|
240 | - // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | - // If not, use the billing info again |
|
242 | - $ShippingAddress = array( |
|
243 | - 'shiptoname' => substr($use_registration_address_info |
|
244 | - ? $attendee->full_name() |
|
245 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | - 'shiptostreet' => substr($use_registration_address_info |
|
247 | - ? $attendee->address() |
|
248 | - : $billing_info['address'], 0, 100), |
|
249 | - 'shiptostreet2' => substr($use_registration_address_info |
|
250 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | - 'shiptocity' => substr($use_registration_address_info |
|
252 | - ? $attendee->city() |
|
253 | - : $billing_info['city'], 0, 40), |
|
254 | - 'state' => substr($use_registration_address_info |
|
255 | - ? $attendee->state_name() |
|
256 | - : $billing_info['state'], 0, 40), |
|
257 | - 'shiptocountry' => $use_registration_address_info |
|
258 | - ? $attendee->country_ID() |
|
259 | - : $billing_info['country'], |
|
260 | - 'shiptozip' => substr($use_registration_address_info |
|
261 | - ? $attendee->zip() |
|
262 | - : $billing_info['zip'], 0, 20), |
|
263 | - 'shiptophonenum' => substr($use_registration_address_info |
|
264 | - ? $attendee->phone() |
|
265 | - : $billing_info['phone'], 0, 20), |
|
266 | - ); |
|
267 | - $PaymentDetails = array( |
|
268 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | - 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | - // Required. Three-letter currency code. Default is USD. |
|
271 | - 'currencycode' => $payment->currency_code(), |
|
272 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | - // Subtotal of items not including S&H, or tax. |
|
274 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | - 'shippingamt' => '', |
|
277 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | - 'handlingamt' => '', |
|
279 | - // Required if you specify itemized cart tax details. |
|
280 | - // Sum of tax for all items on the order. Total sales tax. |
|
281 | - 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | - // Description of the order the customer is purchasing. 127 char max. |
|
283 | - 'desc' => $order_description, |
|
284 | - // Free-form field for your own use. 256 char max. |
|
285 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | - // Your own invoice or tracking number |
|
287 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | - 'notifyurl' => '', |
|
290 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | - ); |
|
292 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | - $PayPalRequestData = array( |
|
294 | - 'DPFields' => $DPFields, |
|
295 | - 'CCDetails' => $CCDetails, |
|
296 | - 'PayerInfo' => $PayerInfo, |
|
297 | - 'PayerName' => $PayerName, |
|
298 | - 'BillingAddress' => $BillingAddress, |
|
299 | - 'ShippingAddress' => $ShippingAddress, |
|
300 | - 'PaymentDetails' => $PaymentDetails, |
|
301 | - 'OrderItems' => $order_items, |
|
302 | - ); |
|
303 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | - try { |
|
305 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | - // remove PCI-sensitive data so it doesn't get stored |
|
307 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | - if(isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
309 | - $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
310 | - } elseif(isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
311 | - $message = $PayPalResult['L_LONGMESSAGE0']; |
|
312 | - } else { |
|
313 | - $message = $PayPalResult['ACK']; |
|
314 | - } |
|
315 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
316 | - $payment->set_status($this->_pay_model->failed_status()); |
|
317 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
318 | - $payment->set_details($PayPalResult); |
|
319 | - } else { |
|
320 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
321 | - $payment->set_status($this->_pay_model->approved_status()); |
|
322 | - } else { |
|
323 | - $payment->set_status($this->_pay_model->declined_status()); |
|
324 | - } |
|
325 | - // make sure we interpret the AMT as a float, not an international string |
|
326 | - // (where periods are thousand separators) |
|
327 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
328 | - $payment->set_gateway_response($message); |
|
329 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
330 | - ? $PayPalResult['TRANSACTIONID'] |
|
331 | - : null); |
|
332 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
333 | - ? $primary_registrant->reg_code() |
|
334 | - : ''; |
|
335 | - $payment->set_extra_accntng($primary_registration_code); |
|
336 | - $payment->set_details($PayPalResult); |
|
337 | - } |
|
338 | - } catch (Exception $e) { |
|
339 | - $payment->set_status($this->_pay_model->failed_status()); |
|
340 | - $payment->set_gateway_response($e->getMessage()); |
|
341 | - } |
|
342 | - // $payment->set_status( $this->_pay_model->declined_status() ); |
|
343 | - // $payment->set_gateway_response( '' ); |
|
344 | - return $payment; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
351 | - * |
|
352 | - * @param array $request |
|
353 | - * @param EEI_Payment $payment |
|
354 | - * @return void |
|
355 | - */ |
|
356 | - private function _log_clean_request($request, $payment) |
|
357 | - { |
|
358 | - $cleaned_request_data = $request; |
|
359 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
360 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
361 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
362 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Cleans the response, logs it, and returns it |
|
369 | - * |
|
370 | - * @param array $response |
|
371 | - * @param EEI_Payment $payment |
|
372 | - * @return array cleaned |
|
373 | - */ |
|
374 | - private function _log_clean_response($response, $payment) |
|
375 | - { |
|
376 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
377 | - unset($response['REQUESTDATA']['ACCT']); |
|
378 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
379 | - unset($response['REQUESTDATA']['CVV2']); |
|
380 | - unset($response['RAWREQUEST']); |
|
381 | - $this->log(array('Paypal Response' => $response), $payment); |
|
382 | - return $response; |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param $DataArray |
|
389 | - * @return array |
|
390 | - */ |
|
391 | - private function prep_and_curl_request($DataArray) |
|
392 | - { |
|
393 | - // Create empty holders for each portion of the NVP string |
|
394 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
395 | - $CCDetailsNVP = ''; |
|
396 | - $PayerInfoNVP = ''; |
|
397 | - $PayerNameNVP = ''; |
|
398 | - $BillingAddressNVP = ''; |
|
399 | - $ShippingAddressNVP = ''; |
|
400 | - $PaymentDetailsNVP = ''; |
|
401 | - $OrderItemsNVP = ''; |
|
402 | - $Secure3DNVP = ''; |
|
403 | - // DP Fields |
|
404 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
405 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
406 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
407 | - } |
|
408 | - // CC Details Fields |
|
409 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
410 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
411 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
412 | - } |
|
413 | - // PayerInfo Type Fields |
|
414 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
415 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
416 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
417 | - } |
|
418 | - // Payer Name Fields |
|
419 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
420 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
421 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
422 | - } |
|
423 | - // Address Fields (Billing) |
|
424 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
425 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
426 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
427 | - } |
|
428 | - // Payment Details Type Fields |
|
429 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
430 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
431 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
432 | - } |
|
433 | - // Payment Details Item Type Fields |
|
434 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
435 | - $n = 0; |
|
436 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
437 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
438 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
439 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
440 | - } |
|
441 | - $n++; |
|
442 | - } |
|
443 | - // Ship To Address Fields |
|
444 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
445 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
446 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
447 | - } |
|
448 | - // 3D Secure Fields |
|
449 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
450 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
451 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
452 | - } |
|
453 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
454 | - $NVPRequest = 'USER=' |
|
455 | - . $this->_username |
|
456 | - . '&PWD=' |
|
457 | - . $this->_password |
|
458 | - . '&VERSION=64.0' |
|
459 | - . '&SIGNATURE=' |
|
460 | - . $this->_signature |
|
461 | - . $DPFieldsNVP |
|
462 | - . $CCDetailsNVP |
|
463 | - . $PayerInfoNVP |
|
464 | - . $PayerNameNVP |
|
465 | - . $BillingAddressNVP |
|
466 | - . $PaymentDetailsNVP |
|
467 | - . $OrderItemsNVP |
|
468 | - . $ShippingAddressNVP |
|
469 | - . $Secure3DNVP; |
|
470 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
471 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
472 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
473 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
474 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
475 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
476 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
477 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
478 | - return $NVPResponseArray; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param $Request |
|
485 | - * @return mixed |
|
486 | - */ |
|
487 | - private function _CURLRequest($Request) |
|
488 | - { |
|
489 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
490 | - $curl = curl_init(); |
|
491 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
492 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
493 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
494 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
495 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
496 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
497 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
498 | - // execute the curl POST |
|
499 | - $Response = curl_exec($curl); |
|
500 | - curl_close($curl); |
|
501 | - return $Response; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * @param $NVPString |
|
508 | - * @return array |
|
509 | - */ |
|
510 | - private function _NVPToArray($NVPString) |
|
511 | - { |
|
512 | - // prepare responses into array |
|
513 | - $proArray = array(); |
|
514 | - while (strlen($NVPString)) { |
|
515 | - // name |
|
516 | - $keypos = strpos($NVPString, '='); |
|
517 | - $keyval = substr($NVPString, 0, $keypos); |
|
518 | - // value |
|
519 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
520 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
521 | - // decoding the response |
|
522 | - $proArray[ $keyval ] = urldecode($valval); |
|
523 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
524 | - } |
|
525 | - return $proArray; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @param array $PayPalResult |
|
532 | - * @return bool |
|
533 | - */ |
|
534 | - private function _APICallSuccessful($PayPalResult) |
|
535 | - { |
|
536 | - $approved = false; |
|
537 | - // check main response message from PayPal |
|
538 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
539 | - $ack = strtoupper($PayPalResult['ACK']); |
|
540 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
541 | - } |
|
542 | - return $approved; |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * @param $DataArray |
|
549 | - * @return array |
|
550 | - */ |
|
551 | - private function _GetErrors($DataArray) |
|
552 | - { |
|
553 | - $Errors = array(); |
|
554 | - $n = 0; |
|
555 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
556 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
557 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
558 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
559 | - : ''; |
|
560 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
561 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
562 | - : ''; |
|
563 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
564 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
565 | - : ''; |
|
566 | - $CurrentItem = array( |
|
567 | - 'L_ERRORCODE' => $LErrorCode, |
|
568 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
569 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
570 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
571 | - ); |
|
572 | - array_push($Errors, $CurrentItem); |
|
573 | - $n++; |
|
574 | - } |
|
575 | - return $Errors; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * nothing to see here... move along.... |
|
582 | - * |
|
583 | - * @access protected |
|
584 | - * @param $Errors |
|
585 | - * @return string |
|
586 | - */ |
|
587 | - private function _DisplayErrors($Errors) |
|
588 | - { |
|
589 | - $error = ''; |
|
590 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
591 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
592 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
593 | - $CurrentVarName = ''; |
|
594 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
595 | - $CurrentVarName = 'Error Code'; |
|
596 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
597 | - $CurrentVarName = 'Short Message'; |
|
598 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
599 | - $CurrentVarName = 'Long Message'; |
|
600 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
601 | - $CurrentVarName = 'Severity Code'; |
|
602 | - } |
|
603 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
604 | - } |
|
605 | - } |
|
606 | - return $error; |
|
607 | - } |
|
14 | + /** |
|
15 | + * @var $_paypal_api_username string |
|
16 | + */ |
|
17 | + protected $_username = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var $_password string |
|
21 | + */ |
|
22 | + protected $_password = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_signature string |
|
26 | + */ |
|
27 | + protected $_signature = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | + */ |
|
32 | + protected $_credit_card_types = null; |
|
33 | + |
|
34 | + protected $_currencies_supported = array( |
|
35 | + 'USD', |
|
36 | + 'GBP', |
|
37 | + 'CAD', |
|
38 | + 'AUD', |
|
39 | + 'BRL', |
|
40 | + 'CHF', |
|
41 | + 'CZK', |
|
42 | + 'DKK', |
|
43 | + 'EUR', |
|
44 | + 'HKD', |
|
45 | + 'HUF', |
|
46 | + 'ILS', |
|
47 | + 'JPY', |
|
48 | + 'MXN', |
|
49 | + 'MYR', |
|
50 | + 'NOK', |
|
51 | + 'NZD', |
|
52 | + 'PHP', |
|
53 | + 'PLN', |
|
54 | + 'SEK', |
|
55 | + 'SGD', |
|
56 | + 'THB', |
|
57 | + 'TRY', |
|
58 | + 'TWD', |
|
59 | + 'RUB', |
|
60 | + 'INR', |
|
61 | + ); |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EEI_Payment $payment |
|
67 | + * @param array $billing_info { |
|
68 | + * @type string $credit_card |
|
69 | + * @type string $credit_card_type |
|
70 | + * @type string $exp_month always 2 characters |
|
71 | + * @type string $exp_year always 4 characters |
|
72 | + * @type string $cvv |
|
73 | + * } |
|
74 | + * @see parent::do_direct_payment for more info |
|
75 | + * @return EE_Payment|EEI_Payment |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function do_direct_payment($payment, $billing_info = null) |
|
79 | + { |
|
80 | + $transaction = $payment->transaction(); |
|
81 | + if (! $transaction instanceof EEI_Transaction) { |
|
82 | + throw new EE_Error( |
|
83 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + $primary_registrant = $transaction->primary_registration(); |
|
87 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | + throw new EE_Error( |
|
89 | + esc_html__( |
|
90 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | + 'event_espresso' |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + $attendee = $primary_registrant->attendee(); |
|
96 | + if (! $attendee instanceof EEI_Attendee) { |
|
97 | + throw new EE_Error( |
|
98 | + esc_html__( |
|
99 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | + 'event_espresso' |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | + $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | + // charge for the full amount. Show itemized list |
|
107 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | + $item_num = 1; |
|
109 | + $total_line_item = $transaction->total_line_item(); |
|
110 | + $order_items = array(); |
|
111 | + foreach ($total_line_item->get_items() as $line_item) { |
|
112 | + // ignore line items with a quantity of 0 |
|
113 | + if ($line_item->quantity() == 0) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + $item = array( |
|
117 | + // Item Name. 127 char max. |
|
118 | + 'l_name' => substr( |
|
119 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | + 0, |
|
121 | + 127 |
|
122 | + ), |
|
123 | + // Item description. 127 char max. |
|
124 | + 'l_desc' => substr( |
|
125 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | + 0, |
|
127 | + 127 |
|
128 | + ), |
|
129 | + // Cost of individual item. |
|
130 | + 'l_amt' => $line_item->unit_price(), |
|
131 | + // Item Number. 127 char max. |
|
132 | + 'l_number' => $item_num++, |
|
133 | + // Item quantity. Must be any positive integer. |
|
134 | + 'l_qty' => $line_item->quantity(), |
|
135 | + // Item's sales tax amount. |
|
136 | + 'l_taxamt' => '', |
|
137 | + // eBay auction number of item. |
|
138 | + 'l_ebayitemnumber' => '', |
|
139 | + // eBay transaction ID of purchased item. |
|
140 | + 'l_ebayitemauctiontxnid' => '', |
|
141 | + // eBay order ID for the item. |
|
142 | + 'l_ebayitemorderid' => '', |
|
143 | + ); |
|
144 | + // add to array of all items |
|
145 | + array_push($order_items, $item); |
|
146 | + } |
|
147 | + $item_amount = $total_line_item->get_items_total(); |
|
148 | + $tax_amount = $total_line_item->get_total_tax(); |
|
149 | + } else { |
|
150 | + $order_items = array(); |
|
151 | + $item_amount = $payment->amount(); |
|
152 | + $tax_amount = 0; |
|
153 | + array_push($order_items, array( |
|
154 | + // Item Name. 127 char max. |
|
155 | + 'l_name' => substr( |
|
156 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | + 0, |
|
158 | + 127 |
|
159 | + ), |
|
160 | + // Item description. 127 char max. |
|
161 | + 'l_desc' => substr( |
|
162 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | + 0, |
|
164 | + 127 |
|
165 | + ), |
|
166 | + // Cost of individual item. |
|
167 | + 'l_amt' => $payment->amount(), |
|
168 | + // Item Number. 127 char max. |
|
169 | + 'l_number' => 1, |
|
170 | + // Item quantity. Must be any positive integer. |
|
171 | + 'l_qty' => 1, |
|
172 | + )); |
|
173 | + } |
|
174 | + // Populate data arrays with order data. |
|
175 | + $DPFields = array( |
|
176 | + // How you want to obtain payment ? |
|
177 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | + 'paymentaction' => 'Sale', |
|
180 | + // Required. IP address of the payer's browser. |
|
181 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | + 'returnfmfdetails' => '1', |
|
184 | + ); |
|
185 | + $CCDetails = array( |
|
186 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | + // If Maestro or Solo, the currency code must be GBP. |
|
188 | + // In addition, either start date or issue number must be specified. |
|
189 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | + // Required. Credit card number. No spaces or punctuation. |
|
191 | + 'acct' => $billing_info['credit_card'], |
|
192 | + // Required. Credit card expiration date. Format is MMYYYY |
|
193 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | + 'cvv2' => $billing_info['cvv'], |
|
196 | + ); |
|
197 | + $PayerInfo = array( |
|
198 | + // Email address of payer. |
|
199 | + 'email' => $billing_info['email'], |
|
200 | + // Unique PayPal customer ID for payer. |
|
201 | + 'payerid' => '', |
|
202 | + // Status of payer. Values are verified or unverified |
|
203 | + 'payerstatus' => '', |
|
204 | + // Payer's business name. |
|
205 | + 'business' => '', |
|
206 | + ); |
|
207 | + $PayerName = array( |
|
208 | + // Payer's salutation. 20 char max. |
|
209 | + 'salutation' => '', |
|
210 | + // Payer's first name. 25 char max. |
|
211 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | + // Payer's middle name. 25 char max. |
|
213 | + 'middlename' => '', |
|
214 | + // Payer's last name. 25 char max. |
|
215 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | + // Payer's suffix. 12 char max. |
|
217 | + 'suffix' => '', |
|
218 | + ); |
|
219 | + $BillingAddress = array( |
|
220 | + // Required. First street address. |
|
221 | + 'street' => $billing_info['address'], |
|
222 | + // Second street address. |
|
223 | + 'street2' => $billing_info['address2'], |
|
224 | + // Required. Name of City. |
|
225 | + 'city' => $billing_info['city'], |
|
226 | + // Required. Name of State or Province. |
|
227 | + 'state' => substr($billing_info['state'], 0, 40), |
|
228 | + // Required. Country code. |
|
229 | + 'countrycode' => $billing_info['country'], |
|
230 | + // Required. Postal code of payer. |
|
231 | + 'zip' => $billing_info['zip'], |
|
232 | + ); |
|
233 | + // check if the registration info contains the needed fields for paypal pro |
|
234 | + // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | + $use_registration_address_info = true; |
|
237 | + } else { |
|
238 | + $use_registration_address_info = false; |
|
239 | + } |
|
240 | + // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | + // If not, use the billing info again |
|
242 | + $ShippingAddress = array( |
|
243 | + 'shiptoname' => substr($use_registration_address_info |
|
244 | + ? $attendee->full_name() |
|
245 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | + 'shiptostreet' => substr($use_registration_address_info |
|
247 | + ? $attendee->address() |
|
248 | + : $billing_info['address'], 0, 100), |
|
249 | + 'shiptostreet2' => substr($use_registration_address_info |
|
250 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | + 'shiptocity' => substr($use_registration_address_info |
|
252 | + ? $attendee->city() |
|
253 | + : $billing_info['city'], 0, 40), |
|
254 | + 'state' => substr($use_registration_address_info |
|
255 | + ? $attendee->state_name() |
|
256 | + : $billing_info['state'], 0, 40), |
|
257 | + 'shiptocountry' => $use_registration_address_info |
|
258 | + ? $attendee->country_ID() |
|
259 | + : $billing_info['country'], |
|
260 | + 'shiptozip' => substr($use_registration_address_info |
|
261 | + ? $attendee->zip() |
|
262 | + : $billing_info['zip'], 0, 20), |
|
263 | + 'shiptophonenum' => substr($use_registration_address_info |
|
264 | + ? $attendee->phone() |
|
265 | + : $billing_info['phone'], 0, 20), |
|
266 | + ); |
|
267 | + $PaymentDetails = array( |
|
268 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | + 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | + // Required. Three-letter currency code. Default is USD. |
|
271 | + 'currencycode' => $payment->currency_code(), |
|
272 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | + // Subtotal of items not including S&H, or tax. |
|
274 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | + 'shippingamt' => '', |
|
277 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | + 'handlingamt' => '', |
|
279 | + // Required if you specify itemized cart tax details. |
|
280 | + // Sum of tax for all items on the order. Total sales tax. |
|
281 | + 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | + // Description of the order the customer is purchasing. 127 char max. |
|
283 | + 'desc' => $order_description, |
|
284 | + // Free-form field for your own use. 256 char max. |
|
285 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | + // Your own invoice or tracking number |
|
287 | + 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | + 'notifyurl' => '', |
|
290 | + 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | + ); |
|
292 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | + $PayPalRequestData = array( |
|
294 | + 'DPFields' => $DPFields, |
|
295 | + 'CCDetails' => $CCDetails, |
|
296 | + 'PayerInfo' => $PayerInfo, |
|
297 | + 'PayerName' => $PayerName, |
|
298 | + 'BillingAddress' => $BillingAddress, |
|
299 | + 'ShippingAddress' => $ShippingAddress, |
|
300 | + 'PaymentDetails' => $PaymentDetails, |
|
301 | + 'OrderItems' => $order_items, |
|
302 | + ); |
|
303 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | + try { |
|
305 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | + // remove PCI-sensitive data so it doesn't get stored |
|
307 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | + if(isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
309 | + $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
310 | + } elseif(isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
311 | + $message = $PayPalResult['L_LONGMESSAGE0']; |
|
312 | + } else { |
|
313 | + $message = $PayPalResult['ACK']; |
|
314 | + } |
|
315 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
316 | + $payment->set_status($this->_pay_model->failed_status()); |
|
317 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
318 | + $payment->set_details($PayPalResult); |
|
319 | + } else { |
|
320 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
321 | + $payment->set_status($this->_pay_model->approved_status()); |
|
322 | + } else { |
|
323 | + $payment->set_status($this->_pay_model->declined_status()); |
|
324 | + } |
|
325 | + // make sure we interpret the AMT as a float, not an international string |
|
326 | + // (where periods are thousand separators) |
|
327 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
328 | + $payment->set_gateway_response($message); |
|
329 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
330 | + ? $PayPalResult['TRANSACTIONID'] |
|
331 | + : null); |
|
332 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
333 | + ? $primary_registrant->reg_code() |
|
334 | + : ''; |
|
335 | + $payment->set_extra_accntng($primary_registration_code); |
|
336 | + $payment->set_details($PayPalResult); |
|
337 | + } |
|
338 | + } catch (Exception $e) { |
|
339 | + $payment->set_status($this->_pay_model->failed_status()); |
|
340 | + $payment->set_gateway_response($e->getMessage()); |
|
341 | + } |
|
342 | + // $payment->set_status( $this->_pay_model->declined_status() ); |
|
343 | + // $payment->set_gateway_response( '' ); |
|
344 | + return $payment; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
351 | + * |
|
352 | + * @param array $request |
|
353 | + * @param EEI_Payment $payment |
|
354 | + * @return void |
|
355 | + */ |
|
356 | + private function _log_clean_request($request, $payment) |
|
357 | + { |
|
358 | + $cleaned_request_data = $request; |
|
359 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
360 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
361 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
362 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Cleans the response, logs it, and returns it |
|
369 | + * |
|
370 | + * @param array $response |
|
371 | + * @param EEI_Payment $payment |
|
372 | + * @return array cleaned |
|
373 | + */ |
|
374 | + private function _log_clean_response($response, $payment) |
|
375 | + { |
|
376 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
377 | + unset($response['REQUESTDATA']['ACCT']); |
|
378 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
379 | + unset($response['REQUESTDATA']['CVV2']); |
|
380 | + unset($response['RAWREQUEST']); |
|
381 | + $this->log(array('Paypal Response' => $response), $payment); |
|
382 | + return $response; |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param $DataArray |
|
389 | + * @return array |
|
390 | + */ |
|
391 | + private function prep_and_curl_request($DataArray) |
|
392 | + { |
|
393 | + // Create empty holders for each portion of the NVP string |
|
394 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
395 | + $CCDetailsNVP = ''; |
|
396 | + $PayerInfoNVP = ''; |
|
397 | + $PayerNameNVP = ''; |
|
398 | + $BillingAddressNVP = ''; |
|
399 | + $ShippingAddressNVP = ''; |
|
400 | + $PaymentDetailsNVP = ''; |
|
401 | + $OrderItemsNVP = ''; |
|
402 | + $Secure3DNVP = ''; |
|
403 | + // DP Fields |
|
404 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
405 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
406 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
407 | + } |
|
408 | + // CC Details Fields |
|
409 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
410 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
411 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
412 | + } |
|
413 | + // PayerInfo Type Fields |
|
414 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
415 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
416 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
417 | + } |
|
418 | + // Payer Name Fields |
|
419 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
420 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
421 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
422 | + } |
|
423 | + // Address Fields (Billing) |
|
424 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
425 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
426 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
427 | + } |
|
428 | + // Payment Details Type Fields |
|
429 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
430 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
431 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
432 | + } |
|
433 | + // Payment Details Item Type Fields |
|
434 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
435 | + $n = 0; |
|
436 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
437 | + $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
438 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
439 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
440 | + } |
|
441 | + $n++; |
|
442 | + } |
|
443 | + // Ship To Address Fields |
|
444 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
445 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
446 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
447 | + } |
|
448 | + // 3D Secure Fields |
|
449 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
450 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
451 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
452 | + } |
|
453 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
454 | + $NVPRequest = 'USER=' |
|
455 | + . $this->_username |
|
456 | + . '&PWD=' |
|
457 | + . $this->_password |
|
458 | + . '&VERSION=64.0' |
|
459 | + . '&SIGNATURE=' |
|
460 | + . $this->_signature |
|
461 | + . $DPFieldsNVP |
|
462 | + . $CCDetailsNVP |
|
463 | + . $PayerInfoNVP |
|
464 | + . $PayerNameNVP |
|
465 | + . $BillingAddressNVP |
|
466 | + . $PaymentDetailsNVP |
|
467 | + . $OrderItemsNVP |
|
468 | + . $ShippingAddressNVP |
|
469 | + . $Secure3DNVP; |
|
470 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
471 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
472 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
473 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
474 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
475 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
476 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
477 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
478 | + return $NVPResponseArray; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param $Request |
|
485 | + * @return mixed |
|
486 | + */ |
|
487 | + private function _CURLRequest($Request) |
|
488 | + { |
|
489 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
490 | + $curl = curl_init(); |
|
491 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
492 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
493 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
494 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
495 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
496 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
497 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
498 | + // execute the curl POST |
|
499 | + $Response = curl_exec($curl); |
|
500 | + curl_close($curl); |
|
501 | + return $Response; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * @param $NVPString |
|
508 | + * @return array |
|
509 | + */ |
|
510 | + private function _NVPToArray($NVPString) |
|
511 | + { |
|
512 | + // prepare responses into array |
|
513 | + $proArray = array(); |
|
514 | + while (strlen($NVPString)) { |
|
515 | + // name |
|
516 | + $keypos = strpos($NVPString, '='); |
|
517 | + $keyval = substr($NVPString, 0, $keypos); |
|
518 | + // value |
|
519 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
520 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
521 | + // decoding the response |
|
522 | + $proArray[ $keyval ] = urldecode($valval); |
|
523 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
524 | + } |
|
525 | + return $proArray; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @param array $PayPalResult |
|
532 | + * @return bool |
|
533 | + */ |
|
534 | + private function _APICallSuccessful($PayPalResult) |
|
535 | + { |
|
536 | + $approved = false; |
|
537 | + // check main response message from PayPal |
|
538 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
539 | + $ack = strtoupper($PayPalResult['ACK']); |
|
540 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
541 | + } |
|
542 | + return $approved; |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * @param $DataArray |
|
549 | + * @return array |
|
550 | + */ |
|
551 | + private function _GetErrors($DataArray) |
|
552 | + { |
|
553 | + $Errors = array(); |
|
554 | + $n = 0; |
|
555 | + while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
556 | + $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
557 | + $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
558 | + ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
559 | + : ''; |
|
560 | + $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
561 | + ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
562 | + : ''; |
|
563 | + $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
564 | + ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
565 | + : ''; |
|
566 | + $CurrentItem = array( |
|
567 | + 'L_ERRORCODE' => $LErrorCode, |
|
568 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
569 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
570 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
571 | + ); |
|
572 | + array_push($Errors, $CurrentItem); |
|
573 | + $n++; |
|
574 | + } |
|
575 | + return $Errors; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * nothing to see here... move along.... |
|
582 | + * |
|
583 | + * @access protected |
|
584 | + * @param $Errors |
|
585 | + * @return string |
|
586 | + */ |
|
587 | + private function _DisplayErrors($Errors) |
|
588 | + { |
|
589 | + $error = ''; |
|
590 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
591 | + $CurrentError = $Errors[ $ErrorVar ]; |
|
592 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
593 | + $CurrentVarName = ''; |
|
594 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
595 | + $CurrentVarName = 'Error Code'; |
|
596 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
597 | + $CurrentVarName = 'Short Message'; |
|
598 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
599 | + $CurrentVarName = 'Long Message'; |
|
600 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
601 | + $CurrentVarName = 'Severity Code'; |
|
602 | + } |
|
603 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
604 | + } |
|
605 | + } |
|
606 | + return $error; |
|
607 | + } |
|
608 | 608 | } |
@@ -78,13 +78,13 @@ discard block |
||
78 | 78 | public function do_direct_payment($payment, $billing_info = null) |
79 | 79 | { |
80 | 80 | $transaction = $payment->transaction(); |
81 | - if (! $transaction instanceof EEI_Transaction) { |
|
81 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
82 | 82 | throw new EE_Error( |
83 | 83 | esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
84 | 84 | ); |
85 | 85 | } |
86 | 86 | $primary_registrant = $transaction->primary_registration(); |
87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
87 | + if ( ! $primary_registrant instanceof EEI_Registration) { |
|
88 | 88 | throw new EE_Error( |
89 | 89 | esc_html__( |
90 | 90 | 'No primary registration on transaction while paying with PayPal Pro.', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ); |
94 | 94 | } |
95 | 95 | $attendee = $primary_registrant->attendee(); |
96 | - if (! $attendee instanceof EEI_Attendee) { |
|
96 | + if ( ! $attendee instanceof EEI_Attendee) { |
|
97 | 97 | throw new EE_Error( |
98 | 98 | esc_html__( |
99 | 99 | 'No attendee on primary registration while paying with PayPal Pro.', |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | // Required. Credit card number. No spaces or punctuation. |
191 | 191 | 'acct' => $billing_info['credit_card'], |
192 | 192 | // Required. Credit card expiration date. Format is MMYYYY |
193 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
193 | + 'expdate' => $billing_info['exp_month'].$billing_info['exp_year'], |
|
194 | 194 | // Requirements determined by your PayPal account settings. Security digits for credit card. |
195 | 195 | 'cvv2' => $billing_info['cvv'], |
196 | 196 | ); |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | $ShippingAddress = array( |
243 | 243 | 'shiptoname' => substr($use_registration_address_info |
244 | 244 | ? $attendee->full_name() |
245 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
245 | + : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32), |
|
246 | 246 | 'shiptostreet' => substr($use_registration_address_info |
247 | 247 | ? $attendee->address() |
248 | 248 | : $billing_info['address'], 0, 100), |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | 'currencycode' => $payment->currency_code(), |
272 | 272 | // Required if you include itemized cart details. (L_AMTn, etc.) |
273 | 273 | // Subtotal of items not including S&H, or tax. |
274 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
274 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount), // |
|
275 | 275 | // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
276 | 276 | 'shippingamt' => '', |
277 | 277 | // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | // Free-form field for your own use. 256 char max. |
285 | 285 | 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
286 | 286 | // Your own invoice or tracking number |
287 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
287 | + 'invnum' => wp_generate_password(12, false), // $transaction->ID(), |
|
288 | 288 | // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
289 | 289 | 'notifyurl' => '', |
290 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
290 | + 'buttonsource' => 'EventEspresso_SP', // EE will blow up if you change this |
|
291 | 291 | ); |
292 | 292 | // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
293 | 293 | $PayPalRequestData = array( |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
306 | 306 | // remove PCI-sensitive data so it doesn't get stored |
307 | 307 | $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
308 | - if(isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
308 | + if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
309 | 309 | $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
310 | - } elseif(isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
310 | + } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
311 | 311 | $message = $PayPalResult['L_LONGMESSAGE0']; |
312 | 312 | } else { |
313 | 313 | $message = $PayPalResult['ACK']; |
@@ -403,52 +403,52 @@ discard block |
||
403 | 403 | // DP Fields |
404 | 404 | $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
405 | 405 | foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
406 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
406 | + $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal); |
|
407 | 407 | } |
408 | 408 | // CC Details Fields |
409 | 409 | $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
410 | 410 | foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
411 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
411 | + $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal); |
|
412 | 412 | } |
413 | 413 | // PayerInfo Type Fields |
414 | 414 | $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
415 | 415 | foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
416 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
416 | + $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal); |
|
417 | 417 | } |
418 | 418 | // Payer Name Fields |
419 | 419 | $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
420 | 420 | foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
421 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
421 | + $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal); |
|
422 | 422 | } |
423 | 423 | // Address Fields (Billing) |
424 | 424 | $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
425 | 425 | foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
426 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
426 | + $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal); |
|
427 | 427 | } |
428 | 428 | // Payment Details Type Fields |
429 | 429 | $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
430 | 430 | foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
431 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
431 | + $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal); |
|
432 | 432 | } |
433 | 433 | // Payment Details Item Type Fields |
434 | 434 | $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
435 | 435 | $n = 0; |
436 | 436 | foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
437 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
437 | + $CurrentItem = $OrderItems[$OrderItemsVar]; |
|
438 | 438 | foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
439 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
439 | + $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal); |
|
440 | 440 | } |
441 | 441 | $n++; |
442 | 442 | } |
443 | 443 | // Ship To Address Fields |
444 | 444 | $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
445 | 445 | foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
446 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
446 | + $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal); |
|
447 | 447 | } |
448 | 448 | // 3D Secure Fields |
449 | 449 | $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
450 | 450 | foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
451 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
451 | + $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal); |
|
452 | 452 | } |
453 | 453 | // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
454 | 454 | $NVPRequest = 'USER=' |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
520 | 520 | $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
521 | 521 | // decoding the response |
522 | - $proArray[ $keyval ] = urldecode($valval); |
|
522 | + $proArray[$keyval] = urldecode($valval); |
|
523 | 523 | $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
524 | 524 | } |
525 | 525 | return $proArray; |
@@ -552,16 +552,16 @@ discard block |
||
552 | 552 | { |
553 | 553 | $Errors = array(); |
554 | 554 | $n = 0; |
555 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
556 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
557 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
558 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
555 | + while (isset($DataArray['L_ERRORCODE'.$n.''])) { |
|
556 | + $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : ''; |
|
557 | + $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.'']) |
|
558 | + ? $DataArray['L_SHORTMESSAGE'.$n.''] |
|
559 | 559 | : ''; |
560 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
561 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
560 | + $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.'']) |
|
561 | + ? $DataArray['L_LONGMESSAGE'.$n.''] |
|
562 | 562 | : ''; |
563 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
564 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
563 | + $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.'']) |
|
564 | + ? $DataArray['L_SEVERITYCODE'.$n.''] |
|
565 | 565 | : ''; |
566 | 566 | $CurrentItem = array( |
567 | 567 | 'L_ERRORCODE' => $LErrorCode, |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | { |
589 | 589 | $error = ''; |
590 | 590 | foreach ($Errors as $ErrorVar => $ErrorVal) { |
591 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
591 | + $CurrentError = $Errors[$ErrorVar]; |
|
592 | 592 | foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
593 | 593 | $CurrentVarName = ''; |
594 | 594 | if ($CurrentErrorVar == 'L_ERRORCODE') { |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
601 | 601 | $CurrentVarName = 'Severity Code'; |
602 | 602 | } |
603 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
603 | + $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal; |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | return $error; |