Beispiel #1
0
    def create_payment(self,
                       order_number,
                       total,
                       user,
                       language=None,
                       description=None,
                       profile=appsettings.DOCDATA_PROFILE,
                       merchant_name=None,
                       **kwargs):
        """
        Start a new payment session / container.

        This is the first step of any Docdata payment session.

        :param order_number: The order number generated by Oscar.
        :param total: The price object, including totals and currency.
        :type total: :class:`oscar.core.prices.Price`
        :type user: :class:`django.contrib.auth.models.User`
        :param language: The language to display the interface in.
        :param description
        :returns: The Docdata order reference ("order key").
        """
        if not language:
            language = get_language()

        if merchant_name is not None:
            client = DocdataClient.for_merchant(merchant_name=merchant_name,
                                                testing_mode=self.testing_mode)
        else:
            client = self.client

        # May raise an DocdataCreateError exception
        call_args = self.get_create_payment_args(
            # Pass all as kwargs, make it easier for subclasses to override using *args, **kwargs and fetch all by name.
            order_number=order_number,
            total=total,
            user=user,
            language=language,
            description=description,
            profile=profile,
            **kwargs)
        createsuccess = client.create(**call_args)

        # Track order_key for local logging
        destination = call_args.get('bill_to')
        self._store_create_success(
            merchant_name=str(client.merchant_name),
            order_number=order_number,
            order_key=createsuccess.order_key,
            amount=call_args['total_gross_amount'],
            language=language,
            country_code=destination.address.country_code
            if destination else None)

        # Return for further reference
        return createsuccess.order_key
Beispiel #2
0
    def cancel_order(self, order):
        """
        Cancel the order.
        :type order: DocdataOrder
        """
        client = DocdataClient.for_merchant(order.merchant_name, testing_mode=self.testing_mode)
        client.cancel(order.order_key)  # Can bail out with an exception (already logged)

        # Don't wait for server to send event back, get most recent state now.
        # Also make sure the order will be marked as cancelled.
        statusreply = client.status(order.order_key)  # Can bail out with an exception (already logged)
        self._store_report(order, statusreply.report, indented_status=DocdataOrder.STATUS_CANCELLED)
Beispiel #3
0
    def update_order(self, order):
        """
        :type order: DocdataOrder
        """
        # Fetch the latest status
        client = DocdataClient.for_merchant(order.merchant_name, testing_mode=self.testing_mode)
        if client.merchant_name != order.merchant_name:
            raise InvalidMerchant("Order {0} belongs to a different merchant: {1} (client uses: {2})".format(
                order.merchant_order_id, order.merchant_name, client.merchant_name
            ))

        statusreply = client.status(order.order_key)  # Can bail out with an exception (already logged)

        # Store the new status
        self._store_report(order, statusreply.report)
    def create_payment(self, order_number, total, user, language=None, description=None, profile=appsettings.DOCDATA_PROFILE, merchant_name=None, **kwargs):
        """
        Start a new payment session / container.

        This is the first step of any Docdata payment session.

        :param order_number: The order number generated by Oscar.
        :param total: The price object, including totals and currency.
        :type total: :class:`oscar.core.prices.Price`
        :type user: :class:`django.contrib.auth.models.User`
        :param language: The language to display the interface in.
        :param description
        :returns: The Docdata order reference ("order key").
        """
        if not language:
            language = get_language()

        if merchant_name is not None:
            client = DocdataClient.for_merchant(merchant_name=merchant_name, testing_mode=self.testing_mode)
        else:
            client = self.client

        # May raise an DocdataCreateError exception
        call_args = self.get_create_payment_args(
            # Pass all as kwargs, make it easier for subclasses to override using *args, **kwargs and fetch all by name.
            order_number=order_number,
            total=total,
            user=user,
            language=language,
            description=description,
            profile=profile,
            **kwargs
        )
        createsuccess = client.create(**call_args)

        # Track order_key for local logging
        destination = call_args.get('bill_to')
        self._store_create_success(
            merchant_name=str(client.merchant_name),
            order_number=order_number,
            order_key=createsuccess.order_key,
            amount=call_args['total_gross_amount'],
            language=language,
            country_code=destination.address.country_code if destination else None
        )

        # Return for further reference
        return createsuccess.order_key
Beispiel #5
0
    def start_payment(self, order, payment, payment_method=None):
        """
        :type order: DocdataOrder
        """
        # Backwards compatibility fix, old parameter was named "order_key".
        if isinstance(order, basestring):
            order = DocdataOrder.objects.select_for_update().active_merchants().get(order_key=order)

        amount = None

        # This can raise an exception.
        client = DocdataClient.for_merchant(order.merchant_name, testing_mode=self.testing_mode)
        startsuccess = client.start(order.order_key, payment, payment_method=payment_method, amount=amount)

        self._set_status(order, DocdataOrder.STATUS_IN_PROGRESS)
        order.save()

        # Not updating the DocdataPayment objects here,
        # instead just wait for Docdata to call the status view.

        # Return for further reference.
        return startsuccess.payment_id