def _update_with_cart_settings(self, hiicart): """Pull cart-specific settings and update self.settings with them. We need an DI facility to get cart-specific settings in. This way, we're able to have different carts use different google accounts.""" if not settings.HIICART_SETTINGS.get("CART_SETTINGS_FN", False): return s = call_func(settings.HIICART_SETTINGS["CART_SETTINGS_FN"], hiicart) self.settings.update(s)
def _update_with_store_settings(self): """Pull cart-specific settings and update self.settings with them. We need an DI facility to get cart-specific settings in. This way, we're able to have different carts use different google accounts.""" if self.cart.hiicart_settings.get("STORE_SETTINGS_FN"): s = call_func(self.cart.hiicart_settings["STORE_SETTINGS_FN"], self.cart) if s: self.settings.update(s) return self.settings = self._settings_base.copy() # reset to defaults
def ipn(request): """View to receive notifications from Google""" if request.method != "POST": logger.error("IPN Request not POSTed") return HttpResponseBadRequest("Requests must be POSTed") data = request.POST logger.info("IPN Received:\n%s" % format_data(data)) cart = _find_cart(data) if cart: gateway = GoogleGateway(cart) # Check credentials if gateway.settings.get("IPN_AUTH_VALS", False): mine = call_func(gateway.settings["IPN_AUTH_VALS"]) else: mine = gateway.get_basic_auth() theirs = request.META["HTTP_AUTHORIZATION"].split(" ")[1] if theirs not in mine: response = HttpResponse("Authorization Required") response["WWW-Authenticate"] = "Basic" response.status_code = 401 return response # Handle the notification type = data["_type"] handler = GoogleIPN(cart) if type == "new-order-notification": handler.new_order(data) elif type == "order-state-change-notification": handler.order_state_change(data) elif type == "risk-information-notification": handler.risk_information(data) elif type == "charge-amount-notification": handler.charge_amount(data) elif type == "refund-amount-notification": handler.refund_amount(data) elif type == "chargeback-amount-notification": handler.chargeback_amount(data) elif type == "authorization-amount-notification": handler.authorization_amount(data) elif type == "cancelled-subscription-notification": handler.cancelled_subscription(data) else: logger.error("google gateway: Unknown message type recieved: %s" % type) else: logger.error("google gateway: Unknown tranaction, %s" % data) # Return ack so google knows we handled the message ack = ( "<notification-acknowledgment xmlns='http://checkout.google.com/schema/2' serial-number='%s'/>" % data["serial-number"].strip() ) response = HttpResponse(content=ack, content_type="text/xml; charset=UTF-8") logger.debug("Google Checkout: Sending IPN Acknowledgement") return response
def ipn(request): """View to receive notifications from Google""" if request.method != "POST": log.error('google ipn request not POSTed') return HttpResponseBadRequest("Requests must be POSTed") data = request.POST log.info("IPN Notification received from Google Checkout: %s" % data) cart = _find_cart(data) if cart: gateway = GoogleGateway(cart) # Check credentials if gateway.settings.get("IPN_AUTH_VALS", False): mine = call_func(gateway.settings["IPN_AUTH_VALS"]) else: mine = gateway.get_basic_auth() theirs = request.META["HTTP_AUTHORIZATION"].split(" ")[1] if theirs not in mine: response = HttpResponse("Authorization Required") response["WWW-Authenticate"] = "Basic" response.status_code = 401 return response # Handle the notification type = data["_type"] handler = GoogleIPN(cart) if type == "new-order-notification": handler.new_order(data) elif type == "order-state-change-notification": handler.order_state_change(data) elif type == "risk-information-notification": handler.risk_information(data) elif type == "charge-amount-notification": handler.charge_amount(data) elif type == "refund-amount-notification": handler.refund_amount(data) elif type == "chargeback-amount-notification": handler.chargeback_amount(data) elif type == "authorization-amount-notification": handler.authorization_amount(data) elif type == "cancelled-subscription-notification": handler.cancelled_subscription(data) else: log.error("google gateway: Unknown message type recieved: %s" % type) else: log.error('google gateway: Unknown tranaction, %s' % data) # Return ack so google knows we handled the message ack = "<notification-acknowledgment xmlns='http://checkout.google.com/schema/2' serial-number='%s'/>" % data[ "serial-number"].strip() response = HttpResponse(content=ack, content_type="text/xml; charset=UTF-8") log.debug("Google Checkout: Sending IPN Acknowledgement") return response