Skip to content

Commit 57bfcd9

Browse files
author
Samuel Kmita
committed
2.2.3
1 parent de99cea commit 57bfcd9

35 files changed

Lines changed: 969 additions & 627 deletions

.DS_Store

8 KB
Binary file not shown.

Gateway/Base.php

Lines changed: 104 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function __construct()
7171
'subscription_payment_method_change',
7272
);
7373

74-
7574
$this->first_name = '';
7675
$this->last_name = '';
7776

@@ -88,13 +87,13 @@ public function __construct()
8887
$this->init_settings();
8988
$this->paylane_settings = get_option('woocommerce_paylane_settings');
9089

91-
$this->method_title = 'PayLane: ' . $this->getMethodTitle();
90+
$this->method_title = 'Polskie ePłatności: ' . $this->getMethodTitle();
9291
$this->description = $this->get_paylane_option('description');
9392
$this->payment_method = $this->get_paylane_option('payment_method');
9493
$this->secure_form = $this->get_paylane_option('secure_form');
9594
$this->merchant_id = $this->get_paylane_option('merchant_id');
9695
$this->fraud_check = $this->get_paylane_option('fraud_check');
97-
$this->ds_check = $this->get_paylane_option('3ds_check');
96+
$this->ds_check = 'true';//$this->get_paylane_option('3ds_check');
9897
$this->enable_notification = $this->get_paylane_option('notifications_enabled');
9998
$this->design = $this->get_paylane_option('design', 'basic');
10099
$this->title = $this->getMethodTitle();
@@ -103,6 +102,10 @@ public function __construct()
103102
$this->enabled = $this->get_paylane_option($this->form_name . '_legacy_enabled', 'no');
104103
}
105104

105+
// add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
106+
// add_action('admin_init', array($this, 'handle_subscriptions_hooks'));
107+
$this->handle_subscriptions_hooks();
108+
106109
}
107110

108111
/**
@@ -140,15 +143,16 @@ protected function getGatewayTitle()
140143
return get_called_class();
141144
}
142145

143-
protected function modTitle($org, $custom, $disableSufix = false){
146+
protected function modTitle($org, $custom, $disableSufix = false)
147+
{
144148
$org = trim($org);
145149
$custom = trim($custom);
146-
if(is_null($custom) || empty($custom) || $org == $custom){
150+
if (is_null($custom) || empty($custom) || $org == $custom) {
147151
$sufix = '';
148-
if(!$disableSufix){
149-
$sufix = ' (PayLane)';
150-
}
151-
return $org.$sufix;
152+
// if (!$disableSufix) {
153+
// $sufix = ' (Polskie ePłatności)';
154+
// }
155+
return $org . $sufix;
152156
}
153157

154158
return $custom;
@@ -176,19 +180,19 @@ public function woocommerce_version_check($version = '3.0')
176180
*/
177181
public function get_icon()
178182
{
179-
$iconUrl = plugins_url('../assets/paylane.png', __FILE__);
183+
$iconUrl = plugins_url('../assets/pep.svg', __FILE__);
180184
$iconHtml = '';
181-
if ($this->get_paylane_option('display_payment_methods_logo','yes') == 'yes') {
185+
if ($this->get_paylane_option('display_payment_methods_logo', 'yes') == 'yes') {
182186
$iconHtml .= '<img src="' . $iconUrl . '" class="paylane-payment-method-label-logo" alt="' . esc_attr__(
183-
'PayLane image', 'woocommerce'
187+
'Polskie ePłatności image', 'woocommerce'
184188
) . '">';
185189
}
186190

187191
return apply_filters('woocommerce_gateway_icon', $iconHtml, $this->id);
188192
}
189193

190194
/**
191-
* Show PayLane methods fields at checkout
195+
* Show Polskie ePłatności methods fields at checkout
192196
*/
193197
public function payment_fields()
194198
{
@@ -241,21 +245,26 @@ public function process_payment($order_id)
241245

242246
if (!$method) {
243247
wc_add_notice(__('Unsupported payment method', 'wc-gateway-paylane'), 'error');
244-
WCPL_Logger::log("[process_payment]\nUnsupported payment method\norder_id: ".$order_id,'error');
248+
WCPL_Logger::log("[process_payment]\nUnsupported payment method\norder_id: " . $order_id, 'error');
245249
return array('success' => false);
246250
}
247251

248252
if (!$this->validate_fields()) {
249-
WCPL_Logger::log("[process_payment]\nNOT valid fields\norder_id: ".$order_id,'error');
253+
WCPL_Logger::log("[process_payment]\nNOT valid fields\norder_id: " . $order_id, 'error');
250254
return array('success' => false);
251255
}
252256

253257
global $woocommerce;
254-
258+
255259
$order = new WC_Order($order_id);
260+
$current_order_status = $order->get_status();
261+
if($current_order_status == 'wc-completed'){
262+
WCPL_Logger::log("[process_payment]\nTransaction action AFTER COMPLETED\norder_id: " . $order_id , 'error');
263+
return array('success' => false);
264+
}
256265
$order->update_status('on-hold', __('Awaiting payment confirmation', 'wc-gateway-paylane'));
257266

258-
update_post_meta($order_id, '_payment_method_title', 'Paylane - ' . self::$paylane_methods[$method]);
267+
update_post_meta($order_id, '_payment_method_title', 'Polskie ePłatności - ' . self::$paylane_methods[$method]);
259268

260269
if ($this->woocommerce_version_check()) {
261270
wc_reduce_stock_levels($order_id);
@@ -274,11 +283,12 @@ public function process_payment($order_id)
274283
'back_url' => $this->notify_link,
275284
);
276285
} elseif ($method === 'apple_pay') {
277-
$payload = json_decode(base64_decode($_POST['paylane_apple_pay_payload']), true);
286+
$ap = wcpl_string(wcpl_gp_param_isset($_POST, 'paylane_apple_pay_payload'));
287+
$payload = json_decode(base64_decode($ap), true);
278288

279289
if (is_null($payload) || !$this->isCorrectpayload($payload)) {
280290
wc_add_notice(__('Incorrect Apple Pay payload', 'wc-gateway-paylane'), 'error');
281-
WCPL_Logger::log("[process_payment]\nIncorrect Apple Pay payload\norder_id: ".$order_id,'error');
291+
WCPL_Logger::log("[process_payment]\nIncorrect Apple Pay payload\norder_id: " . $order_id, 'error');
282292
return array('success' => false);
283293
}
284294

@@ -321,33 +331,31 @@ public function process_payment($order_id)
321331
),
322332
);
323333

324-
// print_r($_POST['payment_params_token']);exit;
325-
326334
switch ($method) {
327335
case 'credit_card':
328336
$data['card'] = array(
329-
"token" => $_POST['payment_params_token'],
337+
"token" => wcpl_string(wcpl_gp_param_isset($_POST, 'payment_params_token')),
330338
);
331339
$data['back_url'] = $this->notify_link_3ds;
332340
break;
333341

334342
case 'sepa':
335343
$data['account'] = array(
336-
'account_holder' => $_POST['sepa_account_holder'],
337-
'account_country' => $_POST['sepa_account_country'],
338-
'iban' => $_POST['sepa_iban'],
339-
'bic' => $_POST['sepa_bic'],
344+
'account_holder' => wcpl_string(wcpl_gp_param_isset($_POST, 'sepa_account_holder')),
345+
'account_country' => wcpl_string(wcpl_gp_param_isset($_POST, 'sepa_account_country')),
346+
'iban' => wcpl_string(wcpl_gp_param_isset($_POST, 'sepa_iban')),
347+
'bic' => wcpl_string(wcpl_gp_param_isset($_POST, 'sepa_bic')),
340348
);
341349
$data['account']['mandate_id'] = $order_id;
342350
break;
343351

344352
case 'ideal':
345353
$data['back_url'] = $this->notify_link;
346-
$data['bank_code'] = $_POST['bank-code'];
354+
$data['bank_code'] = wcpl_string(wcpl_gp_param_isset($_POST, 'bank-code'));
347355
break;
348356

349357
case 'transfer':
350-
$data['payment_type'] = $_POST['transfer_bank'];
358+
$data['payment_type'] = wcpl_string(wcpl_gp_param_isset($_POST, 'transfer_bank'));
351359
$data['back_url'] = $this->notify_link;
352360
break;
353361

@@ -365,7 +373,7 @@ public function process_payment($order_id)
365373
}
366374

367375
$this->set_order_paylane_type($order_id, $method);
368-
WCPL_Logger::log("[process_payment]\nWoocommerce process finished\norder_id: ".$order_id."\ntype: ".$method);
376+
WCPL_Logger::log("[process_payment]\nWoocommerce process finished\norder_id: " . $order_id . "\ntype: " . $method);
369377
return array(
370378
'result' => 'success',
371379
'redirect' => add_query_arg(array('order_id' => $order_id, 'type' => $method), $this->notify_link),
@@ -452,12 +460,17 @@ public function handle_notification($data, $token, $communication_id)
452460
$this->checkBasicAuth();
453461
}
454462
if (empty($_POST['communication_id'])) {
455-
WCPL_Logger::log("[handle_notification]\nEmpty communication id",'error');
463+
WCPL_Logger::log("[handle_notification]\nEmpty communication id", 'error');
456464
die('Empty communication id');
457465
}
458466

459467
foreach ($data as $notification) {
460-
$order_id = $notification['text'];
468+
$_txt = json_decode(stripslashes($notification['text']),true);
469+
if(is_array($_txt)){
470+
$order_id = $_txt['description'];
471+
}else{
472+
$order_id = $notification['text'];
473+
}
461474
$order = new WC_Order($order_id);
462475

463476
$this->parseNotification($notification, $order);
@@ -476,28 +489,28 @@ private function parseNotification($notification, $order)
476489
//first time or not final type
477490

478491
if ($notification['type'] === 'S') {
479-
$order->add_order_note('PayLane: ' . __('Transaction complete', 'wc-gateway-paylane'));
480-
WCPL_Logger::log("[handle_notification]\nTransaction complete\nsale_id: ".$id_sale);
492+
$order->add_order_note('Polskie ePłatności: ' . __('Transaction complete', 'wc-gateway-paylane'));
493+
WCPL_Logger::log("[handle_notification]\nTransaction complete\nsale_id: " . $id_sale);
481494
}
482495

483496
if ($notification['type'] === 'R') {
484-
$order->add_order_note('PayLane: ' . __('Refund complete', 'wc-gateway-paylane'));
485-
WCPL_Logger::log("[handle_notification]\nRefund complete\nsale_id: ".$id_sale);
497+
$order->add_order_note('Polskie ePłatności: ' . __('Refund complete', 'wc-gateway-paylane'));
498+
WCPL_Logger::log("[handle_notification]\nRefund complete\nsale_id: " . $id_sale);
486499
}
487500

488501
if ($notification['type'] === 'RV') {
489502
$order->update_status('on-hold', __('Reversal received', 'wc-gateway-paylane'));
490-
WCPL_Logger::log("[handle_notification]\nReversal received\nsale_id: ".$id_sale);
503+
WCPL_Logger::log("[handle_notification]\nReversal received\nsale_id: " . $id_sale);
491504
}
492505

493506
if ($notification['type'] === 'RRO') {
494507
$order->update_status('on-hold', __('Retrieval request / chargeback opened', 'wc-gateway-paylane'));
495-
WCPL_Logger::log("[handle_notification]\nRetrieval request / chargeback opened (RRO)\nsale_id: ".$id_sale);
508+
WCPL_Logger::log("[handle_notification]\nRetrieval request / chargeback opened (RRO)\nsale_id: " . $id_sale);
496509
}
497510

498511
if ($notification['type'] === 'CAD') {
499512
$order->update_status('on-hold', __('Retrieval request / chargeback opened', 'wc-gateway-paylane'));
500-
WCPL_Logger::log("[handle_notification]\nRetrieval request / chargeback opened (CAD)\nsale_id: ".$id_sale);
513+
WCPL_Logger::log("[handle_notification]\nRetrieval request / chargeback opened (CAD)\nsale_id: " . $id_sale);
501514
}
502515

503516
update_post_meta($order->get_id(), 'paylane-notification-timestamp', time());
@@ -669,4 +682,57 @@ protected function get_form($form_name, $vars = array())
669682

670683
return ob_get_clean();
671684
}
685+
686+
public function handle_subscriptions_hooks()
687+
{
688+
if (class_exists('WC_Subscriptions_Order')) {
689+
add_action('woocommerce_scheduled_subscription_payment_' . $this->id, array($this, 'scheduled_subscription_payment'), 10, 2);
690+
}
691+
}
692+
693+
/**
694+
* @param $amount_to_charge
695+
* @param $order
696+
*/
697+
public function scheduled_subscription_payment($amount_to_charge, $order)
698+
{
699+
WCPL_Logger::log("[scheduled_subscription_payment]\nInit payment\nAmount: " . $amount_to_charge . "\nOrder id: " . $order->get_id());
700+
701+
global $woocommerce, $post;
702+
require_once __DIR__ . '/../includes/paylane-rest.php';
703+
704+
$subscriptions = wcs_get_subscriptions_for_renewal_order($order->get_id());
705+
foreach ($subscriptions as $subscription) {
706+
$parent_id = $subscription->get_data()['parent_id'];
707+
$parent_order = new WC_Order($parent_id);
708+
709+
$params = array(
710+
'id_sale' => get_post_meta($parent_order->get_id(), 'paylane-id-sale', true),
711+
'amount' => $amount_to_charge,
712+
'currency' => get_woocommerce_currency(),
713+
'description' => $order->get_id(),
714+
);
715+
716+
$paymentMethod = get_post_meta($parent_order->get_id(), 'paylane-type', true);
717+
$this->set_order_paylane_type($order->get_id(), $paymentMethod);
718+
719+
720+
WCPL_Logger::log("[scheduled_subscription_payment]\nStart payment\nParams: " . json_encode($params) . "\nOrder: " . $order->get_id() . "\nParent Order: " . $parent_order->get_id());
721+
722+
$client = new PayLaneRestClient($this->get_paylane_option('login_PayLane'), $this->get_paylane_option('password_PayLane'));
723+
$result = $client->resaleBySale($params);
724+
725+
if ($client->isSuccess()) {
726+
$this->set_order_paylane_id($order->get_id(), $result['id_sale']);
727+
WC_Subscriptions_Manager::process_subscription_payments_on_order($parent_order);
728+
729+
WCPL_Logger::log("[scheduled_subscription_payment]\nPayment SUCCESS\nid_sale: " . $result['id_sale']);
730+
} else {
731+
WCPL_Logger::log("[scheduled_subscription_payment]\nPayment FAILURE\nResult: " . json_encode($result), 'warning');
732+
733+
WC_Subscriptions_Manager::process_subscription_payment_failure_on_order($parent_order);
734+
}
735+
736+
}
737+
}
672738
}

Gateway/Secure.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Paylane_Gateway_Secure extends Paylane_Gateway_Base
1818
protected function getMethodTitle()
1919
{
2020
if(!is_admin()){
21-
return $this->modTitle(__( 'Fast transfer with PayLane', 'wc-gateway-paylane' ), $this->get_paylane_option( 'secure_form_name'), true);
21+
return $this->modTitle(__( 'Fast transfer with Polskie ePłatności', 'wc-gateway-paylane' ), $this->get_paylane_option( 'secure_form_name'), true);
2222
}
2323
return __( 'Secure Form', 'wc-gateway-paylane' );
2424
}
@@ -28,16 +28,16 @@ protected function getMethodTitle()
2828
*/
2929
protected function getGatewayTitle()
3030
{
31-
return __('Fast transfer with PayLane', 'wc-gateway-paylane');
31+
return __('Fast transfer with Polskie ePłatności', 'wc-gateway-paylane');
3232
}
3333

3434
public function get_icon()
3535
{
36-
$iconUrl = plugins_url('../assets/paylane.png', __FILE__);
36+
$iconUrl = plugins_url('../assets/pep.svg', __FILE__);
3737
$iconHtml = '';
3838
if ($this->get_paylane_option('display_payment_methods_logo','yes') == 'yes') {
3939
$iconHtml .= '<img src="' . $iconUrl . '" class="paylane-payment-method-label-logo" alt="' . esc_attr__(
40-
'PayLane image', 'woocommerce'
40+
'Polskie ePłatności image', 'woocommerce'
4141
) . '">';
4242
}
4343

LICENSE

100755100644
File mode changed.

assets/.DS_Store

6 KB
Binary file not shown.

assets/css/paylane-woocommerce-basic.css

100755100644
File mode changed.

assets/css/paylane-woocommerce-paylane.css

100755100644
File mode changed.

assets/images/.DS_Store

10 KB
Binary file not shown.

assets/js/paylane-woocommerce.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)