Beispiel #1
0
    def post(self, request, *args, **kwargs):
        try:
            braintree_visamc_transaction = BraintreeVisaMCTransactionSerializer(
                data=request.data)
        except Exception as error:
            return Response(ReturnResponse.Response(1, __name__, 'failed',
                                                    error).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        try:
            braintree_visamc_transaction.is_valid(raise_exception=True)
            instance = braintree_visamc_transaction.save(
                user_profile=request.user.user_profile)
            braintree = BrainTreeProcessor.BraintreeGateway()
            result = braintree.depositVisaMC(instance)

            deposit_transaction = DepositTransaction(
                user_profile=request.user.user_profile,
                deposit_status=DepositTransactionStatus.objects.get(
                    pk=DEPOSIT_STATUS['SETTLED']),
                payment_gateway=PaymentGateway.objects.get(
                    pk=PAYMENT_GATEWAYS['BRAINTREE']),
                deposit_type=DepositTransactionType.objects.get(
                    pk=DEPOSIT_TYPE['VISA']),
                deposit_id=instance.id)
            deposit_transaction.save()
        except Exception as error:
            return Response(ReturnResponse.Response(1, __name__, 'failed',
                                                    error).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        return Response(ReturnResponse.Response(1, __name__, 'success',
                                                result).return_json(),
                        status=status.HTTP_200_OK)
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     braintree = BrainTreeProcessor.BraintreeGateway()
     token = braintree.getToken()
     return JsonResponse({"token": token}, safe=False)