示例#1
0
 def test_constructor(self):
     opts = dict(number='x', year=2000, month=1, verification_value='123')
     self.assertRaises(TypeError, lambda: CreditCard(**opts))
     self.assertRaises(TypeError, lambda: CreditCard(first_name='x', **opts))
     self.assertRaises(TypeError, lambda: CreditCard(last_name='y', **opts))
     c = CreditCard(first_name='x', last_name='y', **opts)
     self.assertEqual(c.cardholders_name, None)
     c2 = CreditCard(cardholders_name='z', **opts)
     self.assertEqual(c2.cardholders_name, 'z')
示例#2
0
    def test_3ds_verifysig_xml(self):

        expected = """<?xml version="1.0" encoding="UTF-8" ?>
<request timestamp="20100625172305" type="3ds-verifysig">
  <merchantid>thestore</merchantid>
  <account>theaccount</account>
  <orderid>1</orderid>
  <amount currency="GBP">2499</amount>
  <card>
    <number>4903034000057389</number>
    <expdate>0714</expdate>
    <chname>Mickey Mouse</chname>
    <type>VISA</type>
  </card>
  <pares>xyz</pares>
  <sha1hash>272d8dde0bf34a0e744f696f2860a7894b687cf7</sha1hash>
</request>"""

        integration = self.mk_integration()
        gateway = self.mk_gateway()
        card = CreditCard(first_name='Mickey',
                          last_name='Mouse',
                          month=7,
                          year=2014,
                          number='4903034000057389',
                          verification_value='123',
                          )
        gateway.validate_card(card)
        actual_xml = integration.build_3ds_verifysig_xml('xyz',
                                                         {'order_id': 1,
                                                          'amount': Decimal('24.99'),
                                                          'card': card,
                                                          'timestamp': datetime(2010,6, 25, 17, 23, 5),
                                                          })
        self.assertXMLEqual(actual_xml, expected)
示例#3
0
 def get_amex_card(self):
     return CreditCard(first_name='Donald',
                       last_name='Duck',
                       month=8,
                       year=2035,
                       number='374101012180018',
                       verification_value='4567',
                       )
示例#4
0
 def get_visa_card(self):
     return CreditCard(first_name='Mickey',
                       last_name='Mouse',
                       month=7,
                       year=2035,
                       number='4903034000057389',
                       verification_value='123',
                       )
示例#5
0
def decode_credit_card_from_dict(dct):
    if '__credit_card__' in dct:
        d = dct.copy()
        d.pop('__credit_card__')
        d.pop('card_type')
        retval = CreditCard(**d)
        card_type = dct.get('card_type',
                            None)  # put there by Gateway.validate_card
        if card_type is not None:
            # Get the credit card class with this name
            retval.card_type = getattr(billing.utils.credit_card, card_type)
        return retval
    return dct
示例#6
0
    def get_credit_card(self):
        """
        Returns a CreditCard from the submitted (cleaned) data.

        If gateway was passed to the form constructor, the gateway.validate_card
        method will be called - which can throw CardNotSupported, and will also
        add the attribute 'card_type' which is the CreditCard subclass if it is
        successful.
        """
        card = CreditCard(**self.cleaned_data)
        if self.gateway is not None:
            self.gateway.validate_card(card)
        return card
示例#7
0
 def _get_test_cards(self):
     cards = []
     card_dicts = settings.MERCHANT_SETTINGS['global_iris']['TEST_CARDS']
     for card_dict in card_dicts:
         card_type = card_dict['TYPE']
         d = dict(first_name= 'Test',
                  last_name= 'Test',
                  month=1,
                  year=datetime.now().year + 2,
                  number=card_dict['NUMBER'],
                  verification_value="1234" if card_type == "AMEX" else "123")
         card = CreditCard(**d)
         card.expected_response_code = card_dict['RESPONSE_CODE']
         cards.append(card)
     return cards
示例#8
0
 def test_signature(self):
     gateway = self.mk_gateway()
     card = CreditCard(number='5105105105105100',
                       first_name='x',
                       last_name='x',
                       year='1', month='1',
                       verification_value='123')
     gateway.validate_card(card)
     config = gateway.get_config(card)
     sig = gateway.get_standard_signature(
         {
             'timestamp':'20010403123245',
             'amount_normalized':'29900',
             'order_id': 'ORD453-11',
             'currency': 'GBP',
             'card': card,
             }, config)
     self.assertEqual(sig, "9e5b49f4df33b52efa646cce1629bcf8e488f7bb")
示例#9
0
def process_credit_card(request):
    if request.method == 'POST':
        form = CreditCardForm(request.POST)
        if form.is_valid():
            paypal_provider = get_gateway("pay_pal")
            cc = CreditCard(first_name=form.cleaned_data['first_name'],
                            last_name=form.cleaned_data['last_name'],
                            month=form.cleaned_data['month'],
                            year=form.cleaned_data['year'],
                            number=form.cleaned_data['number'],
                            verification_value=form.cleaned_data['verify_val'])
            basket = Basket.objects.get(user=request.user)
            total_price = get_total_price(basket, request)
            paypal_provider.purchase(total_price,
                                     cc,
                                     options={"request": request})
            #  PayPalFailure('Security header is not valid')
            current_user = request.user.customer
            for item in basket.basket_items.all():
                current_user.items_history.add(item)
            basket.basket_items.clear()
            current_user.discounts.clear()
    return render(request, "basket/payment_done.html",
                  {"success": "Successfully purchased!"})
示例#10
0
    def test_request_xml(self):
        gateway = self.mk_gateway()
        card = CreditCard(first_name='Mickey',
                          last_name='Mouse',
                          month=7,
                          year=2014,
                          number='4903034000057389',
                          verification_value='123',
                          )
        gateway.validate_card(card)
        data = {
                'timestamp': datetime(2001, 4, 27, 12, 45, 23),
                'order_id': '345',
                'amount': Decimal('20.00'),
                'card': card,
                'customer': '567',
                'billing_address': {
                    'street_address': "45 The Way",
                    'post_code': "ABC 123",
                    'country': 'GB',
                    },
                'product_id': '678',
                'customer_ip_address': '123.4.6.23',
                'varref': 'abc',
                }

        xml = gateway.build_xml(data)

        self.assertXMLEqual(u"""<?xml version="1.0" encoding="UTF-8" ?>
<request timestamp="20010427124523" type="auth">
  <merchantid>thestore</merchantid>
  <account>theaccount</account>
  <channel>ECOM</channel>
  <orderid>345</orderid>
  <amount currency="GBP">2000</amount>
  <card>
    <number>4903034000057389</number>
    <expdate>0714</expdate>
    <chname>Mickey Mouse</chname>
    <type>VISA</type>
    <cvn>
      <number>123</number>
      <presind>1</presind>
    </cvn>
  </card>
  <autosettle flag="1" />
  <tssinfo>
    <custnum>567</custnum>
    <prodid>678</prodid>
    <varref>abc</varref>
    <custipaddress>123.4.6.23</custipaddress>
    <address type="billing">
      <code>123|45</code>
      <country>GB</country>
    </address>
  </tssinfo>
  <sha1hash>eeaeaf2751a86edcf0d77e906b2daa08929e7cbe</sha1hash>
</request>""".encode('utf-8'), xml)

        # Test when we have MPI data (in the format returned
        # from GlobalIris3dsVerifySig.proceed_with_auth)
        mpi_data = {'mpi':{'eci': '5',
                           'xid': 'crqAeMwkEL9r4POdxpByWJ1/wYg=',
                           'cavv': 'AAABASY3QHgwUVdEBTdAAAAAAAA=',
                    }}
        data.update(mpi_data)

        xml2 = gateway.build_xml(data)

        self.assertXMLEqual(u"""<?xml version="1.0" encoding="UTF-8" ?>
<request timestamp="20010427124523" type="auth">
  <merchantid>thestore</merchantid>
  <account>theaccount</account>
  <channel>ECOM</channel>
  <orderid>345</orderid>
  <amount currency="GBP">2000</amount>
  <card>
    <number>4903034000057389</number>
    <expdate>0714</expdate>
    <chname>Mickey Mouse</chname>
    <type>VISA</type>
    <cvn>
      <number>123</number>
      <presind>1</presind>
    </cvn>
  </card>
  <autosettle flag="1" />
  <mpi>
    <eci>5</eci>
    <cavv>AAABASY3QHgwUVdEBTdAAAAAAAA=</cavv>
    <xid>crqAeMwkEL9r4POdxpByWJ1/wYg=</xid>
  </mpi>
  <tssinfo>
    <custnum>567</custnum>
    <prodid>678</prodid>
    <varref>abc</varref>
    <custipaddress>123.4.6.23</custipaddress>
    <address type="billing">
      <code>123|45</code>
      <country>GB</country>
    </address>
  </tssinfo>
  <sha1hash>eeaeaf2751a86edcf0d77e906b2daa08929e7cbe</sha1hash>
</request>""".encode('utf-8'), xml2)