Skip to content

Commit 129572c

Browse files
authored
PFW-1939 - Fix onboarding fatal error; add retry logic and SSL error handling (#2107)
* PFW-1939 - Fix onboarding fatal error; add retry logic and SSL error handling * PFW-1939 - Fixed the typed variable initialization error
1 parent dfae6f9 commit 129572c

File tree

2 files changed

+64
-33
lines changed

2 files changed

+64
-33
lines changed

ppcp-gateway/class-angelleye-paypal-ppcp-request.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class AngellEYE_PayPal_PPCP_Request {
4848
public $api_password;
4949
public $api_signature;
5050
public $Force_tls_one_point_two;
51+
private bool $ignore_ssl_in_request = false;
5152

5253
public static function instance() {
5354
if (is_null(self::$_instance)) {
@@ -128,7 +129,23 @@ public function angelleye_get_settings() {
128129
}
129130
}
130131

131-
public function angelleye_ppcp_remote_get($paypal_url, $args, $action_name) {
132+
function is_ssl_error($message) {
133+
$ssl_errors = [
134+
'ssl', 'SSL', 'SSL routines', 'sslv3', 'tlsv1', 'tls', 'cURL error 60',
135+
'certificate', 'handshake failure', 'unable to get local issuer certificate',
136+
'Peer’s Certificate', 'secure connection', 'unable to verify',
137+
'SSL23_GET_SERVER_HELLO', 'EPROTO', 'curl: (35)'
138+
];
139+
140+
foreach ($ssl_errors as $pattern) {
141+
if (stripos($message, $pattern) !== false) {
142+
return true;
143+
}
144+
}
145+
return false;
146+
}
147+
148+
public function angelleye_ppcp_remote_get($paypal_url, $args, $action_name, $retry = 1) {
132149
$body['testmode'] = ($this->is_sandbox) ? 'yes' : 'no';
133150
$body['meta'] = [
134151
'plugin_version' => VERSION_PFW,
@@ -154,11 +171,22 @@ public function angelleye_ppcp_remote_get($paypal_url, $args, $action_name) {
154171
}
155172
}
156173
$args['headers']['plugin_version_id'] = VERSION_PFW;
174+
if ($this->ignore_ssl_in_request === true) {
175+
$args['sslverify'] = false;
176+
}
157177
if ('generate_id_token' === $action_name) {
158178
$this->result = wp_remote_get($this->ppcp_host . 'generate-id-token', $args);
159179
} else {
160180
$this->result = wp_remote_get($this->ppcp_host . 'ppcp-request', $args);
161181
}
182+
// Handle SSL handshake errors:
183+
// write EPROTO 140377683838912:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/record/rec_layer_s3.c:1564:SSL alert number 40
184+
if (is_wp_error($this->result) && $retry < 2) {
185+
if ($this->is_ssl_error($this->result)) {
186+
$this->ignore_ssl_in_request = true;
187+
}
188+
return $this->angelleye_ppcp_remote_get($paypal_url, $args, $action_name, ++$retry);
189+
}
162190
return $this->result;
163191
}
164192

ppcp-gateway/class-angelleye-paypal-ppcp-seller-onboarding.php

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ public function angelleye_ppcp_multi_account_generate_signup_link($post_id) {
153153
'testmode' => $testmode,
154154
'return_url' => add_query_arg(array('testmode' => $testmode, 'post_id' => $post_id), WC()->api_request_url('AngellEYE_PayPal_PPCP_Seller_Onboarding')),
155155
'return_url_description' => __(
156-
'Return to your shop.', 'paypal-for-woocommerce'
156+
'Return to your shop.', 'paypal-for-woocommerce'
157157
),
158158
'products' => array(
159159
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
160-
));
160+
));
161161
$host_url = $this->ppcp_host . 'generate-signup-link';
162162
$args = array(
163163
'method' => 'POST',
@@ -220,14 +220,14 @@ private function default_data() {
220220
$default_data = array(
221221
'testmode' => $testmode,
222222
'return_url' => admin_url(
223-
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&testmode=' . $testmode
223+
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&testmode=' . $testmode
224224
),
225225
'return_url_description' => __(
226-
'Return to your shop.', 'paypal-for-woocommerce'
226+
'Return to your shop.', 'paypal-for-woocommerce'
227227
),
228228
'products' => array(
229229
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT'
230-
));
230+
));
231231
$country = $this->dcc_applies->country();
232232
if (!empty($country)) {
233233
if (in_array($this->dcc_applies->country(), $this->dcc_applies->apple_google_vault_supported_country)) {
@@ -249,10 +249,10 @@ public function ppcp_apple_pay_data() {
249249
return array(
250250
'testmode' => $testmode,
251251
'return_url' => admin_url(
252-
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&feature_activated=applepay&testmode=' . $testmode
252+
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&feature_activated=applepay&testmode=' . $testmode
253253
),
254254
'return_url_description' => __(
255-
'Return to your shop.', 'paypal-for-woocommerce'
255+
'Return to your shop.', 'paypal-for-woocommerce'
256256
),
257257
'capabilities' => array(
258258
'APPLE_PAY'
@@ -261,18 +261,18 @@ public function ppcp_apple_pay_data() {
261261
'products' => array(
262262
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
263263
'PAYMENT_METHODS'
264-
));
264+
));
265265
}
266266

267267
public function ppcp_google_pay_data() {
268268
$testmode = ($this->is_sandbox) ? 'yes' : 'no';
269269
return array(
270270
'testmode' => $testmode,
271271
'return_url' => admin_url(
272-
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&feature_activated=googlepay&testmode=' . $testmode
272+
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&feature_activated=googlepay&testmode=' . $testmode
273273
),
274274
'return_url_description' => __(
275-
'Return to your shop.', 'paypal-for-woocommerce'
275+
'Return to your shop.', 'paypal-for-woocommerce'
276276
),
277277
'capabilities' => array(
278278
'GOOGLE_PAY'
@@ -281,18 +281,18 @@ public function ppcp_google_pay_data() {
281281
'products' => array(
282282
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
283283
'PAYMENT_METHODS'
284-
));
284+
));
285285
}
286286

287287
public function ppcp_vault_data() {
288288
$testmode = ($this->is_sandbox) ? 'yes' : 'no';
289289
return array(
290290
'testmode' => $testmode,
291291
'return_url' => admin_url(
292-
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&testmode=' . $testmode
292+
'admin.php?page=wc-settings&tab=checkout&section=angelleye_ppcp&testmode=' . $testmode
293293
),
294294
'return_url_description' => __(
295-
'Return to your shop.', 'paypal-for-woocommerce'
295+
'Return to your shop.', 'paypal-for-woocommerce'
296296
),
297297
'capabilities' => array(
298298
'PAYPAL_WALLET_VAULTING_ADVANCED'
@@ -301,7 +301,7 @@ public function ppcp_vault_data() {
301301
'products' => array(
302302
$this->dcc_applies->for_country_currency() ? 'PPCP' : 'EXPRESS_CHECKOUT',
303303
'ADVANCED_VAULTING'
304-
));
304+
));
305305
}
306306

307307
public function angelleye_ppcp_login_seller() {
@@ -590,6 +590,9 @@ public function angelleye_get_seller_onboarding_status() {
590590
);
591591
$host_url = $this->ppcp_host . 'get-tracking-status';
592592
$seller_onboarding_status = $this->api_request->request($host_url, $args, 'get_tracking_status');
593+
if (!is_array($seller_onboarding_status)) {
594+
throw new Exception('Unable to retrieve the account status, please refresh to try again.');
595+
}
593596
if (!isset($seller_onboarding_status['merchant_id'])) {
594597
$seller_onboarding_status['merchant_id'] = sanitize_text_field(wp_unslash($_GET['merchantIdInPayPal']));
595598
}
@@ -667,8 +670,8 @@ public function angelleye_track_seller_onboarding_status_from_cache($merchant_id
667670
try {
668671
$this->api_request = new AngellEYE_PayPal_PPCP_Request();
669672
$url = trailingslashit($this->host) .
670-
'v1/customer/partners/' . $partner_merchant_id .
671-
'/merchant-integrations/' . $merchant_id;
673+
'v1/customer/partners/' . $partner_merchant_id .
674+
'/merchant-integrations/' . $merchant_id;
672675
$args = array(
673676
'method' => 'GET',
674677
'headers' => array(
@@ -760,22 +763,22 @@ public function angelleye_ppcp_onboard_email_sendy_subscription() {
760763
}
761764
$url = 'https://sendy.angelleye.com/subscribe';
762765
$response = wp_remote_post($url, array(
763-
'method' => 'POST',
764-
'timeout' => 45,
765-
'redirection' => 5,
766-
'httpversion' => '1.0',
767-
'blocking' => true,
768-
'headers' => array(),
769-
'body' => array('list' => 'oV0I12rDwJdMDL2jYzvwPQ',
770-
'boolean' => 'true',
771-
'email' => $_POST['email'],
772-
'gdpr' => 'true',
773-
'silent' => 'true',
774-
'api_key' => 'qFcoVlU2uG3AMYabNTrC',
775-
'referrer' => $current_url
776-
),
777-
'cookies' => array()
778-
)
766+
'method' => 'POST',
767+
'timeout' => 45,
768+
'redirection' => 5,
769+
'httpversion' => '1.0',
770+
'blocking' => true,
771+
'headers' => array(),
772+
'body' => array('list' => 'oV0I12rDwJdMDL2jYzvwPQ',
773+
'boolean' => 'true',
774+
'email' => $_POST['email'],
775+
'gdpr' => 'true',
776+
'silent' => 'true',
777+
'api_key' => 'qFcoVlU2uG3AMYabNTrC',
778+
'referrer' => $current_url
779+
),
780+
'cookies' => array()
781+
)
779782
);
780783
if (is_wp_error($response)) {
781784
wp_send_json(wp_remote_retrieve_body($response));

0 commit comments

Comments
 (0)