Passed
Pull Request — master (#715)
by
unknown
04:24
created
includes/gateways/class-getpaid-paykeeper-gateway.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.