@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Constructor |
14 | 14 | */ |
15 | 15 | |
16 | - public function __construct(){ |
|
16 | + public function __construct(){ |
|
17 | 17 | //Init |
18 | 18 | $this->id = 'paykeeper'; |
19 | 19 | $this->title = __( 'PayKeeper', 'my-domain' ); // Frontend name |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $this->supports = array( 'sandbox', 'tokens', 'addons' ); |
31 | 31 | |
32 | 32 | |
33 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
33 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
34 | 34 | parent::__construct() |
35 | 35 | |
36 | 36 | if ($this->enabled){ |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | |
44 | - } |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | 47 | /** |
48 | - * Processes ipns and marks payments as complete. |
|
48 | + * Processes ipns and marks payments as complete. |
|
49 | 49 | * @docs https://docs.paykeeper.ru/metody-integratsii/priyom-post-opoveshhenij/ |
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function verify_ipn() { |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function verify_ipn() { |
|
54 | 54 | // проверяем наличие необходимых данных в массиве $_POST |
55 | - if ( empty( $_POST ) || empty($_POST["id"],$_POST["sum"], $_POST["orderid"],$_POST["key"]))) { |
|
56 | - wp_die( 'Gateway IPN Request Failure', 500 ); |
|
57 | - } |
|
55 | + if ( empty( $_POST ) || empty($_POST["id"],$_POST["sum"], $_POST["orderid"],$_POST["key"]))) { |
|
56 | + wp_die( 'Gateway IPN Request Failure', 500 ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | $posted = wp_unslash( $_POST ); |
60 | 60 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | |
85 | 85 | //проверяем совпадение данныых инвойса с данными из _POST |
86 | 86 | if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $posted["sum"], 2, '.', '' ) ) { |
87 | - /* translators: %s: Amount. */ |
|
88 | - wpinv_error_log( "Amounts do not match: {$posted['sum']} instead of {$invoice->get_total()}", 'IPN Error', false ); |
|
87 | + /* translators: %s: Amount. */ |
|
88 | + wpinv_error_log( "Amounts do not match: {$posted['sum']} instead of {$invoice->get_total()}", 'IPN Error', false ); |
|
89 | 89 | wpinv_error_log( $posted["sum"], 'Validated IPN Amount', false ); |
90 | 90 | wp_die( 'Invoice not paid via PayKeeper', 500 ); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | 93 | if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
94 | 94 | // инвойс уже оплачен или возвращен |
@@ -104,29 +104,29 @@ discard block |
||
104 | 104 | |
105 | 105 | } |
106 | 106 | |
107 | - /** |
|
108 | - * Retrieves IPN Invoice. |
|
109 | - * |
|
110 | - * @param array $posted |
|
111 | - * @return WPInv_Invoice |
|
112 | - */ |
|
113 | - protected function get_ipn_invoice( $posted ) { |
|
107 | + /** |
|
108 | + * Retrieves IPN Invoice. |
|
109 | + * |
|
110 | + * @param array $posted |
|
111 | + * @return WPInv_Invoice |
|
112 | + */ |
|
113 | + protected function get_ipn_invoice( $posted ) { |
|
114 | 114 | |
115 | - wpinv_error_log( 'Retrieving PayKeeper IPN Response Invoice', false ); |
|
115 | + wpinv_error_log( 'Retrieving PayKeeper IPN Response Invoice', false ); |
|
116 | 116 | |
117 | - if ( ! empty( $posted['orderid'] ) ) { |
|
118 | - $invoice = new WPInv_Invoice( $posted['orderid'] ); |
|
117 | + if ( ! empty( $posted['orderid'] ) ) { |
|
118 | + $invoice = new WPInv_Invoice( $posted['orderid'] ); |
|
119 | 119 | |
120 | - if ( $invoice->exists() ) { |
|
121 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
122 | - return $invoice; |
|
123 | - } |
|
124 | - } |
|
120 | + if ( $invoice->exists() ) { |
|
121 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
122 | + return $invoice; |
|
123 | + } |
|
124 | + } |
|
125 | 125 | |
126 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
127 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
126 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
127 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
128 | 128 | |
129 | - } |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | 132 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | defined('ABSPATH') || exit; |
4 | 4 | |
5 | -abstract class GetPaid_PayKeeper_Gateway extends GetPaid_Payment_Gateway{ |
|
5 | +abstract class GetPaid_PayKeeper_Gateway extends GetPaid_Payment_Gateway { |
|
6 | 6 | |
7 | 7 | private $paykeeper_login = "demo"; |
8 | 8 | private $paykeeper_password = "demo"; |
@@ -13,12 +13,12 @@ discard block |
||
13 | 13 | * Constructor |
14 | 14 | */ |
15 | 15 | |
16 | - public function __construct(){ |
|
16 | + public function __construct() { |
|
17 | 17 | //Init |
18 | 18 | $this->id = 'paykeeper'; |
19 | - $this->title = __( 'PayKeeper', 'my-domain' ); // Frontend name |
|
20 | - $this->method_title = __( 'PayKeeper Gateway', 'my-domain' ); // Admin name |
|
21 | - $this->description = __( 'Pay using my PayKeeper payment gateway', 'my-domain' ); |
|
19 | + $this->title = __('PayKeeper', 'my-domain'); // Frontend name |
|
20 | + $this->method_title = __('PayKeeper Gateway', 'my-domain'); // Admin name |
|
21 | + $this->description = __('Pay using my PayKeeper payment gateway', 'my-domain'); |
|
22 | 22 | |
23 | 23 | |
24 | 24 | $this->sandbox_invoice_url = ""; |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | |
28 | 28 | |
29 | 29 | // Add support features |
30 | - $this->supports = array( 'sandbox', 'tokens', 'addons' ); |
|
30 | + $this->supports = array('sandbox', 'tokens', 'addons'); |
|
31 | 31 | |
32 | 32 | |
33 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
33 | + $this->enabled = wpinv_is_gateway_active($this->id); |
|
34 | 34 | parent::__construct() |
35 | 35 | |
36 | - if ($this->enabled){ |
|
36 | + if ($this->enabled) { |
|
37 | 37 | //code run if this gateway is enabled |
38 | 38 | |
39 | 39 | //$this->paykeeper_login = wpinv_get_option("paykeeper_login"); |
@@ -52,54 +52,54 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function verify_ipn() { |
54 | 54 | // проверяем наличие необходимых данных в массиве $_POST |
55 | - if ( empty( $_POST ) || empty($_POST["id"],$_POST["sum"], $_POST["orderid"],$_POST["key"]))) { |
|
56 | - wp_die( 'Gateway IPN Request Failure', 500 ); |
|
55 | + if (empty($_POST) || empty($_POST["id"], $_POST["sum"], $_POST["orderid"], $_POST["key"]))) { |
|
56 | + wp_die('Gateway IPN Request Failure', 500); |
|
57 | 57 | } |
58 | 58 | |
59 | - $posted = wp_unslash( $_POST ); |
|
59 | + $posted = wp_unslash($_POST); |
|
60 | 60 | |
61 | - if (empty($posted['clientid'])){$posted['clientid']="";} |
|
61 | + if (empty($posted['clientid'])) {$posted['clientid'] = ""; } |
|
62 | 62 | // проверяем подпись и целостность запроса |
63 | 63 | if ($posted["key"] != md5( |
64 | - $posted["id"].$posted["sum"].$posted['clientid'].$posted["orderid"].$this->secret_world; |
|
64 | + $posted["id"] . $posted["sum"] . $posted['clientid'] . $posted["orderid"] . $this->secret_world; |
|
65 | 65 | )) { |
66 | - wp_die( 'Gateway IPN Request Invalid hash', 500 ); |
|
66 | + wp_die('Gateway IPN Request Invalid hash', 500); |
|
67 | 67 | } |
68 | 68 | // ищем инвойс по orderid |
69 | 69 | |
70 | 70 | |
71 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
71 | + $invoice = $this->get_ipn_invoice($posted); |
|
72 | 72 | |
73 | - if (empty($invoice)){ |
|
74 | - wpinv_error_log( 'Aborting, Invoice was not found', false ); |
|
75 | - wp_die( 'Invoice Not Found', 500 ); |
|
73 | + if (empty($invoice)) { |
|
74 | + wpinv_error_log('Aborting, Invoice was not found', false); |
|
75 | + wp_die('Invoice Not Found', 500); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Abort if it was not paid by our gateway. |
79 | - if ( $this->id != $invoice->get_gateway() ) { |
|
80 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayKeeper', false ); |
|
79 | + if ($this->id != $invoice->get_gateway()) { |
|
80 | + wpinv_error_log('Aborting, Invoice was not paid via PayKeeper', false); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
84 | 84 | |
85 | 85 | //проверяем совпадение данныых инвойса с данными из _POST |
86 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $posted["sum"], 2, '.', '' ) ) { |
|
86 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($posted["sum"], 2, '.', '')) { |
|
87 | 87 | /* translators: %s: Amount. */ |
88 | - wpinv_error_log( "Amounts do not match: {$posted['sum']} instead of {$invoice->get_total()}", 'IPN Error', false ); |
|
89 | - wpinv_error_log( $posted["sum"], 'Validated IPN Amount', false ); |
|
90 | - wp_die( 'Invoice not paid via PayKeeper', 500 ); |
|
88 | + wpinv_error_log("Amounts do not match: {$posted['sum']} instead of {$invoice->get_total()}", 'IPN Error', false); |
|
89 | + wpinv_error_log($posted["sum"], 'Validated IPN Amount', false); |
|
90 | + wp_die('Invoice not paid via PayKeeper', 500); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
93 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
94 | 94 | // инвойс уже оплачен или возвращен |
95 | - wpinv_error_log( 'Aborting, Invoice was paid or refunded', false ); |
|
95 | + wpinv_error_log('Aborting, Invoice was paid or refunded', false); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // меняем статус инвойса на УПЛОЧЕНО |
99 | 99 | $invoice->mark_paid(); |
100 | - wpinv_error_log( 'Wow, Invoice {$invoice->id} was paid successfully', false ); |
|
100 | + wpinv_error_log('Wow, Invoice {$invoice->id} was paid successfully', false); |
|
101 | 101 | // пишем ответ Пайкиперу |
102 | - echo "OK ".md5($posted["id"].$this->secret_word) |
|
102 | + echo "OK " . md5($posted["id"] . $this->secret_word) |
|
103 | 103 | |
104 | 104 | |
105 | 105 | } |
@@ -110,21 +110,21 @@ discard block |
||
110 | 110 | * @param array $posted |
111 | 111 | * @return WPInv_Invoice |
112 | 112 | */ |
113 | - protected function get_ipn_invoice( $posted ) { |
|
113 | + protected function get_ipn_invoice($posted) { |
|
114 | 114 | |
115 | - wpinv_error_log( 'Retrieving PayKeeper IPN Response Invoice', false ); |
|
115 | + wpinv_error_log('Retrieving PayKeeper IPN Response Invoice', false); |
|
116 | 116 | |
117 | - if ( ! empty( $posted['orderid'] ) ) { |
|
118 | - $invoice = new WPInv_Invoice( $posted['orderid'] ); |
|
117 | + if (!empty($posted['orderid'])) { |
|
118 | + $invoice = new WPInv_Invoice($posted['orderid']); |
|
119 | 119 | |
120 | - if ( $invoice->exists() ) { |
|
121 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
120 | + if ($invoice->exists()) { |
|
121 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
122 | 122 | return $invoice; |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
127 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
126 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
127 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
128 | 128 | |
129 | 129 | } |
130 | 130 |
@@ -52,9 +52,11 @@ |
||
52 | 52 | */ |
53 | 53 | public function verify_ipn() { |
54 | 54 | // проверяем наличие необходимых данных в массиве $_POST |
55 | - if ( empty( $_POST ) || empty($_POST["id"],$_POST["sum"], $_POST["orderid"],$_POST["key"]))) { |
|
55 | + if ( empty( $_POST ) || empty($_POST["id"],$_POST["sum"], $_POST["orderid"],$_POST["key"])) { |
|
56 | + ) { |
|
56 | 57 | wp_die( 'Gateway IPN Request Failure', 500 ); |
57 | 58 | } |
59 | + } |
|
58 | 60 | |
59 | 61 | $posted = wp_unslash( $_POST ); |
60 | 62 |