Changeset 12494
- Timestamp:
- 19 Jan 2015, 13:25:25 (10 years ago)
- 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 72 72 STOCK_KEEPING_UNITS = { 73 73 "pcs": _("pieces"), 74 "license": _("license"), 74 75 } 75 76 … … 1121 1122 1122 1123 1124 class StandardItemAdapter(grok.Adapter): 1125 grok.implements(ITransaction) 1126 grok.adapts(IPaymentItem) 1127 1128 1129 def 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 1123 1142 class PayPalCreditCardService(grok.GlobalUtility): 1124 1143 grok.implements(IPaymentGatewayService) … … 1179 1198 if credit_card is None: 1180 1199 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 1182 1215 1183 1216 -
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_paypal.py
r12454 r12494 1198 1198 assert exception.message == 'Payer PAYER-123 has no credit card.' 1199 1199 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 1200 1216 1201 1217 class FunctionalPaypalTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.