Exemplo n.º 1
0
    def purchase_part_one(
        self, return_token, return_domain, return_path,
        return_with_https, encryption_key, customer=None,
        card=None
    ):
        """First part of the 2 stage purchase process.

        See the XML API documentation for more information about the
        purchase process.

        Args:
            return_token (string): Unique token for this purchase call.
            return_domain (string): The domain for the return URL.
            return_path (string): The path for the return URL.
            return_with_https (boolean): Indicates whether the URL should use
                HTTP or HTTPS.
            encryption_key (string): Encryption key for data.
            customer (Customer): Optional, Customer object representing the
                customer making the purchase.
            card (Card): Optional, Card object representing the payment
                card information.

        Returns:
            Dictionary: A dictionary containing an item called
                'redirect_html_page_data' with a string value of
                HTML that should be passed to the user's browser
                in order to perform the redirect.
        """

        if card:
            card_data = dict_ignore_nones(**card._get_dict())
        else:
            card_data = None

        if customer:
            customer_data = dict_ignore_nones(**customer._get_dict())
        else:
            customer_data = None

        https_string = boolean_to_yes_no(
            return_with_https
        )

        crypto_block = self._get_crypto_block_for_object(
            method_name='make_reservation',
            interface_object=self
        )

        resp_dict = self.get_core_api().purchase_reservation_part_one(
            crypto_block=crypto_block,
            upfront_data_token=self.settings['upfront_data_token'],
            customer_data=customer_data,
            return_token=return_token, return_domain=return_domain,
            return_path=return_path, return_with_https=https_string,
            encryption_key=encryption_key, card_data=card_data,
        )

        return resp_dict
Exemplo n.º 2
0
    def purchase_reservation(
        self, customer=None, send_confirmation_email=None,
    ):
        """A one stage purchase process that should only be used for purchases
        made on credit.

        See the XML API documentation for more information about the
        purchase process. Note the absence of a 'card_data' element
        in the input - this is intentional since the 2-stage purchase process
        (calling purchase_part_one & purchase_part_two) should always be used
        whenever a payment method is required.

        Args:
            customer (Customer): Optional, Customer object representing the
                customer making the purchase.
            send_confirmation_email (boolean): Optional, boolean indicating
                whether TSW should send a confirmation email or not.

        Returns:
            Dictionary: The result of the attempted purchase
        """

        if customer:
            customer_data = dict_ignore_nones(**customer._get_dict())
        else:
            customer_data = None

        crypto_block = self._get_crypto_block_for_object(
            method_name='make_reservation',
            interface_object=self
        )

        resp_dict = self.get_core_api().purchase_reservation(
            crypto_block=crypto_block,
            upfront_data_token=self.settings['upfront_data_token'],
            customer_data=customer_data,
            send_confirmation_email=send_confirmation_email,
        )

        return resp_dict