function espresso_process_google_checkout_ipn($payment_data) { global $org_options; do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, ''); $google_checkout_settings = get_option('event_espresso_google_checkout_settings'); list($root, $data) = espresso_google_checkout_get_response(); switch ($root) { case "new-order-notification": //notifies that a payment process has been initiated on google checkout, //but not necessarily finished. Don't save a payment as complete yet... $payment_data['txn_type'] = 'Google Checkout'; $payment_data['txn_id'] = $data[$root]['google-order-number']['VALUE']; $payment_data['payment_status'] = $google_checkout_settings['default_payment_status']; $payment_data['txn_details'] = serialize($_REQUEST); if ($google_checkout_settings['use_sandbox']) { wp_mail($org_options['contact_email'], __("Event Espresso-Google Wallet gateway IPN notification", "event_espresso"), sprintf(__("We received a 'new-order-notificaiton' from \n\t\t\t\t\t\tGoogle Wallet, indicating that they've begun to verify the payment info of registration %s. ", "event_espresso"), $payment_data['registration_id'], $response)); } //_e("Google Checkout is verifying your payment. You will receive an email in about 1-15 minutes notifying you of your purchase status.",'event_espresso'); break; case "risk-information-notification": break; case "charge-amount-notification": break; case "authorization-amount-notification": if ($payment_data['payment_status'] != 'Completed' && $payment_data['txn_id'] == $data[$root]['google-order-number']['VALUE']) { //only attempt to charge if payment $google_checkout_id = empty($google_checkout_settings['google_checkout_id']) ? '' : $google_checkout_settings['google_checkout_id']; $google_checkout_key = empty($google_checkout_settings['google_checkout_key']) ? '' : $google_checkout_settings['google_checkout_key']; $use_sandbox = $google_checkout_settings['use_sandbox'] ? 'sandbox' : 'production'; $google_order_number = $data[$root]['google-order-number']['VALUE']; //$tracking_data = array("Z12345" => "UPS", "Y12345" => "Fedex"); $GChargeRequest = new Espresso_GoogleRequest($google_checkout_id, $google_checkout_key, $use_sandbox); //$GRequest->SetCertificatePath($certificate_path); //$GChargeRequest->SendChargeAndShipOrder($google_order_number, $tracking_data); list($status, $response) = $GChargeRequest->SendChargeOrder($google_order_number); if ($status == 200) { $payment_data['payment_status'] = 'Completed'; } else { wp_mail($org_options['contact_email'], __("Event Espresso-Google Wallet gateway IPN problem", "event_espresso"), sprintf(__("We received an 'authorization-amount-notification from Google Wallet, \n\t\t\t\t\t\t\t\t\tindicating we were ready to charge for a payment from %s, but when doing so we received this error message from Google Wallet. The message had status %s, and contained %s. \n\t\t\t\t\t\t\t\t\tNote, you can login to google wallet using your merchant account and manually charge it, and also manually approve the registration in Event Espresso on the event's attendee page.", "event_espresso"), $payment_data['registration_id'], $status, print_r($data, true))); } } break; case "refund-amount-notification": break; case "chargeback-amount-notification": break; case "order-numbers": break; case "invalid-order-numbers": break; case "order-state-change-notification": wp_mail($org_options['contact_email'], __("Event Espresso-Google Wallet gateway IPN Order State Changed", "event_espresso"), sprintf(__("Received an 'order-state-change-notification' form Google checkout,\n\t\t\t\tbut wasn't sure how to handle it... This could mean a payment was declined. Here's the exact message:%s", "event_espresso"), $payment_data['registration_id'], print_r($data, true))); break; default: break; } return $payment_data; }
/** * Send a <notification-history-request> request to Google Checkout * * info: {@link http://code.google.com/apis/checkout/developer/Google_Checkout_XML_API_Notification_History_API.html} * * @param string $sn serial number * @param string $npt next page token * @param array $orders array of string google order numbers * @param array $nt array of string notification types * @param array $st array of tracking data where tracking code => carrier * @param string @st string of start time in format YYYY-MM-DD[T]HH:MM:SS[Timezone] ie * 2010-05-01T05:00:00Z * @param string @et string of end time in format YYYY-MM-DD[T]HH:MM:SS[Timezone] ie * 2010-05-02T05:00:00Z * @param string $cp path to SSL certificates for peer validation */ function SendNotificationHistoryRequest($sn = null, $npt = null, $orders = array(), $nt = array(), $st = null, $et = null, $cp = null) { $postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $postargs .= "<notification-history-request xmlns=\"" . $this->schema_url . "\">"; if (isset($sn)) { $postargs .= "<serial-number>" . $sn . "</serial-number>"; } elseif (isset($npt)) { $postargs .= "<next-page-token>" . $npt . "</next-page-token>"; } else { if (isset($orders) && count($orders) > 0) { $postargs .= "<order-numbers>"; foreach ($orders as $order) { $postargs .= "<google-order-number>" . $order . "</google-order-number>"; } $postargs .= "</order-numbers>"; } if (isset($nt) && count($nt) > 0) { $postargs .= "<notification-types>"; foreach ($nt as $notification_type) { $postargs .= "<notification-type>" . $notification_type . "</notification-type"; } $postargs .= "</notification-types>"; } if (isset($st) && isset($et)) { $postargs .= "<start-time>" . $st . "</start-time>"; $postargs .= "<end-time>" . $et . "</end-time>"; } } $postargs .= "</notification-history-request>"; $Grequest = new Espresso_GoogleRequest($this->merchant_id, $this->merchant_key, $this->server_type); $Grequest->SetCertificatePath($cp); return $Grequest->SendReq($Grequest->GetReportUrl(), $Grequest->GetAuthenticationHeaders(), $postargs); }
/** * Submit a server-to-server request. * Creates a GoogleRequest object (defined in googlerequest.php) and sends * it to the Google Checkout server. * * more info: * {@link http://code.google.com/apis/checkout/developer/index.html#alternate_technique} * * @return array with the returned http status code (200 if OK) in index 0 * and the redirect url returned by the server in index 1 */ function CheckoutServer2Server($proxy = array(), $certPath = '') { require_once dirname(__FILE__) . '/googlerequest.php'; $GRequest = new Espresso_GoogleRequest($this->merchant_id, $this->merchant_key, $this->server_url == "https://checkout.google.com/" ? "Production" : "sandbox", $this->currency); $GRequest->SetProxy($proxy); $GRequest->SetCertificatePath($certPath); return $GRequest->SendServer2ServerCart($this->GetXML()); }