示例#1
0
    def test_success_cc_charge_request(self):

        # 1: get a token
        # on live, this step --MUST-- be performed by the web
        # application through the javascript library.
        token = self.get_token(random.choice(fixtures.CC_ACCEPTED),
                               SANDBOX_CLIENT_KEY)

        # 2: Create a sandbox gateway
        gateway = veritrans.VTDirect(SANDBOX_SERVER_KEY, sandbox_mode=True)

        # 3: Create a charge request
        cc_payment = payment_types.CreditCard(
            bank=self.expected['credit_card']['bank'], token_id=token)

        charge_req = request.ChargeRequest(
            charge_type=cc_payment,
            transaction_details=self.trans_details,
            customer_details=self.cust_details,
            item_details=self.item_details)

        # 4: Submit our request
        resp = gateway.submit_charge_request(charge_req)

        self.assertIsInstance(resp, response.CreditCardChargeResponse)
        self.assertEqual(status.SUCCESS, resp.status_code)
示例#2
0
    def test_accept_challenged_charge_request(self):
        '''
        Verify that we can accept challenged charge requests.
        '''
        # 1: get a token
        # on live, this step --MUST-- be performed by the web
        # application through the javascript library.
        token = self.get_token(random.choice(fixtures.CC_CHALLENGED_FDS),
                               SANDBOX_CLIENT_KEY)

        # 2: Create a sandbox gateway
        gateway = veritrans.VTDirect(SANDBOX_SERVER_KEY, sandbox_mode=True)

        # 3: Create a charge request
        cc_payment = payment_types.CreditCard(
            bank=self.expected['credit_card']['bank'], token_id=token)

        charge_req = request.ChargeRequest(
            charge_type=cc_payment,
            transaction_details=self.trans_details,
            customer_details=self.cust_details,
            item_details=self.item_details)

        # 4: Submit charge request
        #     - verify we get a status_code of CHALLENGE back
        #     - verify that we are returned a CreditCardChargeResponse
        resp = gateway.submit_charge_request(charge_req)

        self.assertIsInstance(resp, response.CreditCardChargeResponse)
        self.assertEqual(status.CHALLENGE, resp.status_code)

        # 5: Lookup the status of the transaction using the response
        #     - verify can use CreditCareChargeResponse can as a StatusRequest
        #     - verify we get a StatusResponse back
        #     - verify the status_code is still CHALLENGE
        status_resp = gateway.submit_status_request(resp)
        self.assertIsInstance(status_resp, response.StatusResponse)
        self.assertEqual(status_resp.status_code, status.CHALLENGE)

        # 6: Approve the transaction!
        #     - verify can build an ApprovalRequest
        #     - verify we get an ApprovalResponse back
        #     - verify the status_code is now SUCCESS
        approval_req = request.ApprovalRequest(status_resp.order_id)
        approval_resp = gateway.submit_approval_request(approval_req)

        self.assertIsInstance(approval_resp, response.ApproveResponse)
        self.assertEqual(approval_resp.status_code, status.SUCCESS)
    def test_serialization(self):
        '''
        This test covers the serialization of ChargeRequest and all of it's
        subentities.
        '''
        expected = fixtures.CC_REQUEST

        cc_payment = payment_types.CreditCard(
            bank=expected['credit_card']['bank'],
            token_id=expected['credit_card']['token_id'],
            bins=expected['credit_card']['bins'])
        trans_details = request.TransactionDetails(
            order_id=expected['transaction_details']['order_id'],
            gross_amount=expected['transaction_details']['gross_amount'])
        cust_details = request.CustomerDetails(
            first_name=expected['customer_details']['first_name'],
            last_name=expected['customer_details']['last_name'],
            email=expected['customer_details']['email'],
            phone=expected['customer_details']['phone'],
            billing_address=request.Address(
                **expected['customer_details']['billing_address']),
            shipping_address=request.Address(
                **expected['customer_details']['shipping_address'])
            )
        item_details = [request.ItemDetails(item_id=item['id'],
                                            price=item['price'],
                                            quantity=item['quantity'],
                                            name=item['name'])
                        for item
                        in expected['item_details']]

        charge_req = request.ChargeRequest(charge_type=cc_payment,
                                           transaction_details=trans_details,
                                           customer_details=cust_details,
                                           item_details=item_details)

        actual = charge_req.serialize()

        self.assertEqual(actual, expected)