Esempio n. 1
0
    def _signature(self, params):
        """
        Calculate the signature from a dictionary of params.

        NOTE: This method uses the processor's hashing method.  That method
        is a thin wrapper of standard library calls, and it seemed overly complex
        to rewrite that code in the test suite.

        Args:
            params (dict): Dictionary with a key 'signed_field_names',
                which is a comma-separated list of keys in the dictionary
                to include in the signature.

        Returns:
            string

        """
        return processor_hash(
            ",".join(
                [
                    u"{0}={1}".format(signed_field, params[signed_field])
                    for signed_field in params["signed_field_names"].split(u",")
                ]
            )
        )
Esempio n. 2
0
    def _is_signature_valid(post_params):
        """
        Return a bool indicating  whether the client sent
        us a valid signature in the payment page request.
        """
        # Retrieve the list of signed fields
        signed_fields = post_params.get("signed_field_names").split(",")

        # Calculate the public signature
        hash_val = ",".join(["{0}={1}".format(key, post_params[key]) for key in signed_fields])
        public_sig = processor_hash(hash_val)

        return public_sig == post_params.get("signature")
Esempio n. 3
0
    def _is_signature_valid(post_params):
        """
        Return a bool indicating  whether the client sent
        us a valid signature in the payment page request.
        """
        # Retrieve the list of signed fields
        signed_fields = post_params.get('signed_field_names').split(',')

        # Calculate the public signature
        hash_val = ",".join(
            ["{0}={1}".format(key, post_params[key]) for key in signed_fields])
        public_sig = processor_hash(hash_val)

        return (public_sig == post_params.get('signature'))
Esempio n. 4
0
    def _signature(self, params):
        """
        Calculate the signature from a dictionary of params.

        NOTE: This method uses the processor's hashing method.  That method
        is a thin wrapper of standard library calls, and it seemed overly complex
        to rewrite that code in the test suite.

        Args:
            params (dict): Dictionary with a key 'signed_field_names',
                which is a comma-separated list of keys in the dictionary
                to include in the signature.

        Returns:
            string

        """
        return processor_hash(",".join([
            u"{0}={1}".format(signed_field, params[signed_field])
            for signed_field in params['signed_field_names'].split(u",")
        ]))
Esempio n. 5
0
    def response_post_params(cls, post_params):
        """
        Calculate the POST params we want to send back to the client.
        """

        if cls.PAYMENT_STATUS_RESPONSE == "success":
            decision = "ACCEPT"
        elif cls.PAYMENT_STATUS_RESPONSE == "decline":
            decision = "DECLINE"
        else:
            decision = "REJECT"

        resp_params = {
            # Indicate whether the payment was successful
            "decision": decision,

            # Reflect back parameters we were sent by the client
            "req_amount": post_params.get('amount'),
            "auth_amount": post_params.get('amount'),
            "req_reference_number": post_params.get('reference_number'),
            "req_transaction_uuid": post_params.get('transaction_uuid'),
            "req_access_key": post_params.get('access_key'),
            "req_transaction_type": post_params.get('transaction_type'),
            "req_override_custom_receipt_page": post_params.get('override_custom_receipt_page'),
            "req_payment_method": post_params.get('payment_method'),
            "req_currency": post_params.get('currency'),
            "req_locale": post_params.get('locale'),
            "signed_date_time": post_params.get('signed_date_time'),

            # Fake data
            "req_bill_to_address_city": "Boston",
            "req_card_number": "xxxxxxxxxxxx1111",
            "req_bill_to_address_state": "MA",
            "req_bill_to_address_line1": "123 Fake Street",
            "utf8": u"✓",
            "reason_code": "100",
            "req_card_expiry_date": "01-2018",
            "req_bill_to_forename": "John",
            "req_bill_to_surname": "Doe",
            "auth_code": "888888",
            "req_bill_to_address_postal_code": "02139",
            "message": "Request was processed successfully.",
            "auth_response": "100",
            "auth_trans_ref_no": "84997128QYI23CJT",
            "auth_time": "2014-08-18T110622Z",
            "bill_trans_ref_no": "84997128QYI23CJT",
            "auth_avs_code": "X",
            "req_bill_to_email": "*****@*****.**",
            "auth_avs_code_raw": "I1",
            "req_profile_id": "0000001",
            "req_card_type": "001",
            "req_bill_to_address_country": "US",
            "transaction_id": "4083599817820176195662",
        }

        # Indicate which fields we are including in the signature
        # Order is important
        signed_fields = [
            'transaction_id', 'decision', 'req_access_key', 'req_profile_id',
            'req_transaction_uuid', 'req_transaction_type', 'req_reference_number',
            'req_amount', 'req_currency', 'req_locale',
            'req_payment_method', 'req_override_custom_receipt_page',
            'req_bill_to_forename', 'req_bill_to_surname',
            'req_bill_to_email', 'req_bill_to_address_line1',
            'req_bill_to_address_city', 'req_bill_to_address_state',
            'req_bill_to_address_country', 'req_bill_to_address_postal_code',
            'req_card_number', 'req_card_type', 'req_card_expiry_date',
            'message', 'reason_code', 'auth_avs_code',
            'auth_avs_code_raw', 'auth_response', 'auth_amount',
            'auth_code', 'auth_trans_ref_no', 'auth_time',
            'bill_trans_ref_no', 'signed_field_names', 'signed_date_time'
        ]

        # if decision is decline , cancel or error then remove auth_amount from signed_field.
        # list and also delete from resp_params dict

        if decision in ["DECLINE", "CANCEL", "ERROR"]:
            signed_fields.remove('auth_amount')
            del resp_params["auth_amount"]

        # Add the list of signed fields
        resp_params['signed_field_names'] = ",".join(signed_fields)

        # Calculate the public signature
        hash_val = ",".join([
            "{0}={1}".format(key, resp_params[key])
            for key in signed_fields
        ])
        resp_params['signature'] = processor_hash(hash_val)

        return resp_params
Esempio n. 6
0
    def response_post_params(cls, post_params):
        """
        Calculate the POST params we want to send back to the client.
        """
        resp_params = {
            # Indicate whether the payment was successful
            "decision":
            "ACCEPT" if cls.PAYMENT_STATUS_RESPONSE == "success" else "REJECT",

            # Reflect back parameters we were sent by the client
            "req_amount":
            post_params.get('amount'),
            "auth_amount":
            post_params.get('amount'),
            "req_reference_number":
            post_params.get('reference_number'),
            "req_transaction_uuid":
            post_params.get('transaction_uuid'),
            "req_access_key":
            post_params.get('access_key'),
            "req_transaction_type":
            post_params.get('transaction_type'),
            "req_override_custom_receipt_page":
            post_params.get('override_custom_receipt_page'),
            "req_payment_method":
            post_params.get('payment_method'),
            "req_currency":
            post_params.get('currency'),
            "req_locale":
            post_params.get('locale'),
            "signed_date_time":
            post_params.get('signed_date_time'),

            # Fake data
            "req_bill_to_address_city":
            "Boston",
            "req_card_number":
            "xxxxxxxxxxxx1111",
            "req_bill_to_address_state":
            "MA",
            "req_bill_to_address_line1":
            "123 Fake Street",
            "utf8":
            u"✓",
            "reason_code":
            "100",
            "req_card_expiry_date":
            "01-2018",
            "req_bill_to_forename":
            "John",
            "req_bill_to_surname":
            "Doe",
            "auth_code":
            "888888",
            "req_bill_to_address_postal_code":
            "02139",
            "message":
            "Request was processed successfully.",
            "auth_response":
            "100",
            "auth_trans_ref_no":
            "84997128QYI23CJT",
            "auth_time":
            "2014-08-18T110622Z",
            "bill_trans_ref_no":
            "84997128QYI23CJT",
            "auth_avs_code":
            "X",
            "req_bill_to_email":
            "*****@*****.**",
            "auth_avs_code_raw":
            "I1",
            "req_profile_id":
            "0000001",
            "req_card_type":
            "001",
            "req_bill_to_address_country":
            "US",
            "transaction_id":
            "4083599817820176195662",
        }

        # Indicate which fields we are including in the signature
        # Order is important
        signed_fields = [
            'transaction_id', 'decision', 'req_access_key', 'req_profile_id',
            'req_transaction_uuid', 'req_transaction_type',
            'req_reference_number', 'req_amount', 'req_currency', 'req_locale',
            'req_payment_method', 'req_override_custom_receipt_page',
            'req_bill_to_forename', 'req_bill_to_surname', 'req_bill_to_email',
            'req_bill_to_address_line1', 'req_bill_to_address_city',
            'req_bill_to_address_state', 'req_bill_to_address_country',
            'req_bill_to_address_postal_code', 'req_card_number',
            'req_card_type', 'req_card_expiry_date', 'message', 'reason_code',
            'auth_avs_code', 'auth_avs_code_raw', 'auth_response',
            'auth_amount', 'auth_code', 'auth_trans_ref_no', 'auth_time',
            'bill_trans_ref_no', 'signed_field_names', 'signed_date_time'
        ]

        # Add the list of signed fields
        resp_params['signed_field_names'] = ",".join(signed_fields)

        # Calculate the public signature
        hash_val = ",".join(
            ["{0}={1}".format(key, resp_params[key]) for key in signed_fields])
        resp_params['signature'] = processor_hash(hash_val)

        return resp_params