コード例 #1
0
 def setUp(self):
     self.facade = Facade()
     self.card = Bankcard(card_number=CARD_VISA,
                          expiry_date='1015',
                          name="Frankie",
                          cvv="123",
                          start_date="1010")
コード例 #2
0
 def test_refund_request(self):
     self.facade.gateway._fetch_response_xml = Mock(
         return_value=fixtures.SAMPLE_RESPONSE)
     card = Bankcard('1000350000000007', '10/13', cvv='345')
     ref = self.facade.refund('100005', D('123.22'), card)
     txn = OrderTransaction.objects.filter(order_number='100005')[0]
     self.assertEquals('refund', txn.method)
コード例 #3
0
 def test_zero_amount_raises_exception(self):
     card = Bankcard(card_number=CARD_VISA,
                     expiry_date='1015',
                     name="Frankie",
                     cvv="123",
                     start_date="1010")
     with self.assertRaises(UnableToTakePayment):
         self.facade.authorise('1000', 0, card)
コード例 #4
0
    def _test_adapter(self):
        bankcard = Bankcard(card_number='1000011000000005',
                            expiry_date='01/13')

        dc_facade = Facade()
        reference = dc_facade.debit('102910', D('23.00'), bankcard)
        print reference

        OrderTransaction.objects.get(order_number='102910')
コード例 #5
0
 def test_empty_issue_date_is_allowed(self):
     with patch('requests.post') as post:
         post.return_value = self.create_mock_response(
             SAMPLE_SUCCESSFUL_RESPONSE)
         card = Bankcard(card_number=CARD_VISA,
                         expiry_date='1015',
                         name="Frankie",
                         cvv="123")
         txn_ref = self.facade.authorise('1000', 1.23, card)
         self.assertEquals(self.dps_txn_ref, txn_ref['txn_reference'])
コード例 #6
0
 def test_pre_request_creates_txn_model(self):
     self.facade.gateway._fetch_response_xml = Mock(
         return_value=fixtures.SAMPLE_RESPONSE)
     card = Bankcard('1000350000000007', '10/13', cvv='345')
     self.facade.pre_authorise('100001', D('123.22'), card)
     txn = OrderTransaction.objects.filter(order_number='100001')[0]
     self.assertEquals('pre', txn.method)
     self.assertEquals(D('123.22'), txn.amount)
     self.assertTrue(len(txn.request_xml) > 0)
     self.assertTrue(len(txn.response_xml) > 0)
コード例 #7
0
 def test_unicode_handling(self):
     self.facade.gateway._fetch_response_xml = Mock(
         return_value=fixtures.SAMPLE_RESPONSE)
     card = Bankcard('1000350000000007', '10/13', cvv='345')
     self.facade.pre_authorise(
         '1234',
         D('10.00'),
         card,
         the3rdman_data={'customer_info': {
             'surname': u'Smörgåsbord'
         }})
コード例 #8
0
    def test_invalid_request_exception_raised_for_error(self):
        response_xml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <datacash_reference>21859999000005679</datacash_reference>
    <information>This vTID is not configured to process pre-registered card transactions.</information>
    <merchantreference>123403</merchantreference>
    <reason>Prereg: Merchant Not Subscribed</reason>
    <status>251</status>
    <time>1074692433</time>
</Response>"""
        self.facade.gateway._fetch_response_xml = Mock(
            return_value=response_xml)
        card = Bankcard('1000350000000007', '10/13', cvv='345')
        with self.assertRaises(InvalidGatewayRequestError):
            self.facade.pre_authorise('100001', D('123.22'), card)
コード例 #9
0
    def test_second_fulfill_has_merchant_ref(self):
        # Initial pre-auth
        self.facade.gateway._fetch_response_xml = Mock(
            return_value=fixtures.SAMPLE_RESPONSE)
        card = Bankcard('1000350000000007', '10/13', cvv='345')
        ref = self.facade.pre_authorise('1234', D('100.00'), card)
        txn = OrderTransaction.objects.get(datacash_reference=ref)

        # First fulfill
        self.facade.gateway._fetch_response_xml = Mock(
            return_value=fixtures.SAMPLE_SUCCESSFUL_FULFILL_RESPONSE)
        self.facade.fulfill_transaction('1234', D('50.00'),
                                        txn.datacash_reference, txn.auth_code)

        self.facade.fulfill_transaction('1234', D('40.00'),
                                        txn.datacash_reference, txn.auth_code)
        fulfill_txn = OrderTransaction.objects.get(order_number='1234',
                                                   amount=D('40.00'))
        self.assertTrue('merchantreference' in fulfill_txn.request_xml)
コード例 #10
0
    def test_transaction_declined_exception_raised_for_decline(self):
        response_xml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <CardTxn>
        <authcode>DECLINED</authcode>
        <card_scheme>Mastercard</card_scheme>
        <country>United Kingdom</country>
    </CardTxn>
    <datacash_reference>4400200045583767</datacash_reference>
    <merchantreference>AA004630</merchantreference>
    <mode>TEST</mode>
    <reason>DECLINED</reason>
    <status>7</status>
    <time>1169223906</time>
</Response>"""
        self.facade.gateway._fetch_response_xml = Mock(
            return_value=response_xml)
        card = Bankcard('1000350000000007', '10/13', cvv='345')
        with self.assertRaises(UnableToTakePayment):
            self.facade.pre_authorise('100001', D('123.22'), card)
コード例 #11
0
 def test_pre_request_uses_billing_address_fields(self):
     mock = Mock(return_value=fixtures.SAMPLE_RESPONSE)
     self.facade.gateway._fetch_response_xml = mock
     card = Bankcard('1000350000000007', '10/13', cvv='345')
     address = MockBillingAddress(line1='1 Egg Street',
                                  line2='Farmville',
                                  line4='Greater London',
                                  postcode='N1 8RT')
     self.facade.pre_authorise('100001',
                               D('123.22'),
                               card,
                               billing_address=address)
     request_xml = mock.call_args[0][0]
     self.assertXmlElementEquals(
         request_xml, '1 Egg Street',
         'Request.Transaction.CardTxn.Card.Cv2Avs.street_address1')
     self.assertXmlElementEquals(
         request_xml, 'Farmville',
         'Request.Transaction.CardTxn.Card.Cv2Avs.street_address2')
     self.assertXmlElementEquals(
         request_xml, 'N1 8RT',
         'Request.Transaction.CardTxn.Card.Cv2Avs.postcode')
コード例 #12
0
 def setUp(self):
     self.card = Bankcard(
         card_number='4111111111111111',
         name='John Doe',
         expiry_date='12/13',
     )
コード例 #13
0
 def test_auth_request_with_integer_cvv(self):
     self.facade.gateway._fetch_response_xml = Mock(
         return_value=fixtures.SAMPLE_RESPONSE)
     card = Bankcard('1000350000000007', '10/13', cvv=345)
     self.facade.authorise('100001', D('123.22'), card)
コード例 #14
0
 def test_zero_amount_for_auth_raises_exception(self):
     card = Bankcard('1000350000000007', '10/13', cvv='345')
     with self.assertRaises(UnableToTakePayment):
         self.facade.authorise('1234', D('0.00'), card)
コード例 #15
0
 def test_auth_request_returns_datacash_ref(self):
     self.facade.gateway._fetch_response_xml = Mock(
         return_value=fixtures.SAMPLE_RESPONSE)
     card = Bankcard('1000350000000007', '10/13', cvv='345')
     ref = self.facade.authorise('100001', D('123.22'), card)
     self.assertEquals('3000000088888888', ref)