Skip to content

Commit

Permalink
implemented paypal web payin
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Sep 5, 2023
1 parent d700b5e commit 5134814
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mangopay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 25 additions & 0 deletions mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions mangopay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
49 changes: 47 additions & 2 deletions tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 5134814

Please sign in to comment.