예제 #1
0
 public function external_hook($hook)
 {
     switch ($hook) {
         case 'notification':
             if (!isset($_REQUEST['serial-number']) || !$_REQUEST['serial-number']) {
                 send_error('Google API not setup correctly. Please ensure API callback URL is set correctly as per instructions');
                 exit;
             }
             chdir(dirname(__FILE__));
             //'includes/plugin_paymethod_google/');
             require_once 'library/googleresponse.php';
             //require_once('library/googlemerchantcalculations.php');
             require_once 'library/googleresult.php';
             require_once 'library/googlerequest.php';
             require_once 'library/googlenotification.php';
             require_once 'library/googlenotificationhistory.php';
             define('RESPONSE_HANDLER_ERROR_LOG_FILE', _UCM_FOLDER . '/temp/googleerror.log');
             define('RESPONSE_HANDLER_LOG_FILE', _UCM_FOLDER . '/temp/googlemessage.log');
             $server_type = self::is_sandbox() ? "sandbox" : '';
             //$currency = module_config::get_currency($currency_id);
             //$Gresponse = new GoogleResponse(self::get_merchant_id(), self::get_merchant_key());
             $Grequest = new GoogleRequest(self::get_merchant_id(), self::get_merchant_key(), $server_type);
             $GNotificationHistory = new GoogleNotificationHistoryRequest(self::get_merchant_id(), self::get_merchant_key(), $server_type);
             $response = $GNotificationHistory->SendNotificationHistoryRequest($_REQUEST['serial-number']);
             $xml_response_status = $response[0];
             $xml_response = $response[1];
             $response = new SimpleXMLElement($xml_response);
             $root = $response->getName();
             // debugging
             //send_error('xml2: '.$root.var_export($response,true));
             //$Gresponse->SetMerchantAuthentication(self::get_merchant_id(), self::get_merchant_key());
             //$Gresponse->SendAck();
             $google_order_number = (string) $response->{'google-order-number'};
             if ($google_order_number) {
                 $invoice_payment_data = get_single('invoice_payment', 'other_id', $google_order_number);
             } else {
                 $invoice_payment_data = false;
                 send_error('Google payment API failure, no Google Order Number located');
             }
             if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) {
                 self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Recorded an API hit: ' . $root);
             }
             switch ($root) {
                 case "new-order-notification":
                     // an order has been placed.
                     // dont really need to do anything.
                     // we grab the merchant private data from this bit
                     // it contains the private id etc..
                     if ($google_order_number && $response->{'shopping-cart'}->{'merchant-private-data'}) {
                         $private_data = (array) $response->{'shopping-cart'}->{'merchant-private-data'};
                         $invoice_id = (int) $private_data['invoice_id'];
                         $invoice_payment_id = (int) $private_data['invoice_payment_id'];
                         if ($invoice_id > 0 && $invoice_payment_id > 0) {
                             self::add_payment_data($invoice_payment_id, 'log', 'Found Google Order Number: ' . $google_order_number);
                             $sql = "UPDATE `" . _DB_PREFIX . "invoice_payment` SET `other_id` = '" . mysql_real_escape_string($google_order_number) . "' WHERE invoice_id = '{$invoice_id}' AND invoice_payment_id = '{$invoice_payment_id}'";
                             query($sql);
                         }
                     }
                     break;
                 case "order-state-change-notification":
                     $new_financial_state = (string) $response->{'new-financial-order-state'};
                     if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) {
                         self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Recorded an order status change to: ' . $new_financial_state);
                     }
                     switch ($new_financial_state) {
                         case 'REVIEWING':
                             break;
                         case 'CHARGEABLE':
                             if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) {
                                 self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Charging customers credit card. ');
                             }
                             // process and charge the order:
                             $Grequest->SendProcessOrder($google_order_number);
                             $Grequest->SendChargeOrder($google_order_number, '');
                             break;
                         case 'CHARGING':
                             break;
                         case 'CHARGED':
                             break;
                         case 'PAYMENT_DECLINED':
                             break;
                         case 'CANCELLED':
                             break;
                         case 'CANCELLED_BY_GOOGLE':
                             //$Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'],
                             //    "Sorry, your order is cancelled by Google", true);
                             break;
                         default:
                             break;
                     }
                     break;
                 case "charge-amount-notification":
                     // payment has been made!
                     // update the order.
                     $Grequest->SendArchiveOrder($google_order_number);
                     if ($invoice_payment_data && $invoice_payment_data['invoice_payment_id']) {
                         self::add_payment_data($invoice_payment_data['invoice_payment_id'], 'log', 'Received a payment of ' . $response->{'latest-charge-amount'} . ' and assigning it to this invoice.');
                         update_insert("invoice_payment_id", $invoice_payment_data['invoice_payment_id'], "invoice_payment", array('date_paid' => date('Y-m-d')));
                     }
                     break;
                 case "chargeback-amount-notification":
                     break;
                 case "refund-amount-notification":
                     break;
                 case "risk-information-notification":
                     break;
                 default:
                     //$Gresponse->SendBadRequestStatus("Invalid or not supported Message");
                     break;
             }
             break;
     }
 }
 public function gateway_ipn($config)
 {
     $cancel = $this->EE->input->get('cancel', TRUE);
     if ($cancel != '') {
         $this->EE->product_model->cart_update_status(session_id(), 0);
         $this->EE->functions->redirect($this->EE->functions->create_url($this->_config["store"][$this->site_id]["cart_url"]));
         exit;
     }
     $this->EE->load->library('logger');
     $this->EE->logger->developer('IPN Started');
     require_once 'assets/google-checkout/library/googleresponse.php';
     require_once 'assets/google-checkout/library/googlemerchantcalculations.php';
     require_once 'assets/google-checkout/library/googlerequest.php';
     require_once 'assets/google-checkout/library/googlenotificationhistory.php';
     //Definitions
     $merchant_id = $config['merchant_id'];
     // Your Merchant ID
     $merchant_key = $config['merchant_key'];
     // Your Merchant Key
     $server_type = $config['sandbox'];
     $currency = "USD";
     $certificate_path = "";
     // set your SSL CA cert path
     //Create the response object
     $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
     //Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
     //If serial-number-notification pull serial number and request xml
     if (strpos($xml_response, "xml") == FALSE) {
         //Find serial-number ack notification
         $serial_array = array();
         parse_str($xml_response, $serial_array);
         $serial_number = $serial_array["serial-number"];
         //Request XML notification
         $Grequest = new GoogleNotificationHistoryRequest($merchant_id, $merchant_key, $server_type);
         $raw_xml_array = $Grequest->SendNotificationHistoryRequest($serial_number);
         if ($raw_xml_array[0] != 200) {
             //Add code here to retry with exponential backoff
         } else {
             $raw_xml = $raw_xml_array[1];
         }
         $Gresponse->SendAck($serial_number, false);
     } else {
         //Else assume pre 2.5 XML notification
         //Check Basic Authentication
         $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
         $status = $Gresponse->HttpAuthentication();
         if (!$status) {
             die('authentication failed');
         }
         $raw_xml = $xml_response;
         $Gresponse->SendAck(null, false);
     }
     if (get_magic_quotes_gpc()) {
         $raw_xml = stripslashes($raw_xml);
     }
     list($root, $data) = $Gresponse->GetParsedXML($raw_xml);
     switch ($root) {
         case "new-order-notification":
             $this->EE->logger->developer('Google New Order Notification');
             $transaction_id = $data[$root]['shopping-cart']['merchant-private-data']['transaction_id']['VALUE'];
             $google_order_number = $data[$root]['google-order-number']['VALUE'];
             $this->ipn_create_order($transaction_id, 2);
             $this->add_gc_entry($transaction_id, $google_order_number);
             break;
         case "authorization-amount-notification":
             break;
         case "order-state-change-notification":
             $this->EE->logger->developer('Order State Change Triggered');
             $orderstate = $data[$root]['new-fulfillment-order-state']['VALUE'];
             $google_order_number = $data[$root]['google-order-number']['VALUE'];
             $br_merchant_id = $this->get_gc_entry($google_order_number);
             $status['NEW'] = 2;
             $status['PROCESSING'] = 3;
             $status['DELIVERED'] = 4;
             if (isset($status[$orderstate])) {
                 $this->ipn_create_order($br_merchant_id, $status[$orderstate]);
                 $this->EE->logger->developer("Updating order with status ID: " . $status[$orderstate]);
             }
             break;
     }
 }
예제 #3
0
// set to GBP if in the UK
//Create the response object
$Gresponse = new GoogleResponse($merchant_id, $merchant_key);
//Setup the log file
$Gresponse->SetLogFiles('', '', L_OFF);
//Change this to L_ON to log
//Retrieve the XML sent in the HTTP POST request to the ResponseHandler
$xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
//If serial-number-notification pull serial number and request xml
if (strpos($xml_response, "xml") == FALSE) {
    //Find serial-number ack notification
    $serial_array = array();
    parse_str($xml_response, $serial_array);
    $serial_number = $serial_array["serial-number"];
    //Request XML notification
    $Grequest = new GoogleNotificationHistoryRequest($merchant_id, $merchant_key, $server_type);
    $raw_xml_array = $Grequest->SendNotificationHistoryRequest($serial_number);
    if ($raw_xml_array[0] != 200) {
        //Add code here to retry with exponential backoff
    } else {
        $raw_xml = $raw_xml_array[1];
    }
    $Gresponse->SendAck($serial_number, false);
} else {
    //Else assume pre 2.5 XML notification
    //Check Basic Authentication
    $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
    $status = $Gresponse->HttpAuthentication();
    if (!$status) {
        die('authentication failed');
    }