コード例 #1
0
    def post(self, request):
        # Mark the payment method as complete or denied
        amount = Decimal(request.data['amount'])
        order_number = request.data['reference_number']
        order = get_object_or_404(Order, number=order_number)

        # Get the method key
        method_key = Signer().unsign(request.data['transaction_id'])

        # Decline the payment
        if request.data.get('deny'):
            utils.mark_payment_method_declined(order, request, method_key,
                                               request.data['amount'])
            return Response({
                'status': 'Declined',
            })

        # Record the funds allocation
        new_state = CreditCard().record_successful_authorization(
            order, amount, uuid.uuid1())
        utils.update_payment_method_state(order, request, method_key,
                                          new_state)
        return Response({
            'status': 'Success',
        })
コード例 #2
0
    def post(self, request):
        # Mark the payment method as complete or denied
        amount = Decimal(request.data["amount"])
        order_number = request.data["reference_number"]
        order = get_object_or_404(Order, number=order_number)

        # Get the method key
        method_key = Signer().unsign(request.data["transaction_id"])

        # Get transaction UUID
        reference = request.data["uuid"]

        # Decline the payment
        if request.data.get("deny"):
            new_state = CreditCard().record_declined_authorization(
                order, amount, reference)
            utils.update_payment_method_state(order, request, method_key,
                                              new_state)
            return Response({
                "status": "Declined",
            })

        # Record the funds allocation
        new_state = CreditCard().record_successful_authorization(
            order, amount, reference)
        utils.update_payment_method_state(order, request, method_key,
                                          new_state)
        return Response({
            "status": "Success",
        })
コード例 #3
0
    def post(self, request):
        amount = Decimal(request.data['amount'])
        order_number = request.data['reference_number']
        order = get_object_or_404(Order, number=order_number)

        # Decline the payment
        if request.data.get('deny'):
            utils.mark_payment_method_declined(order, request, CreditCard.code,
                                               request.data['amount'])
            return Response({
                'status': 'Declined',
            })

        # Require the client to do another form post
        new_state = CreditCard().require_authorization_post(order, amount)
        utils.update_payment_method_state(order, request, CreditCard.code,
                                          new_state)
        return Response({
            'status': 'Success',
        })
コード例 #4
0
    def record_token(self, request, format, reply_log_entry):
        # Fetch the related order
        order = self._get_order(request)
        method_key = self._get_method_key(request)

        # Figure out what status the order is in.
        decision = reply_log_entry.get_decision()

        # Check if the payment token was actually created or not.
        if decision == DECISION_ACCEPT:
            new_state = Cybersource().record_created_payment_token(request, reply_log_entry, order, method_key, request.data)
            utils.update_payment_method_state(order, request, method_key, new_state)
            return redirect(settings.REDIRECT_PENDING)

        amount = Decimal(request.data.get('req_amount', '0.00'))
        try:
            utils.mark_payment_method_declined(order, request, method_key, amount)
        except InvalidOrderStatus:
            logger.exception((
                "Failed to set Order {} to payment declined. Order is current in status {}. "
                "Examine CyberSourceReply[{}]"
            ).format(order.number, order.status, reply_log_entry.pk))
        return redirect(settings.REDIRECT_FAIL)
コード例 #5
0
    def record_authorization(self, request, format, reply_log_entry):
        # If the transaction already exists, do nothing
        if Transaction.objects.filter(reference=request.data.get('transaction_id')).exists():
            logger.warning('Duplicate transaction_id received from CyberSource: %s' % request.data.get('transaction_id'))
            return redirect(settings.REDIRECT_SUCCESS)

        # Fetch the related order
        order = self._get_order(request)
        method_key = self._get_method_key(request)

        # Figure out what status the order is in.
        decision = reply_log_entry.get_decision()

        # If authorization was successful, log it and redirect to the success page.
        if decision in (DECISION_ACCEPT, DECISION_REVIEW):
            new_state = Cybersource().record_successful_authorization(reply_log_entry, order, request.data)
            utils.update_payment_method_state(order, request, method_key, new_state)

            # If the order is under review, add a note explaining why
            if decision == DECISION_REVIEW:
                msg = (
                    'Transaction %s is currently under review. '
                    'Use Decision Manager to either accept or reject the transaction.'
                ) % request.data.get('transaction_id')
                self._create_order_note(order, msg)

            return redirect(settings.REDIRECT_SUCCESS)

        new_state = Cybersource().record_declined_authorization(reply_log_entry, order, request.data)
        try:
            utils.update_payment_method_state(order, request, method_key, new_state)
        except InvalidOrderStatus:
            logger.exception((
                "Failed to set Order {} to payment declined. Order is current in status {}. "
                "Examine CyberSourceReply[{}]"
            ).format(order.number, order.status, reply_log_entry.pk))
        return redirect(settings.REDIRECT_FAIL)
コード例 #6
0
    def post(self, request):
        amount = Decimal(request.data["amount"])
        order_number = request.data["reference_number"]
        order = get_object_or_404(Order, number=order_number)

        # Get the method key
        method_key = Signer().unsign(request.data["transaction_id"])

        # Decline the payment
        if request.data.get("deny"):
            utils.mark_payment_method_declined(order, request, method_key,
                                               request.data["amount"])
            return Response({
                "status": "Declined",
            })

        # Require the client to do another form post
        new_state = CreditCard().require_authorization_post(
            order, method_key, amount)
        utils.update_payment_method_state(order, request, method_key,
                                          new_state)
        return Response({
            "status": "Success",
        })