def response_ccavenue_response_handler(responseId):
    from ..main import app
    response = Response.objects.get({"_id": ObjectId(responseId)})
    form = Form.objects.only("formOptions").get({"_id": response.form.id})
    formId = str(form.id)

    merchant_id = form.formOptions.paymentMethods["ccavenue"]["merchant_id"]
    config = CCAvenueConfig.objects.get({"merchant_id": merchant_id})
    if not config:
        mark_error_payment(
            response,
            f"CCAvenue config not found for merchant id: {merchant_id}.",
            "ccavenue", paramDict)

    res = dict(parse_qsl(app.current_request.raw_body.decode('utf-8')))
    paramDict = decrypt(res['encResp'], config.SECRET_working_key)
    if paramDict["merchant_param1"] != formId or paramDict[
            "merchant_param2"] != responseId:
        mark_error_payment(
            response,
            f"Form id / response id do not match. \nExpected: {formId}/{responseId}. \nReceived: {paramDict['merchant_param1']}/{paramDict['merchant_param1']}",
            "ccavenue", paramDict)
    if paramDict["order_status"] != "Success":
        mark_error_payment(
            response,
            f"Order status does not mark success. Expected: Success. Received: {paramDict['order_status']}",
            "ccavenue", paramDict)
        # todo: redirect to another error page.
    elif paramDict["order_status"] == "Success":
        order_id = paramDict["order_id"]
        if any(item.status == "SUCCESS" and item.id == order_id
               and item.method == "ccavenue"
               for item in response.payment_trail):
            mark_error_payment(response,
                               f"Duplicate IPN transaction ID: {order_id}",
                               "ccavenue", paramDict)
        mark_successful_payment(
            form=form,
            response=response,
            full_value=paramDict,
            method_name="ccavenue",
            amount=paramDict["amount"],  # TODO: or mer_amount?
            currency=paramDict["currency"],
            id=paramDict["order_id"])
        response.save()
        redirect_url = get(form.formOptions.paymentMethods,
                           "ccavenue.redirectUrl",
                           "http://www.chinmayamission.com")
        return chalice.Response('',
                                status_code=302,
                                headers={'Location': redirect_url})
Exemplo n.º 2
0
 def test_update_ccavenue_hash_with_subaccount(self):
     """Does changing the subaccount id affect the response?
     """
     merchant_id = str(uuid.uuid4())
     response = Response(amount_paid=20,
                         paymentInfo={
                             "currency": "INR",
                             "total": "50"
                         })
     config = CCAvenueConfig(
         access_code="access_code",
         merchant_id=merchant_id,
         SECRET_working_key="SECRET_working_key",
     ).save()
     ccavenuePaymentMethodInfo1 = update_ccavenue_hash(
         "formId", {"merchant_id": merchant_id}, response)
     ccavenuePaymentMethodInfo2 = update_ccavenue_hash(
         "formId", {"merchant_id": merchant_id}, response)
     ccavenuePaymentMethodInfo3 = update_ccavenue_hash(
         "formId",
         {
             "merchant_id": merchant_id,
             "sub_account_id": "sub_account_id"
         },
         response,
     )
     response1 = decrypt(ccavenuePaymentMethodInfo1["encRequest"],
                         "SECRET_working_key")
     del response1["order_id"]
     response2 = decrypt(ccavenuePaymentMethodInfo2["encRequest"],
                         "SECRET_working_key")
     del response2["order_id"]
     response3 = decrypt(ccavenuePaymentMethodInfo3["encRequest"],
                         "SECRET_working_key")
     del response3["order_id"]
     self.assertEqual(response1, response2)
     self.assertNotEqual(response2, response3)
Exemplo n.º 3
0
 def test_update_ccavenue_hash_with_template_avlues(self):
     merchant_id = str(uuid.uuid4())
     response = Response(
         amount_paid=20,
         paymentInfo={
             "currency": "INR",
             "total": "50"
         },
         value={"name": "Abc 123"},
     )
     config = CCAvenueConfig(
         access_code="access_code",
         merchant_id=merchant_id,
         SECRET_working_key="SECRET_working_key",
     ).save()
     ccavenuePaymentMethodInfo = {
         "merchant_id": merchant_id,
         "billing_name": "{{value.name}}",
         "billing_address": "{{value.name}}",
         "billing_city": "{{value.name}}",
         "billing_state": "{{value.name}}",
         "billing_zip": "{{value.name}}",
         "billing_tel": "{{value.name}}",
         "billing_email": "{{value.name}}",
     }
     response = decrypt(
         update_ccavenue_hash("formId", ccavenuePaymentMethodInfo,
                              response)["encRequest"],
         "SECRET_working_key",
     )
     self.assertEqual(response["merchant_id"], merchant_id)
     self.assertEqual(response["billing_name"], "Abc 123")
     self.assertEqual(response["billing_address"], "Abc 123")
     self.assertEqual(response["billing_city"], "Abc 123")
     self.assertEqual(response["billing_state"], "Abc 123")
     self.assertEqual(response["billing_zip"], "Abc 123")
     self.assertEqual(response["billing_tel"], "Abc 123")
     self.assertEqual(response["billing_email"], "Abc 123")
Exemplo n.º 4
0
 def test_encrypt_decrypt(self):
     encrypted = encrypt(INPUT_DATA, WORKING_KEY)
     decrypted = decrypt(encrypted, WORKING_KEY)
     self.assertEqual(INPUT_DATA, decrypted)