cardinity.php (2367B)
1 <?php 2 use Cardinity\Client; 3 use Cardinity\Method\Payment; 4 use Cardinity\Method\Refund; 5 6 class ModelExtensionPaymentCardinity extends Model { 7 public function getOrder($order_id) { 8 $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "cardinity_order` WHERE `order_id` = '" . (int)$order_id . "' LIMIT 1"); 9 10 return $query->row; 11 } 12 13 public function createClient($credentials) { 14 return Client::create(array( 15 'consumerKey' => $credentials['key'], 16 'consumerSecret' => $credentials['secret'], 17 )); 18 } 19 20 public function verifyCredentials($client) { 21 $method = new Payment\GetAll(10); 22 23 try { 24 $client->call($method); 25 26 return true; 27 } catch (Exception $e) { 28 $this->log($e->getMessage()); 29 30 return false; 31 } 32 } 33 34 public function getPayment($client, $payment_id) { 35 $method = new Payment\Get($payment_id); 36 37 try { 38 $payment = $client->call($method); 39 40 return $payment; 41 } catch (Exception $e) { 42 $this->log($e->getMessage()); 43 44 return false; 45 } 46 } 47 48 public function getRefunds($client, $payment_id) { 49 $method = new Refund\GetAll($payment_id); 50 51 try { 52 $refunds = $client->call($method); 53 54 return $refunds; 55 } catch (Exception $e) { 56 $this->log($e->getMessage()); 57 58 return false; 59 } 60 } 61 62 public function refundPayment($client, $payment_id, $amount, $description) { 63 $method = new Refund\Create($payment_id, $amount, $description); 64 65 try { 66 $refund = $client->call($method); 67 68 return $refund; 69 } catch (Exception $e) { 70 $this->log($e->getMessage()); 71 72 return false; 73 } 74 } 75 76 public function log($data) { 77 if ($this->config->get('payment_cardinity_debug')) { 78 $backtrace = debug_backtrace(); 79 $log = new Log('cardinity.log'); 80 $log->write('(' . $backtrace[1]['class'] . '::' . $backtrace[1]['function'] . ') - ' . print_r($data, true)); 81 } 82 } 83 84 public function install() { 85 $this->db->query(" 86 CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "cardinity_order` ( 87 `cardinity_order_id` INT(11) NOT NULL AUTO_INCREMENT, 88 `order_id` INT(11) NOT NULL, 89 `payment_id` VARCHAR(255), 90 PRIMARY KEY (`cardinity_order_id`) 91 ) ENGINE=MyISAM DEFAULT COLLATE=utf8_general_ci; 92 "); 93 } 94 95 public function uninstall() { 96 $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "cardinity_order`;"); 97 } 98 }