--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e43be322-bab9-4162-9fbc-05c6c9b95c94%40googlegroups.com.
class WeacceptTransaction(Transaction): """Weaccept's Transaction model"""
# before frontend interaction auth_token = models.TextField() # got from step 1 order_id = models.IntegerField(verbose_name="Accept's Order ID") # id from step 2 order_url = models.CharField(max_length=255, null=True) # order_url from step 2 billing_data = JSONField() # provided in request for paymet key, step 3 payment_key = models.TextField() # payment_token from step 3 hmac = models.TextField(null=True) # after (from callback) success_status = models.BooleanField(default=False) is_refunded = models.BooleanField(default=False) reference_number = models.IntegerField(null=True) processed_clbk_json = JSONField(null=True)
class CashPayment(APIView): """Cash Payment endpoint"""
serializer_class = serializers.CardPaymentSerializer required_fields = ["amount_cents", "billing_data"]
def post(self, request): # Validate required fields utils.validate(self.required_fields, request) payment = utils.CashPayment(**request.data) payment.prepare() payment.pay_request() # create a new transaction models.WeacceptTransaction.objects.create( merchant_order_id=payment.merchant_order_id, amount=payment.amount_cents, auth_token=payment.auth_res.get("token"), order_id=payment.order_reg_res.get("id"), order_url=payment.order_reg_res.get("order_url"), billing_data=payment.billing_data, payment_key=payment.payment_key_res.get("token"), hmac=payment.pay_req_res.get("hmac"), )
return Response( { "message": "Our representative will go to the address you provided " "to collect the cash from you", **payment.pay_req_res, } )
class TransactionProcessedCallback(APIView): """Processed callback that will recieve "TRANSACTION", "TOKEN", "ORDER", "DELIVERY_STATUS" objects"""
def post(self, request): # XXX extend to handle TOKEN, DELIVERY_STATUS objects... later t_obj = request.data.get("obj") # transaction object incoming_hmac = request.query_params.get("hmac") calculated_hmac = utils.calculate_hmac_transaction(t_obj)
# if not equal hmac, not coming from Accept! if incoming_hmac != calculated_hmac: return Response( {"message": "invalid data"}, status=status.HTTP_400_BAD_REQUEST )
import ipdb
ipdb.set_trace()
# XXX: The error happens here
transaction = models.WeacceptTransaction.objects.get( merchant_order_id=t_obj.get("order").get("merchant_order_id") ) transaction.success_status = bool(t_obj.get("success")) transaction.is_refunded = bool(t_obj.get("is_refunded")) transaction.reference_number = int(t_obj.get("data").get("transaction_no") or 1) transaction.processed_clbk_json = t_obj transaction.save( update_fields=[ "success_status", "is_refunded", "reference_number", "processed_clbk_json", ] )
email = t_obj.get("order").get("shipping_data").get("email") # TODO: send mail based upon success status try: send_mail( "Transaction Processed", "Your transaction is processed", "SERNDER MAIL", [email], fail_silently=False, ) except Exception as ex: print(">>>>>>>>>>FAILED TO SEND MAIL") print(ex)
return Response({"message": "Transaction Updated!"}, status=status.HTTP_200_OK)
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a379e013-a01c-4c58-bf2b-0b4cd01f0fae%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a379e013-a01c-4c58-bf2b-0b4cd01f0fae%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/987c6ce7-70b6-49a9-ab3e-506e369d060e%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/987c6ce7-70b6-49a9-ab3e-506e369d060e%40googlegroups.com.
if you are able to share more code from the `utils.CashPayment` call that may help us
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/987c6ce7-70b6-49a9-ab3e-506e369d060e%40googlegroups.com.
--Best regards,
Mohammed M. Habib, PhD
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/044d543f-5b6e-40d7-9ee6-36b7e84f5647%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/044d543f-5b6e-40d7-9ee6-36b7e84f5647%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/044d543f-5b6e-40d7-9ee6-36b7e84f5647%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/79ed22d5-675d-4362-834d-5f70f5e23856%40googlegroups.com.