Ejemplo n.º 1
0
    def handle_payment(self, order_number, total, **kwargs):
        """
        Complete payment with WorldPay. This redirects into the WorldPay flow.
        """
        data = self.get_context_data()
        shipping_method = data['shipping_method']

        shipping_address = data['shipping_address']
        billing_address = data['billing_address']

        M_params = {
            b'order_kwargs': json.dumps(data['order_kwargs']).encode("utf-8")
        }

        url = build_payment_url(total,
                                order_number,
                                data['user'],
                                data['basket'],
                                shipping_method,
                                shipping_address,
                                billing_address,
                                M_params=M_params,
                                test_mode=settings.WORLDPAY_TEST_MODE)

        if self.request.session.has_key('checkout_order_id'):
            # We're about to start a new payment, clear any previous checkout id
            self.request.session['checkout_order_id'] = None

        callback_url = self.request.build_absolute_uri(
            reverse('worldpay-callback'))
        url += '&MC_Callback=' + callback_url
        raise RedirectRequired(url)
Ejemplo n.º 2
0
    def handle_paypal_payment(self,
                              currency,
                              item_list,
                              donation=False,
                              deductable_total=0.00,
                              shipping_charge=0.00,
                              execute_uri=None,
                              cancel_uri=None):

        venue = self.request.basket.get_tickets_venue()
        self.configure_paypal(venue)

        payment_data = self.get_payment_data(item_list,
                                             currency,
                                             shipping_charge,
                                             execute_uri=execute_uri,
                                             cancel_uri=cancel_uri)

        payment = paypalrestsdk.Payment(payment_data)
        success = payment.create()
        if success:
            payment_id = payment.id
            for link in payment.links:
                if link.rel == 'approval_url':
                    # Convert to str to avoid Google App Engine Unicode issue
                    # https://github.com/paypal/rest-api-sdk-python/pull/58
                    approval_url = str(link.href)
            if self.request.is_ajax():
                raise RedirectRequiredAjax(approval_url, payment_id)
            else:
                raise RedirectRequired(approval_url)
        else:
            raise UnableToTakePayment(payment.error)
Ejemplo n.º 3
0
    def handle_payment(self, order_number, total, **kwargs):
        submission = kwargs['submission']

        # Make request to Docdata.
        # Any raised exceptions are handled by the PaymentDetail.submit() code.
        facade = CustomDocdataFacade()
        docdata_ref = facade.create_payment(
            order_number=order_number,
            total=total,
            user=submission['user'],
            # Extra parameters to add the "Invoice" element in Docdata:
            billing_address=submission[
                'shipping_address'],  # NOTE: no billing address collected in steps.
            shipping_address=submission['shipping_address'],
            basket=submission['basket'],
            description='')

        # NOTE: at this point, the payment is registered as the gateway,
        # and there is no way back. Any errors after this part require manual intervention!

        # Request was successful - record the "payment source".
        # This represents the origin where the payment should come from.
        # When an order is paid in multiple parts, multiple Source objects should be created.
        # As this request was a 'pre-auth', we set the 'amount_allocated'.
        # If we had performed an 'auth' request, then we would set 'amount_debited'.
        source = Source(
            source_type=facade.get_source_type(),
            currency=total.currency,
            amount_allocated=total.
            incl_tax,  # amount_* field depends on type of transaction.
            reference=docdata_ref)
        self.add_payment_source(source)

        # Also record payment event.
        # This will be visible in the Dashboard
        self.add_payment_event('pre-auth',
                               total.incl_tax,
                               reference=docdata_ref)

        # Ask oscar to redirect to docdata
        # TODO: test default_act="yes", skips menu entirely
        # TODO: add issuer_id for iDEAL.
        payment_url_args = {}

        if self.checkout_session.payment_method() is not None:
            payment_url_args[
                'default_pm'] = self.checkout_session.payment_method()

        url = facade.get_payment_menu_url(self.request, docdata_ref,
                                          **payment_url_args)
        logger.info("Redirecting user to {0}".format(url))

        # Regardless of whether the order is paid, write it in the database before redirecting.
        # Oscar actually skips this when redirecting the user to the payment provider.
        self._save_order(order_number, submission)

        # Redirect the user to the payment provider.
        raise RedirectRequired(url)
Ejemplo n.º 4
0
    def handle_payment(self, basket_id, order_number, total, **kwargs):
        payment = self.get_adyen_payment(order_number, total)

        if not payment:
            # no payment necessary
            return [], []

        user_agent = self.request.META.get('HTTP_USER_AGENT')
        raise RedirectRequired(oscar_adyen_api.pay(
            payment, basket_id,
            build_absolute_uri=self.request.build_absolute_uri,
            force_multi=is_old_browser(user_agent)))
Ejemplo n.º 5
0
    def handle_payment(self, order_number, total_incl_tax, **kwargs):
        # Determine base URL of current site - you could just set this in a
        # setting
        if settings.DEBUG:
            # Determine the localserver's hostname to use when
            # in testing mode
            base_url = 'http://%s' % self.request.META['HTTP_HOST']
        else:
            base_url = 'https://%s' % Site.objects.get_current().domain

        # Payment requires a redirect so we raise a RedirectRequired exception
        # and oscar's checkout flow will handle the rest.
        url = facade.BilingFacade(base_url).get_redirect_url(
            order_number, total_incl_tax, self.request.user)
        raise RedirectRequired(url)
Ejemplo n.º 6
0
    def handle_payment(self, order_number, total, **kwargs):
        """
        Called from submit method
        Handle any payment processing and record payment sources and events.

        This method is designed to be overridden within your project.

        This method is responsible for handling payment and recording the
        payment sources (using the add_payment_source method) and payment
        events (using add_payment_event) so they can be
        linked to the order when it is saved later on.
        """
        method = self.checkout_session.payment_method()
        if method == 'cod':
            source_type, is_created = models.SourceType.objects.get_or_create(
                name='cash')
            redirect_url = ''
        elif method == 'yandex_kassa':
            Configuration.account_id = settings.KASSA_ID
            Configuration.secret_key = settings.KASSA_TOKEN
            source_type, is_created = models.SourceType.objects.get_or_create(
                name='online')
            payment = Payment.create(
                {
                    "amount": {
                        "value": str(total.incl_tax),
                        "currency": "RUB"
                    },
                    "confirmation": {
                        "type": "redirect",
                        "return_url":
                        "http://127.0.0.1:8000/checkout/thank-you/"
                    },
                    "capture": True,  # холдирование - False
                    "description": order_number
                },
                uuid.uuid4())
            redirect_url = payment.confirmation.confirmation_url

        source = source_type.sources.model(source_type=source_type,
                                           amount_allocated=total.incl_tax,
                                           currency=total.currency)
        self.add_payment_source(source)
        self.add_payment_event('Authorised', total.incl_tax)
        if redirect_url:
            # return redirect(redirect_url)
            raise RedirectRequired(redirect_url)
Ejemplo n.º 7
0
    def handle_payment(self, order_number, total, **kwargs):
        submission = kwargs['submission']

        # Create new Mollie Payment!
        facade = Facade()
        payment_id = facade.create_payment(order_number=order_number,
                                           total=total.incl_tax,
                                           redirect_url=self.get_success_url())

        # Register the Oscar Source(Type)
        source = Source(source_type=facade.get_source_type(),
                        amount_allocated=total.incl_tax,
                        currency=total.currency,
                        reference=payment_id)
        self.add_payment_source(source)

        # Record Payment event and create the Order(!)
        self.add_payment_event('pre-auth', total.incl_tax)
        self._save_order(order_number, submission)

        # Redirect to Mollie Payment Page
        url = facade.get_payment_url(payment_id)
        raise RedirectRequired(url)