Changeset 12494 for main


Ignore:
Timestamp:
19 Jan 2015, 13:25:25 (10 years ago)
Author:
uli
Message:

First working test for external payment.

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

    r12454 r12494  
    7272STOCK_KEEPING_UNITS = {
    7373    "pcs": _("pieces"),
     74    "license": _("license"),
    7475    }
    7576
     
    11211122
    11221123
     1124class StandardItemAdapter(grok.Adapter):
     1125    grok.implements(ITransaction)
     1126    grok.adapts(IPaymentItem)
     1127
     1128
     1129def payment_item_to_transaction(item):
     1130    """Turn an IPaymentItem into an ITransaction
     1131    """
     1132    amount = Amount(currency=item.currency, total=item.amount)
     1133    description = item.title
     1134    item = Item(name=item.title, price=item.amount, currency=item.currency,
     1135                quantity=1, sku=_("license"))
     1136    item_list = ItemList(items=[item, ])
     1137    transaction = Transaction(
     1138        amount=amount, description=description, item_list=item_list)
     1139    return transaction
     1140
     1141
    11231142class PayPalCreditCardService(grok.GlobalUtility):
    11241143    grok.implements(IPaymentGatewayService)
     
    11791198        if credit_card is None:
    11801199            raise ValueError("Payer %s has no credit card." % payer.payer_id)
    1181         return None
     1200        transaction = payment_item_to_transaction(payment_item)
     1201        payment_dict = {
     1202            "intent": "sale",
     1203            "payer": {
     1204                "payment_method": "credit_card",
     1205                "funding_instruments": [{
     1206                    "credit_card_token": {
     1207                        "credit_card_id": credit_card.credit_card_id,
     1208                        "payer_id": payer.payer_id,
     1209                        }}]},
     1210            "transactions": [
     1211                transaction.to_dict()]
     1212            }
     1213        payment = paypalrestsdk.Payment(payment_dict)
     1214        return payment
    11821215
    11831216
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_paypal.py

    r12454 r12494  
    11981198        assert exception.message == 'Payer PAYER-123 has no credit card.'
    11991199
     1200    @external_paypal_test
     1201    def test_create_payment(self):
     1202        # we can actually create payments
     1203        service = PayPalCreditCardService()
     1204        site = self.create_site()
     1205        credit_card = self.get_credit_card()
     1206        result = service.store_credit_card(credit_card)
     1207        payer_id = result.payer_id
     1208        payer = FakePayer()
     1209        payer.payer_id = result.payer_id
     1210        payment_item = FakePaymentItem()
     1211        payment = service.create_payment(
     1212            payer=payer, payment_item=payment_item)
     1213        result = payment.create()
     1214        assert result is True
     1215
    12001216
    12011217class FunctionalPaypalTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.