def status_extended(self, order_key):
        """
        Request the status with extended information.
        """
        if not order_key:
            raise OrderKeyMissing("Missing order_key!")

        reply = self.client.service.statusExtended(
            self.merchant,
            order_key,
            self.integration_info.to_xml(
                self.client.factory
            )  # NOTE: called iIntegrationInfo in the XSD!!
        )

        if hasattr(reply, 'statusSuccess'):
            return StatusReply(order_key, reply.statusSuccess.report)
        elif hasattr(reply, 'statusError'):
            error = reply.statusError.error
            log_docdata_error(
                error,
                "DocdataClient: failed to get status for payment cluster %s",
                order_key)
            raise DocdataStatusError(error._code, error.value)
        else:
            logger.error("Unexpected response node from docdata!")
            raise NotImplementedError(
                'Received unknown reply from DocData. Remote Payment not created.'
            )
    def status(self, order_key):
        """
        Request the status of of order and it's payments.

        :rtype: StatusReply
        """
        # Example response:
        #
        # <?xml version='1.0' encoding='UTF-8'?>
        # <statusResponse xmlns="http://www.docdatapayments.com/services/paymentservice/1_0/">
        #   <statusSuccess>
        #     <success code="SUCCESS">Operation successful.</success>
        #     <report>
        #       <approximateTotals exchangedTo="EUR" exchangeRateDate="2012-12-04 14:39:53">
        #         <totalRegistered>3310</totalRegistered>
        #         <totalShopperPending>0</totalShopperPending>
        #         <totalAcquirerPending>0</totalAcquirerPending>
        #         <totalAcquirerApproved>3310</totalAcquirerApproved>
        #         <totalCaptured>0</totalCaptured>
        #         <totalRefunded>0</totalRefunded>
        #         <totalChargedback>0</totalChargedback>
        #       </approximateTotals>
        #       <payment>           # Can occur multiple times.
        #         <id>1606709142</id>
        #         <paymentMethod>MASTERCARD</paymentMethod>
        #         <authorization>
        #           <status>AUTHORIZED</status>
        #           <amount currency="EUR">3310</amount>
        #           <confidenceLevel>ACQUIRER_APPROVED</confidenceLevel>
        #         </authorization>
        #       </payment>
        #     </report>
        #   </statusSuccess>
        # </statusResponse>
        if not order_key:
            raise OrderKeyMissing("Missing order_key!")

        reply = self.client.service.status(
            self.merchant,
            order_key,
            iIntegrationInfo=self.integration_info.to_xml(
                self.client.factory
            )  # NOTE: called iIntegrationInfo in the XSD!!
        )

        if hasattr(reply, 'statusSuccess'):
            return StatusReply(order_key, reply.statusSuccess.report)
        elif hasattr(reply, 'statusError'):
            error = reply.statusError.error
            log_docdata_error(
                error,
                "DocdataClient: failed to get status for payment cluster %s",
                order_key)
            raise DocdataStatusError(error._code, error.value)
        else:
            logger.error("Unexpected response node from docdata!")
            raise NotImplementedError(
                'Received unknown reply from DocData. No status processed from Docdata.'
            )
    def start(self, order_key, payment, payment_method=None, amount=None):
        """
        The start operation is used for starting a (web direct) payment on an order.
        It does not need to be used if the merchant makes use of Docdata Payments web menu.

        The web direct can be used for recurring payments for example.
        Standard payments (e.g. iDEAL, creditcard) all happen through the web menu
        because implementing those locally requires certification by the credit card companies.

        TODO: untested

        :type order_key: str
        :param payment: A subclass of the payment class, which one depends on the payment method.
        :type payment: Payment
        :param payment_method: One of the supported payment methods, e.g. PAYMENT_METHOD_IDEAL, PAYMENT_METHOD_MASTERCARD.
                               If omitted, the payment method of the ``payment`` object is used.
        :type payment_method: str
        :param amount: Optional payment amount. If left empty, the full amount of the payment order is used.
        :type amount: Amount
        """
        if not order_key:
            raise OrderKeyMissing("Missing order_key!")

        # We only need to set amount because of bug in suds library. Otherwise it defaults to order amount.

        paymentRequestInput = self.client.factory.create(
            'ns0:paymentRequestInput')
        if amount is not None:
            paymentRequestInput.paymentAmount = amount.to_xml(
                self.client.factory)
        paymentRequestInput.paymentMethod = payment_method or payment.payment_method
        paymentRequestInput[payment.request_parameter] = payment.to_xml(
            self.client.factory)

        # Execute start payment request.
        reply = self.client.service.start(
            self.merchant,
            order_key,
            paymentRequestInput,
            integrationInfo=self.integration_info.to_xml(self.client.factory))
        if hasattr(reply, 'startSuccess'):
            return StartReply(reply.startSuccess.paymentId)
        elif hasattr(reply, 'startError'):
            error = reply.createError.error
            log_docdata_error(
                error,
                "DocdataClient: failed to get start payment for order %s",
                order_key)
            raise DocdataStartError(error._code, error.value)
        else:
            raise NotImplementedError(
                'Received unknown reply from DocData. Remote Payment not created.'
            )
示例#4
0
    def cancel(self, order_key):
        """
        The cancel command is used for canceling a previously created payment,
        and can only be used for payments with status NEW, STARTED and AUTHORIZED.
        """
        if not order_key:
            raise OrderKeyMissing("Missing order_key!")

        reply = self.client.service.cancel(self.merchant, order_key)

        if hasattr(reply, 'cancelSuccess'):
            return True
        elif hasattr(reply, 'cancelErrors'):
            error = reply.cancelErrors.error
            log_docdata_error(error, "DocdataClient: failed to cancel the order %s", order_key)
            raise DocdataCancelError(error._code, error.value)
        else:
            logger.error("Unexpected response node from docdata!")
            raise NotImplementedError('Received unknown reply from DocData. Remote Payment not cancelled.')