shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

pp_express.php (3690B)


      1 <?php
      2 class ControllerExtensionRecurringPPExpress extends Controller {
      3 	public function index() {
      4 		$this->load->language('extension/recurring/pp_express');
      5 		
      6 		if (isset($this->request->get['order_recurring_id'])) {
      7 			$order_recurring_id = $this->request->get['order_recurring_id'];
      8 		} else {
      9 			$order_recurring_id = 0;
     10 		}
     11 		
     12 		$this->load->model('account/recurring');
     13 
     14 		$recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id);
     15 		
     16 		if ($recurring_info) {
     17 			$data['continue'] = $this->url->link('account/recurring', '', true);	
     18 			
     19 			if ($recurring_info['status'] == 2 || $recurring_info['status'] == 3) {
     20 				$data['order_recurring_id'] = $order_recurring_id;
     21 			} else {
     22 				$data['order_recurring_id'] = '';
     23 			}
     24 
     25 			return $this->load->view('extension/recurring/pp_express', $data);
     26 		}
     27 	}
     28 	
     29 	public function cancel() {
     30 		$json = array();
     31 		
     32 		$this->load->language('extension/recurring/pp_express');
     33 		
     34 		//cancel an active recurring
     35 		$this->load->model('account/recurring');
     36 		
     37 		if (isset($this->request->get['order_recurring_id'])) {
     38 			$order_recurring_id = $this->request->get['order_recurring_id'];
     39 		} else {
     40 			$order_recurring_id = 0;
     41 		}
     42 		
     43 		$recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id);
     44 
     45 		if ($recurring_info && $recurring_info['reference']) {
     46 			if ($this->config->get('payment_pp_express_test')) {
     47 				$api_url = 'https://api-3t.sandbox.paypal.com/nvp';
     48 				$api_username = $this->config->get('payment_pp_express_sandbox_username');
     49 				$api_password = $this->config->get('payment_pp_express_sandbox_password');
     50 				$api_signature = $this->config->get('payment_pp_express_sandbox_signature');
     51 			} else {
     52 				$api_url = 'https://api-3t.paypal.com/nvp';
     53 				$api_username = $this->config->get('payment_pp_express_username');
     54 				$api_password = $this->config->get('payment_pp_express_password');
     55 				$api_signature = $this->config->get('payment_pp_express_signature');
     56 			}
     57 		
     58 			$request = array(
     59 				'USER'         => $api_username,
     60 				'PWD'          => $api_password,
     61 				'SIGNATURE'    => $api_signature,
     62 				'VERSION'      => '109.0',
     63 				'BUTTONSOURCE' => 'OpenCart_2.0_EC',
     64 				'METHOD'       => 'SetExpressCheckout',
     65 				'METHOD'       => 'ManageRecurringPaymentsProfileStatus',
     66 				'PROFILEID'    => $recurring_info['reference'],
     67 				'ACTION'       => 'Cancel'
     68 			);
     69 
     70 			$curl = curl_init($api_url);
     71 
     72 			curl_setopt($curl, CURLOPT_POST, true);
     73 			curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
     74 			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     75 			curl_setopt($curl, CURLOPT_HEADER, false);
     76 			curl_setopt($curl, CURLOPT_TIMEOUT, 30);
     77 			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     78 
     79 			$response = curl_exec($curl);
     80 			
     81 			if (!$response) {
     82 				$this->log(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl)));
     83 			}
     84 			
     85 			curl_close($curl);
     86 			
     87 			$response_info = array();
     88 			
     89 			parse_str($response, $response_info);
     90 
     91 			if (isset($response_info['PROFILEID'])) {
     92 				$this->model_account_recurring->editOrderRecurringStatus($order_recurring_id, 4);
     93 				$this->model_account_recurring->addOrderRecurringTransaction($order_recurring_id, 5);
     94 
     95 				$json['success'] = $this->language->get('text_cancelled');
     96 			} else {
     97 				$json['error'] = sprintf($this->language->get('error_not_cancelled'), $response_info['L_LONGMESSAGE0']);
     98 			}
     99 		} else {
    100 			$json['error'] = $this->language->get('error_not_found');
    101 		}
    102 
    103 		$this->response->addHeader('Content-Type: application/json');
    104 		$this->response->setOutput(json_encode($json));
    105 	}	
    106 }