· 9 years ago · Oct 01, 2016, 06:28 PM
1<?php
2/**
3 *
4 * @package ipn
5 * @author Lukafurlan
6 * @version 1.0
7 *
8 */
9class ipn {
10
11 private $database;
12
13 public function __construct()
14 {
15 require_once('/home/dreamsca/public_html/store/class/database.class.php');
16 $this->database = new database;
17 }
18
19 public static function encrypt_decrypt($action, $string)
20 {
21 $output = false;
22
23 $encrypt_method = "AES-256-CBC";
24 $secret_key = 'wrtzfgxyxcvbgjzgtfrdsaswerhdtgjfkgl';
25 $secret_iv = 'eqwgrsthdzfghjgfddsdawretsdw';
26
27
28 $key = hash('sha256', $secret_key);
29
30 $iv = substr(hash('sha256', $secret_iv), 0, 16);
31
32 if( $action == 'encrypt' ) {
33 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
34 $output = base64_encode($output);
35 }
36 else if( $action == 'decrypt' ){
37 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
38 }
39
40 return $output;
41 }
42
43 public function ipnData($itemName, $itemNumber, $paymentStatus, $mcGross, $txnId, $payerEmail, $custom)
44 {
45 $custom = $this->encrypt_decrypt("decrypt", $custom);
46 $customData = explode("-", $custom);
47
48 $storeId = $customData[0];
49 $purchaseId = $customData[1];
50
51 if($this->database->checkAuthenticity($purchaseId, $storeId))
52 {
53 $productId = $this->database->getCheckoutDataForID($storeId, $purchaseId);
54 if($totalPrice == $mcGross) {
55 $purchaseDate = date("D M j G:i:s T Y");
56 $purchaseMonth = date("Ym");
57 $this->database->purchaseData($itemName, $itemNumber, $paymentStatus, $mcGross, $txnId, $payerEmail, $storeId, $purchaseId, $purchaseDate, $purchaseMonth);
58 $this->database->updatePurchase($storeId, $purchaseId);
59 }
60 }
61 }
62
63 public function chargeBack($itemName, $itemNumber, $paymentStatus, $mcGross, $txnId, $payerEmail, $custom)
64 {
65 $custom = $this->encrypt_decrypt("decrypt", $custom);
66 $customData = explode("-", $custom);
67
68 $storeId = $customData[0];
69 $purchaseId = $customData[1];
70
71 if($this->database->paymentAlreadyRecieved($purchaseId))
72 {
73 $this->database->updatePayment($purchaseId, $paymentStatus);
74 }
75 }
76
77}