Ignore:
Timestamp:
12 Jan 2015, 15:19:54 (10 years ago)
Author:
uli
Message:

Store credit card data really and externally.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/payments
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/paypal.py

    r12453 r12454  
    11421142        """Store `paypal_credit_card` in vault.
    11431143
    1144         Returns a credit card token in case of success.
     1144        Returns a credit card token in case of success. Otherwise an
     1145        IOError is raised.
    11451146
    11461147        `paypal_credit_card` must provide `ICreditCard`. The credit
    11471148        card created is stored at PayPal and gets a token stored
    1148         locally.
    1149 
    1150         If no `creditcards` are available in local site, we create a
    1151         container.
     1149        locally (in site['creditcards']).
     1150
     1151        If no `creditcards` folder is available in local site, we
     1152        create a new container.
    11521153        """
    11531154        site = grok.getSite()
    11541155        if not 'creditcards' in site:
    11551156            site['creditcards'] = grok.Container()
    1156         return
     1157        pp_credit_card = paypalrestsdk.CreditCard(
     1158            paypal_credit_card.to_dict())
     1159        result = pp_credit_card.create()
     1160        if not result:
     1161            # error
     1162            raise IOError(pp_credit_card.error)
     1163        result = CreditCardToken(
     1164            pp_credit_card.id, pp_credit_card.payer_id,
     1165            pp_credit_card.number, pp_credit_card.type,
     1166            pp_credit_card.expire_month, pp_credit_card.expire_year
     1167            )
     1168        site['creditcards'][pp_credit_card.payer_id] = result
     1169        return result
    11571170
    11581171    def create_payment(self, payer, payment_item,  payee=None):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_paypal.py

    r12453 r12454  
    11561156        assert service.get_credit_card(u'CARD2') is None
    11571157
    1158     def test_store_credit_card_no_credcard_container(self):
    1159         # a missing creditcards container is created on-the-fly
     1158    @external_paypal_test
     1159    def test_store_credit_card(self):
     1160        # we can (and must) store credit card data online.
    11601161        site = self.create_site()
    11611162        assert 'creditcards' not in site
    11621163        service = PayPalCreditCardService()
    11631164        credit_card = self.get_credit_card()
    1164         service.store_credit_card(credit_card)
     1165        result = service.store_credit_card(credit_card)
     1166        # a missing creditcards container is created on-the-fly
    11651167        assert 'creditcards' in site
     1168        assert ICreditCardToken.providedBy(result)
     1169        assert result.payer_id in site['creditcards']
     1170        assert site['creditcards'][result.payer_id] == result
     1171
     1172    @external_paypal_test
     1173    def test_store_credit_card_invalid(self):
     1174        # an exception is raised with invalid credit cards.
     1175        site = self.create_site()
     1176        service = PayPalCreditCardService()
     1177        credit_card = CreditCard(
     1178            number=u"12345678",
     1179            credit_card_type="visa",
     1180            expire_month=4,
     1181            expire_year=2012,
     1182            )
     1183        self.assertRaises(
     1184            IOError, service.store_credit_card, credit_card)
    11661185
    11671186    def test_create_payment_no_credictard(self):
Note: See TracChangeset for help on using the changeset viewer.