def finalize(self, token, payerid): """Complete payment on Paypal after user has confirmed.""" params = {} params['token'] = token params['payerid'] = payerid if len(self.cart.recurring_lineitems) > 0: item = self.cart.recurring_lineitems[0] if self._is_immediate_payment(item): params.update(self._get_checkout_data()) self._do_nvp('DoExpressCheckoutPayment', params) # Subscription is activated with CreateRecurringPaymentsProfile params = {} params['token'] = token params['payerid'] = payerid params.update(self._get_recurring_data()) response = self._do_nvp('CreateRecurringPaymentsProfile', params) profileid = response['PROFILEID'] status = response['PROFILESTATUS'] item.payment_token = profileid if status == 'ActiveProfile': item.is_active = True else: item.is_active = False item.save() else: # Submit for immediate payment params.update(self._get_checkout_data()) self._do_nvp('DoExpressCheckoutPayment', params) url = self.settings["COMPLETE_URL"] return SubmitResult('url', url)
def submit(self, collect_address=False, cart_settings_kwargs=None): """Submit a cart to Google Checkout. Google Checkout's submission process is: * Construct an xml representation of the cart * Post the xml to Checkout, using HTTP Basic Auth * Checkout returns a url to redirect the user to""" # Construct cart xml self._update_with_cart_settings(cart_settings_kwargs) template = loader.get_template("gateway/google/cart.xml") ctx = Context({ "cart": self.cart, "continue_shopping_url": self.settings.get("SHOPPING_URL", None), "edit_cart_url": self.settings.get("EDIT_URL", None), "currency": self.settings["CURRENCY"] }) cart_xml = convertToUTF8(template.render(ctx)) response, content = self._send_xml(self._cart_url, cart_xml) xml = ET.XML(content) url = xml.find( "{http://checkout.google.com/schema/2}redirect-url").text return SubmitResult("url", url)
def get_details(self, token): """Get details from Paypal about payer and payment.""" params = {'token': token} response = self._do_nvp('GetExpressCheckoutDetails', params) payerid = response['PAYERID'] self._update_cart_details(response) # TODO: user-defined callback on get_details to update cart? if self.settings.get("CONFIRM_URL"): url = self.settings["CONFIRM_URL"] else: # No confirm_url specified, so assume we go straight to finalizing the order url = self.settings["FINALIZE_URL"] if '?' in url: url += '&cart=' else: url += '?cart=' url += self.cart._cart_uuid session_args = { 'hiicart_paypal_express_token': token, 'hiicart_paypal_express_payerid': payerid } return SubmitResult('url', url, session_args=session_args)
def submit(self, collect_address=False, cart_settings_kwargs=None, submit=False): """ Simply returns the gateway type to let the frontend know how to proceed. """ return SubmitResult("direct")
def submit(self, collect_address=False, cart_settings_kwargs=None): "Submit the cart to Amazon's Co-Branded UI (CBUI)" self._update_with_cart_settings(cart_settings_kwargs) values = self._get_cbui_values(collect_address) values["Signature"] = fps.generate_signature("GET", values, self._cbui_base_url, self.settings) url = "%s?%s" % (self._cbui_base_url, urllib.urlencode(values)) return SubmitResult("url", url)
def refund(self, payment, amount, reason=None): """Refund a payment.""" params = {'transactionid': payment.transaction_id} if payment.amount == amount: params['refundtype'] = 'Full' else: params.update({ 'refundtype': 'Partial', 'amt': str(amount.quantize(Decimal('.01'))) }) self._do_nvp('RefundTransaction', params) return SubmitResult(None)
def submit(self, collect_address=False, cart_settings_kwargs=None): """Submit order details to the gateway. * Server POSTs an API call to Paypal * Paypal returns a response that includes an URL to redirect the user to""" self._update_with_cart_settings(cart_settings_kwargs) params = self._get_checkout_data() response = self._do_nvp('SetExpressCheckout', params) token = response['TOKEN'] url = self._create_redirect_url(token) return SubmitResult( 'url', url, session_args={'hiicart_paypal_express_token': token})
def refund(self, transaction_id, amount=None, reason=None): self._update_with_cart_settings({'request': None}) params = {} params['transactionid'] = transaction_id params['refundtype'] = 'Partial' if amount else 'Full' if amount: params['amt'] = Decimal(amount).quantize(Decimal('.01')) params['currencycode'] = self.settings['CURRENCY_CODE'] if reason: params['note'] = reason response = self._do_nvp('RefundTransaction', params) return SubmitResult(None)
def submit(self, collect_address=False, cart_settings_kwargs=None, modify_existing_cart=False): """Submit a cart to the gateway. Returns a SubmitResult.""" self._update_with_cart_settings(cart_settings_kwargs) data = self._get_form_data(modify_existing_cart) if self.settings["ENCRYPT"]: data = {"encrypted": self._encrypt_data(data)} return SubmitResult("form", form_data={ "action": self.submit_url, "fields": data })
def refund(self, payment, amount, reason=None): """Refund a payment.""" self._update_with_cart_settings({'request': None}) template = loader.get_template("gateway/google/refund.xml") ctx = Context({ "transaction_id": payment.transaction_id, "reason": reason, "comment": None, "currency": self.settings["CURRENCY"], "amount": Decimal(amount).quantize(Decimal('.01')) }) refund_xml = convertToUTF8(template.render(ctx)) response, content = self._send_xml(self._order_url, refund_xml) return SubmitResult(None)
def submit(self, collect_address=False, cart_settings_kwargs=None): """Submit the cart to the Paypal""" # NOTE: This is possible in Paypal, but I don't have time to # implement it right now. self._update_with_cart_settings(cart_settings_kwargs) if len(self.cart.one_time_lineitems) > 0 and len( self.cart.recurring_lineitems) > 0: raise Paypal2GatewayError( "Recurring and Non-Recurring items can't be mixed.") result = api.set_express_checkout(self.cart, self.settings, collect_address) params = urllib.urlencode({ "cmd": "_express-checkout", "token": result['TOKEN'] }) url = LIVE_REDIRECT if self.settings["LIVE"] else SANDBOX_REDIRECT return SubmitResult("url", "%s?%s" % (url, params))
def submit(self, collect_address=False, cart_settings_kwargs=None): """Submit the cart to the Paypal Adaptive Payments API""" self._update_with_cart_settings(cart_settings_kwargs) if len(self.cart.recurring_lineitems) > 0: raise GatewayError("Adaptive Payments doesn't support recurring payments.") params = {"actionType": "PAY", "currencyCode": "USD", "feesPayer": "EACHRECEIVER", "cancelUrl": self.settings["CANCEL_URL"], "returnUrl": self.settings["RETURN_URL"], "ipnNotificationUrl": self.ipn_url, "trackingId": self.cart.cart_uuid, } for i, r in enumerate(self.settings["RECEIVERS"]): params["receiverList.receiver(%i).email" % i] = r[0] params["receiverList.receiver(%i).amount" % i] = r[1].quantize(Decimal(".01")) params["receiverList.receiver(%i).primary" % i] = str(r[2]).lower() result = api._send_command(self.settings, "Pay", params) params = urllib.urlencode({"cmd": "_ap-payment", "paykey": result['payKey']}) return SubmitResult("url", "%s?%s" % (self.submit_url, params))