diff --git a/mangopay/constants.py b/mangopay/constants.py index 43010d5..f19194b 100644 --- a/mangopay/constants.py +++ b/mangopay/constants.py @@ -287,7 +287,8 @@ ("BANK_WIRE", "bank_wire", "Bank Wire"), ("APPLEPAY", "applepay", "Applepay"), ("GOOGLEPAY", "googlepay", "Googlepay"), - ("MBWAY", "mbway", "Mbway") + ("MBWAY", "mbway", "Mbway"), + ("PAYPAL", "paypal", "PayPal") ) CARD_STATUS_CHOICES = Choices( diff --git a/mangopay/resources.py b/mangopay/resources.py index 0478d5d..f651ccd 100644 --- a/mangopay/resources.py +++ b/mangopay/resources.py @@ -692,6 +692,29 @@ class Meta: } +@python_2_unicode_compatible +class PayPalWebPayIn(PayIn): + creation_date = DateTimeField(api_name='CreationDate') + author = ForeignKeyField(User, api_name='AuthorId', required=True) + debited_funds = MoneyField(api_name='DebitedFunds', required=True) + fees = MoneyField(api_name='Fees', required=True) + credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True) + return_url = CharField(api_name='ReturnURL', required=True) + redirect_url = CharField(api_name='RedirectURL') + statement_descriptor = CharField(api_name='StatementDescriptor') + shipping = ShippingField(api_name='Shipping') + line_items = ListField(api_name='LineItems', required=True) + culture = CharField(api_name='Culture') + + class Meta: + verbose_name = 'payin' + verbose_name_plural = 'payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/paypal', + SelectQuery.identifier: '/payins' + } + + @python_2_unicode_compatible class PayconiqPayIn(PayIn): author = ForeignKeyField(User, api_name='AuthorId', required=True) @@ -743,6 +766,7 @@ class Meta: InsertQuery.identifier: '/payins/googlepay/direct' } + class MbwayPayIn(PayIn): creation_date = DateTimeField(api_name='CreationDate') author = ForeignKeyField(User, api_name='AuthorId', required=True) @@ -759,6 +783,7 @@ class Meta: SelectQuery.identifier: '/payins' } + class CardWebPayIn(PayIn): author = ForeignKeyField(User, api_name='AuthorId', required=True) credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True) diff --git a/mangopay/utils.py b/mangopay/utils.py index 40d4415..62a8ee4 100644 --- a/mangopay/utils.py +++ b/mangopay/utils.py @@ -923,3 +923,25 @@ def to_api_json(self): "PayinCaptureId": self.payin_capture_id, "PayinComplementId": self.payin_complement_id } + + +class LineItem(object): + def __init__(self, name=None, quantity=None, unit_amount=None, tax_amount=None, description=None): + self.name = name + self.quantity = quantity + self.unit_amount = unit_amount + self.tax_amount = tax_amount + self.description = description + + def __str__(self): + return 'LineItem: %s %s %s %s %s' % \ + (self.name, self.quantity, self.unit_amount, self.tax_amount, self.description) + + def to_api_json(self): + return { + "Name": self.name, + "Quantity": self.quantity, + "UnitAmount": self.unit_amount, + "TaxAmount": self.tax_amount, + "Description": self.description + } diff --git a/tests/test_payins.py b/tests/test_payins.py index d1deeb7..37c6ec2 100644 --- a/tests/test_payins.py +++ b/tests/test_payins.py @@ -9,9 +9,9 @@ from mangopay.resources import DirectDebitDirectPayIn, Mandate, ApplepayPayIn, GooglepayPayIn, \ RecurringPayInRegistration, \ - RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn + RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn, PayPalWebPayIn from mangopay.utils import (Money, ShippingAddress, Shipping, Billing, Address, SecurityInfo, ApplepayPaymentData, - GooglepayPaymentData, DebitedBankAccount, BrowserInfo) + GooglepayPaymentData, DebitedBankAccount, BrowserInfo, LineItem) from tests import settings from tests.resources import (Wallet, PayIn, DirectPayIn, BankWirePayIn, BankWirePayInExternalInstruction, PayPalPayIn, @@ -1157,3 +1157,48 @@ def test_PayIns_MbwayDirect_Create(self): self.assertEqual("DIRECT", result.execution_type) self.assertEqual("MBWAY", result.payment_type) self.assertEqual("PAYIN", result.type) + + def test_PayIns_PayPalWeb_Create(self): + user = BaseTestLive.get_john(True) + + # create wallet + credited_wallet = Wallet() + credited_wallet.owners = (user,) + credited_wallet.currency = 'EUR' + credited_wallet.description = 'WALLET IN EUR' + credited_wallet = Wallet(**credited_wallet.save()) + + pay_in = PayPalWebPayIn() + pay_in.author = user + pay_in.credited_wallet = credited_wallet + pay_in.fees = Money() + pay_in.fees.amount = 100 + pay_in.fees.currency = "EUR" + pay_in.debited_funds = Money() + pay_in.debited_funds.amount = 1000 + pay_in.debited_funds.currency = "EUR" + pay_in.return_url = "http://mangopay.com" + + line_item = LineItem() + line_item.name = "test" + line_item.quantity = 1 + line_item.unit_amount = 1000 + line_item.tax_amount = 0 + line_item.description = "test" + pay_in.line_items = [line_item] + + pay_in.statement_descriptor = "test" + pay_in.tag = "test tag" + + result = PayPalWebPayIn(**pay_in.save()) + fetched = PayPalWebPayIn().get(result.id) + + self.assertIsNotNone(result) + self.assertIsNotNone(fetched) + self.assertEqual(result.id, fetched.id) + + self.assertEqual("CREATED", result.status) + self.assertEqual("REGULAR", result.nature) + self.assertEqual("WEB", result.execution_type) + self.assertEqual("PAYPAL", result.payment_type) + self.assertEqual("PAYIN", result.type)