Ignore:
Timestamp:
20 Jan 2015, 05:57:59 (10 years ago)
Author:
uli
Message:

Adapt (nice) change in official Paypal API for ICreditCard.

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

    r12494 r12496  
    300300        )
    301301
    302     payer_id = schema.TextLine(
     302    external_customer_id = schema.TextLine(
    303303        title=u'Payer ID',
    304304        description=(u'A unique identifier for the credit card. This '
     
    390390          data. Required if using a stored credit card.
    391391
    392     `payer_id`: Unique identifier. If none is given, we assign a
    393           uuid. The uuid reads 'PAYER_<32 hex digits>'.
     392    `external_customer_id`: Unique identifier. If none is given, we
     393          assign a uuid. The uuid reads 'PAYER_<32 hex digits>'.
    394394
    395395    `number`: Credit card number. Numeric characters only with no
     
    426426    grok.implements(ICreditCard)
    427427
    428     def __init__(self, paypal_id=None, payer_id=None, number=None,
    429                  credit_card_type=None, expire_month=1, expire_year=2000,
    430                  cvv2=None, first_name=None, last_name=None,
    431                  billing_address=None, state=None, paypal_valid_until=None):
     428    def __init__(self, paypal_id=None, external_customer_id=None,
     429                 number=None, credit_card_type=None, expire_month=1,
     430                 expire_year=2000, cvv2=None, first_name=None,
     431                 last_name=None, billing_address=None, state=None,
     432                 paypal_valid_until=None):
    432433        if not re.match('^[0-9]+$', number):
    433434            raise ValueError("Credit card number may "
    434435                             "not contain non-numbers.")
    435         if payer_id is None:
    436             payer_id = u'PAYER_' + unicode(uuid.uuid4().hex)
     436        if external_customer_id is None:
     437            external_customer_id = u'PAYER_' + unicode(uuid.uuid4().hex)
    437438        self.paypal_id = paypal_id
    438         self.payer_id = payer_id
     439        self.external_customer_id = external_customer_id
    439440        self.number = number
    440441        self.credit_card_type = credit_card_type
     
    11891190
    11901191    def create_payment(self, payer, payment_item,  payee=None):
     1192        """Create a creditcard payment.
     1193
     1194        XXX: payer_id is deprecated by paypal: use
     1195        XXX: external_customer_id instead (also when creating credit cards).
     1196        XXX: This is a Good Thing(tm) because `payer_id` is already used in
     1197        XXX: some parts of the API for PayPal-assigned values.
     1198        """
    11911199        if not IPayer.providedBy(payer):
    11921200            payer = IPayer(payer)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_paypal.py

    r12494 r12496  
    286286            )
    287287        assert credit_card.paypal_id is None
    288         assert credit_card.payer_id is not None
     288        assert credit_card.external_customer_id is not None
    289289        assert credit_card.number == u"12345678"
    290290        assert credit_card.credit_card_type == "visa"
     
    298298        assert credit_card.paypal_valid_until is None
    299299
    300     def test_payer_id_given(self):
    301         # we do not override given payer ids
     300    def test_external_customer_id_given(self):
     301        # we do not override given curstomer ids
    302302        credit_card = CreditCard(
    303303            number=u"12345678",
     
    305305            expire_month=4,
    306306            expire_year=2012,
    307             payer_id=u'MySpecialPayerId',
    308             )
    309         assert credit_card.payer_id == u'MySpecialPayerId'
    310 
    311     def test_payer_id_not_given(self):
    312         # in case no payer id is given, we generate one
     307            external_customer_id=u'MySpecialPayerId',
     308            )
     309        assert credit_card.external_customer_id == u'MySpecialPayerId'
     310
     311    def test_external_customer_id_not_given(self):
     312        # in case no customer id is given, we generate one
    313313        credit_card = CreditCard(
    314314            number=u"12345678",
     
    317317            expire_year=2012,
    318318            )
    319         # our payer ids contain a leading 'PAYER_' and 32 hex digits
    320         assert re.match('PAYER_[0-9a-f]{32}$', credit_card.payer_id)
     319        # our customer ids contain a leading 'PAYER_' and 32 hex digits
     320        assert re.match(
     321            'PAYER_[0-9a-f]{32}$', credit_card.external_customer_id)
    321322
    322323    def test_number_is_checked(self):
     
    340341        credit_card = CreditCard(
    341342            credit_card_type=u"visa",
    342             payer_id=u"PAYER_0123456789012345678901",
     343            external_customer_id=u"PAYER_0123456789012345678901",
    343344            number=u"4417119669820331",
    344345            expire_month=11,
     
    353354                "type": u"visa",
    354355                "number": u"4417119669820331",
    355                 "payer_id": u"PAYER_0123456789012345678901",
     356                "external_customer_id": u"PAYER_0123456789012345678901",
    356357                "expire_month": u"11",
    357358                "expire_year": u"2018",
     
    12131214        result = payment.create()
    12141215        assert result is True
     1216       
     1217        ###
     1218        ### hier gehts weiter
    12151219
    12161220
Note: See TracChangeset for help on using the changeset viewer.