diff --git a/mangopay/constants.py b/mangopay/constants.py index 43010d5..57dc390 100644 --- a/mangopay/constants.py +++ b/mangopay/constants.py @@ -47,7 +47,8 @@ TRANSACTION_TYPE_CHOICES = Choices( ('PAYIN', 'payin', 'Pay In'), ('PAYOUT', 'payout', 'Pay out'), - ('TRANSFER', 'transfer', 'Transfer') + ('TRANSFER', 'transfer', 'Transfer'), + ('CARD_VALIDATION', 'card_validation', 'Card validation') ) NATURE_CHOICES = Choices( @@ -172,11 +173,20 @@ ('DEPOSIT_PREAUTHORIZATION_CREATED', 'deposit_preauthorization_created', 'Deposit Preauthorization Created'), ('DEPOSIT_PREAUTHORIZATION_FAILED', 'deposit_preauthorization_failed', 'Deposit Preauthorization Failed'), - ('DEPOSIT_PREAUTHORIZATION_PAYMENT_WAITING', 'deposit_preauthorization_payment_waiting', 'Deposit Preauthorization Payment Waiting'), - ('DEPOSIT_PREAUTHORIZATION_PAYMENT_EXPIRED', 'deposit_preauthorization_payment_expired', 'Deposit Preauthorization Payment Expired'), - ('DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCEL_REQUESTED', 'deposit_preauthorization_payment_cancel_requested', 'Deposit Preauthorization Payment Cancel Requested'), - ('DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCELED', 'deposit_preauthorization_payment_canceled', 'Deposit Preauthorization Payment Canceled'), - ('DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED', 'deposit_preauthorization_payment_validated', 'Deposit Preauthorization Payment Validated') + ('DEPOSIT_PREAUTHORIZATION_PAYMENT_WAITING', 'deposit_preauthorization_payment_waiting', + 'Deposit Preauthorization Payment Waiting'), + ('DEPOSIT_PREAUTHORIZATION_PAYMENT_EXPIRED', 'deposit_preauthorization_payment_expired', + 'Deposit Preauthorization Payment Expired'), + ('DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCEL_REQUESTED', 'deposit_preauthorization_payment_cancel_requested', + 'Deposit Preauthorization Payment Cancel Requested'), + ('DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCELED', 'deposit_preauthorization_payment_canceled', + 'Deposit Preauthorization Payment Canceled'), + ('DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED', 'deposit_preauthorization_payment_validated', + 'Deposit Preauthorization Payment Validated'), + + ('CARD_VALIDATION_CREATED', 'card_validation_created', 'Card Validation Created'), + ('CARD_VALIDATION_FAILED', 'card_validation_failed', 'Card Validation Failed'), + ('CARD_VALIDATION_SUCCEEDED', 'card_validation_succeeded', 'Card Validation Succeeded'), ) NOTIFICATION_STATUS_CHOICES = Choices( @@ -287,7 +297,13 @@ ("BANK_WIRE", "bank_wire", "Bank Wire"), ("APPLEPAY", "applepay", "Applepay"), ("GOOGLEPAY", "googlepay", "Googlepay"), - ("MBWAY", "mbway", "Mbway") + ("GOOGLE_PAY", "google_pay", "Google Pay"), + ("MBWAY", "mbway", "Mbway"), + ("PAYPAL", "paypal", "PayPal"), + ("MULTIBANCO", "multibanco", "Multibanco"), + ("SATISPAY", "satispay", "Satispay"), + ("BLIK", "blik", "Blik"), + ("KLARNA", "klarna", "Klarna") ) CARD_STATUS_CHOICES = Choices( @@ -338,4 +354,10 @@ ('CREATED', 'created', 'Created'), ('SUCCEEDED', 'succeeded', 'Succeeded'), ('FAILED', 'failed', 'Failed') -) \ No newline at end of file +) + +SHIPPING_PREFERENCE_CHOICES = Choices( + ('SET_PROVIDED_ADDRESS', 'set_provided_address', 'Set Provided Address'), + ('GET_FROM_FILE', 'get_from_file', 'Get From File'), + ('NO_SHIPPING', 'no_shipping', 'No Shipping') +) diff --git a/mangopay/resources.py b/mangopay/resources.py index 0478d5d..65c4f51 100644 --- a/mangopay/resources.py +++ b/mangopay/resources.py @@ -336,25 +336,53 @@ def get_transactions(self, *args, **kwargs): select.identifier = 'CARD_GET_TRANSACTIONS' return select.all(*args, **kwargs) - def validate(self, *args, **kwargs): - kwargs['id'] = self.id - insert = InsertQuery(self, **kwargs) - insert.identifier = 'CARD_VALIDATE' - return insert.execute() - class Meta: verbose_name = 'card' verbose_name_plural = 'cards' url = { SelectQuery.identifier: '/cards', UpdateQuery.identifier: '/cards', - 'CARDS_FOR_FINGERPRINT': '/cards/fingerprints/%(fingerprint)s', - 'CARD_VALIDATE': '/cards/%(id)s/validate'} + 'CARDS_FOR_FINGERPRINT': '/cards/fingerprints/%(fingerprint)s' + } def __str__(self): return '%s of user %s' % (self.card_type, self.user_id) +class CardValidation(BaseModel): + creation_date = DateTimeField(api_name='CreationDate') + author = ForeignKeyField(User, api_name='AuthorId', required=True) + ip_address = CharField(api_name='IpAddress', required=True) + browser_info = BrowserInfoField(api_name='BrowserInfo', required=True) + secure_mode_return_url = CharField(api_name='SecureModeReturnURL', required=True) + secure_mode_redirect_url = CharField(api_name='SecureModeRedirectURL') + secure_mode_needed = BooleanField(api_name='SecureModeNeeded') + validity = CharField(api_name='Validity', + choices=constants.VALIDITY_CHOICES, + default=constants.VALIDITY_CHOICES.unknown) + type = CharField(api_name='Type', choices=constants.TRANSACTION_TYPE_CHOICES, default=None) + applied_3ds_version = CharField(api_name='Applied3DSVersion') + status = CharField(api_name='Status', + choices=constants.STATUS_CHOICES, + default=None) + result_code = CharField(api_name='ResultCode') + result_message = CharField(api_name='ResultMessage') + + def validate(self, card_id, **kwargs): + insert = InsertQuery(self, **kwargs) + insert.insert_query = self.get_field_dict() + insert.insert_query['id'] = card_id + insert.identifier = 'CARD_VALIDATE' + return insert.execute() + + class Meta: + verbose_name = 'card_validation' + verbose_name_plural = 'card_validations' + url = { + 'CARD_VALIDATE': '/cards/%(id)s/validation' + } + + class CardRegistration(BaseModel): user = ForeignKeyField(User, api_name='UserId', required=True, related_name='card_registrations') currency = CharField(api_name='Currency', required=True) @@ -477,7 +505,13 @@ def cast(cls, result): ("BANK_WIRE", "EXTERNAL_INSTRUCTION"): BankWirePayInExternalInstruction, ("APPLEPAY", "DIRECT"): ApplepayPayIn, ("GOOGLEPAY", "DIRECT"): GooglepayPayIn, - ("MBWAY", "DIRECT"): MbwayPayIn + ("GOOGLE_PAY", "DIRECT"): GooglePayDirectPayIn, + ("MBWAY", "WEB"): MbwayPayIn, + ("PAYPAL", "WEB"): PayPalWebPayIn, + ("MULTIBANCO", "WEB"): MultibancoPayIn, + ("SATISPAY", "WEB"): SatispayPayIn, + ("BLIK", "WEB"): BlikPayIn, + ("KLARNA", "WEB"): KlarnaPayIn } return types.get((payment_type, execution_type), cls) @@ -692,6 +726,31 @@ 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') + shipping_preference = CharField(api_name='ShippingPreference', choices=constants.SHIPPING_PREFERENCE_CHOICES, + default=None) + + 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 +802,33 @@ class Meta: InsertQuery.identifier: '/payins/googlepay/direct' } + +class GooglePayDirectPayIn(PayIn): + tag = CharField(api_name='Tag') + author = ForeignKeyField(User, api_name='AuthorId', required=True) + credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True) + debited_funds = MoneyField(api_name='DebitedFunds', required=True) + fees = MoneyField(api_name='Fees', required=True) + secure_mode_return_url = CharField(api_name='SecureModeReturnURL', required=True) + secure_mode = CharField(api_name='SecureMode', + choices=constants.SECURE_MODE_CHOICES, + default=constants.SECURE_MODE_CHOICES.default) + ip_address = CharField(api_name='IpAddress', required=True) + browser_info = BrowserInfoField(api_name='BrowserInfo', required=True) + payment_data = CharField(api_name='PaymentData', required=True) + shipping = ShippingField(api_name='Shipping') + billing = BillingField(api_name='Billing') + statement_descriptor = CharField(api_name='StatementDescriptor') + + class Meta: + verbose_name = 'googlepay_direct_payin' + verbose_name_plural = 'googlepay_direct_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/googlepay', + SelectQuery.identifier: '/payins' + } + + class MbwayPayIn(PayIn): creation_date = DateTimeField(api_name='CreationDate') author = ForeignKeyField(User, api_name='AuthorId', required=True) @@ -759,6 +845,90 @@ class Meta: SelectQuery.identifier: '/payins' } + +class MultibancoPayIn(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) + statement_descriptor = CharField(api_name='StatementDescriptor') + redirect_url = CharField(api_name='RedirectURL') + return_url = CharField(api_name='ReturnURL', required=True) + + class Meta: + verbose_name = 'multibanco_payin' + verbose_name_plural = 'multibanco_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/multibanco', + SelectQuery.identifier: '/payins' + } + + +class SatispayPayIn(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) + return_url = CharField(api_name='ReturnURL', required=True) + redirect_url = CharField(api_name='RedirectURL') + country = CharField(api_name='Country', required=True) + statement_descriptor = CharField(api_name='StatementDescriptor') + + class Meta: + verbose_name = 'satispay_payin' + verbose_name_plural = 'satispay_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/satispay', + SelectQuery.identifier: '/payins' + } + + +class BlikPayIn(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) + statement_descriptor = CharField(api_name='StatementDescriptor') + return_url = CharField(api_name='ReturnURL', required=True) + redirect_url = CharField(api_name='RedirectURL') + + class Meta: + verbose_name = 'blik_payin' + verbose_name_plural = 'blik_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/blik', + SelectQuery.identifier: '/payins' + } + + +class KlarnaPayIn(PayIn): + author = ForeignKeyField(User, api_name='AuthorId', required=True) + debited_funds = MoneyField(api_name='DebitedFunds', required=True) + fees = MoneyField(api_name='Fees', required=True) + return_url = CharField(api_name='ReturnURL', required=True) + line_items = ListField(api_name='LineItems', required=True) + country = CharField(api_name='Country', required=True) + phone = CharField(api_name='Phone', required=True) + email = EmailField(api_name='Email', required=True) + additional_data = CharField(api_name='AdditionalData', required=True) + billing = BillingField(api_name='Billing', required=True) + merchant_order_id = CharField(api_name='MerchantOrderId', required=True) + culture = CharField(api_name='Culture', required=True) + shipping = ShippingField(api_name='Shipping') + creation_date = DateTimeField(api_name='CreationDate') + credited_funds = MoneyField(api_name='CreditedFunds') + redirect_url = CharField(api_name='RedirectURL') + payment_method = CharField(api_name='PaymentMethod') + + class Meta: + verbose_name = 'klarna_payin' + verbose_name_plural = 'klarna_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/klarna', + SelectQuery.identifier: '/payins' + } + + class CardWebPayIn(PayIn): author = ForeignKeyField(User, api_name='AuthorId', required=True) credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True) @@ -849,6 +1019,7 @@ class Meta: SelectQuery.identifier: '/payins' } + class PreAuthorization(BaseModel): author = ForeignKeyField(User, api_name='AuthorId', required=True) debited_funds = MoneyField(api_name='DebitedFunds', 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_cards.py b/tests/test_cards.py index 0e84730..b58c42d 100644 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -6,7 +6,7 @@ except ImportError: import urllib as urlrequest -from mangopay.resources import Card, CardRegistration +from mangopay.resources import Card, CardRegistration, CardValidation from tests.test_base import BaseTest from tests.test_base import BaseTestLive @@ -279,7 +279,36 @@ def test_getCardTransactions(self): self.assertIsInstance(transactions_page.data, list) def test_cardValidation(self): - card = BaseTestLive.get_johns_card() - validatedCard = card.validate() + user = BaseTestLive.get_john() + + card_registration = CardRegistration() + card_registration.user = user + card_registration.currency = 'EUR' - self.assertIsNotNone(validatedCard) + saved_registration = card_registration.save() + data = { + 'cardNumber': '4970107111111119', + 'cardCvx': '123', + 'cardExpirationDate': '1224', + 'accessKeyRef': card_registration.access_key, + 'data': card_registration.preregistration_data + } + headers = { + 'content-type': 'application/x-www-form-urlencoded' + } + registration_data_response = requests.post(card_registration.card_registration_url, data=data, headers=headers) + saved_registration['registration_data'] = registration_data_response.text + updated_registration = CardRegistration(**saved_registration).save() + card_id = updated_registration['card_id'] + + card_validation = CardValidation() + card_validation.author = user + card_validation.tag = "test" + card_validation.secure_mode_return_url = "http://www.example.com/" + card_validation.ip_address = "2001:0620:0000:0000:0211:24FF:FE80:C12C" + card_validation.browser_info = BaseTest.get_browser_info() + + validation_response = card_validation.validate(card_id) + + self.assertIsNotNone(validation_response) + self.assertIsNotNone(validation_response['id']) diff --git a/tests/test_payins.py b/tests/test_payins.py index d1deeb7..5c381fa 100644 --- a/tests/test_payins.py +++ b/tests/test_payins.py @@ -1,20 +1,16 @@ # -*- coding: utf-8 -*- -import json -import time import unittest -from cmath import rect -from datetime import date import responses from mangopay.resources import DirectDebitDirectPayIn, Mandate, ApplepayPayIn, GooglepayPayIn, \ RecurringPayInRegistration, \ - RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn + RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn, PayPalWebPayIn, \ + GooglePayDirectPayIn, MultibancoPayIn, SatispayPayIn, BlikPayIn, KlarnaPayIn from mangopay.utils import (Money, ShippingAddress, Shipping, Billing, Address, SecurityInfo, ApplepayPaymentData, - GooglepayPaymentData, DebitedBankAccount, BrowserInfo) - + GooglepayPaymentData, DebitedBankAccount, LineItem) from tests import settings -from tests.resources import (Wallet, PayIn, DirectPayIn, BankWirePayIn, BankWirePayInExternalInstruction, PayPalPayIn, +from tests.resources import (Wallet, DirectPayIn, BankWirePayIn, PayPalPayIn, PayconiqPayIn, CardWebPayIn, DirectDebitWebPayIn, constants) from tests.test_base import BaseTest, BaseTestLive @@ -262,13 +258,13 @@ def test_create_bank_wire_payins(self): @responses.activate def test_get_bank_wire_external_instructions_iban(self): debited_bank_account_params = { - "owner_name": None, - "account_number": None, - "iban": "1234567", - "bic": None, - "type": "IBAN", - "country": None - } + "owner_name": None, + "account_number": None, + "iban": "1234567", + "bic": None, + "type": "IBAN", + "country": None + } debited_bank_account = DebitedBankAccount(**debited_bank_account_params) self.register_mock({ 'method': responses.GET, @@ -467,37 +463,37 @@ def test_create_payoniq_payin(self): 'method': responses.POST, 'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/payins/payconiq/web', 'body': { - "Id": "119683174", - "Tag": "custom meta", - "CreationDate" :1632985748, - "ExpirationDate" :1632986949, - "AuthorId": "119683166", - "CreditedUserId": "119683166", - "DebitedFunds": { - "Currency": "EUR", - "Amount": 22 - }, - "CreditedFunds": { - "Currency": "EUR", - "Amount": 12 - }, - "Fees": { - "Currency": "EUR", - "Amount": 10 - }, - "Status": "CREATED", - "ResultCode": None, - "ResultMessage": None, - "ExecutionDate": None, - "Type": "PAYIN", - "Nature": "REGULAR", - "CreditedWalletId": "119683167", - "DebitedWalletId": None, - "PaymentType": "PAYCONIQ", - "ExecutionType": "WEB", - "RedirectURL": "https://portal.payconiq.com/qrcode?c=https%3A%2F%2Fpayconiq.com%2Fpay%2F2%2F52e501a43d878e8846470b8f", - "ReturnURL": "http://www.my-site.com/returnURL", - "DeepLinkURL": "HTTPS://PAYCONIQ.COM/PAY/2/52E501A43D878E8846470B8F" + "Id": "119683174", + "Tag": "custom meta", + "CreationDate": 1632985748, + "ExpirationDate": 1632986949, + "AuthorId": "119683166", + "CreditedUserId": "119683166", + "DebitedFunds": { + "Currency": "EUR", + "Amount": 22 + }, + "CreditedFunds": { + "Currency": "EUR", + "Amount": 12 + }, + "Fees": { + "Currency": "EUR", + "Amount": 10 + }, + "Status": "CREATED", + "ResultCode": None, + "ResultMessage": None, + "ExecutionDate": None, + "Type": "PAYIN", + "Nature": "REGULAR", + "CreditedWalletId": "119683167", + "DebitedWalletId": None, + "PaymentType": "PAYCONIQ", + "ExecutionType": "WEB", + "RedirectURL": "https://portal.payconiq.com/qrcode?c=https%3A%2F%2Fpayconiq.com%2Fpay%2F2%2F52e501a43d878e8846470b8f", + "ReturnURL": "http://www.my-site.com/returnURL", + "DeepLinkURL": "HTTPS://PAYCONIQ.COM/PAY/2/52E501A43D878E8846470B8F" }, 'status': 200 }) @@ -696,7 +692,7 @@ def test_create_direct_debit_via_web_interface_payin(self): self.assertEqual(card_payin.payment_type, 'DIRECT_DEBIT') @responses.activate - def test_create_mbway_direct_payins(self): + def test_create_mbway_web_payins(self): self.mock_natural_user() self.mock_user_wallet() @@ -728,14 +724,14 @@ def test_create_mbway_direct_payins(self): "Nature": "REGULAR", "CreditedWalletId": "102150481", "PaymentType": "MBWAY", - "ExecutionType": "DIRECT", + "ExecutionType": "WEB", "StatementDescriptor": "My descriptor", "PhoneNumber": "351#269458236" }, 'status': 200 }) - mbway_direct_params = { + mbway_web_params = { "author": self.natural_user, "debited_funds": Money(amount=500, currency='EUR'), "fees": Money(amount=0, currency='EUR'), @@ -744,16 +740,16 @@ def test_create_mbway_direct_payins(self): "phone": "351#269458236", "tag": "MB WAY Tag" } - mbway_payin = MbwayPayIn(**mbway_direct_params) + mbway_payin = MbwayPayIn(**mbway_web_params) self.assertIsNone(mbway_payin.get_pk()) mbway_payin.save() self.assertIsInstance(mbway_payin, MbwayPayIn) self.assertEqual(mbway_payin.status, 'CREATED') self.assertEqual(mbway_payin.payment_type, 'MBWAY') - self.assertEqual(mbway_payin.execution_type, 'DIRECT') + self.assertEqual(mbway_payin.execution_type, 'WEB') - for key, value in mbway_direct_params.items(): + for key, value in mbway_web_params.items(): self.assertEqual(getattr(mbway_payin, key), value) self.assertIsNotNone(mbway_payin.get_pk()) @@ -772,16 +768,6 @@ def test_using_api_names_as_payin_attributes(self): payin.Tag = 'x' self.assertIs(payin.Tag, payin.tag) - def test_get_paypal_with_account_email(self): - payin_id = "54088959" - paypal_buyer_email = "paypal-buyer-user@mangopay.com" - payin = PayPalPayIn.get(payin_id) - - self.assertIsNotNone(payin, "PayPal pay in is null") - self.assertEqual(payin.payment_type, "PAYPAL") - self.assertEqual(payin_id, payin.id) - self.assertEqual(paypal_buyer_email, payin.buyer_account_email) - class PayInsTestLive(BaseTestLive): @unittest.skip('Set a breakpoint after creating the mandate, navigate to mandate.redirect_url and confirm') @@ -930,7 +916,7 @@ def test_RecurringPayment(self): got_cit = RecurringPayInCIT.get(cit_id) self.assertIsNotNone(got_cit) - #self.assertIsInstance(got_cit, RecurringPayInCIT) + # self.assertIsInstance(got_cit, RecurringPayInCIT) params = { "author": user, @@ -1123,7 +1109,59 @@ def test_card_preauthorized_deposit_payin(self): self.assertEqual("PREAUTHORIZED", pay_in.payment_type) self.assertEqual("PAYIN", pay_in.type) - def test_PayIns_MbwayDirect_Create(self): + def test_PayIns_GooglePayDirect_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 = GooglePayDirectPayIn() + pay_in.tag = "Google Pay PayIn" + 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.secure_mode_return_url = "https://mangopay.com/docs/please-ignore" + pay_in.secure_mode = "DEFAULT" + pay_in.ip_address = "159.180.248.187" + + browser = BaseTest.get_browser_info() + + pay_in.browser_info = browser + pay_in.payment_data = "{\"signature\":\"MEUCIQCLXOan2Y9DobLVSOeD5V64Peayvz0ZAWisdz/1iTdthAIgVFb4Hve4EhtW81k46SiMlnXLIiCn1h2+vVQGjHe+sSo\\u003d\",\"intermediateSigningKey\":{\"signedKey\":\"{\\\"keyValue\\\":\\\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEDGRER6R6PH6K39YTIYX+CpDNej6gQgvi/Wx19SOPtiDnkjAl4/LF9pXlvZYe+aJH0Dy095I6BlfY8bNBB5gjPg\\\\u003d\\\\u003d\\\",\\\"keyExpiration\\\":\\\"1688521049102\\\"}\",\"signatures\":[\"MEYCIQDup1B+rkiPAWmpg7RmqY0NfgdGhmdyL8wvAX+6C1aOU2QIhAIZACSDQ/ZexIyEia5KrRlG2B+y3AnKNlhRzumRcnNOR\"]},\"protocolVersion\":\"ECv2\",\"signedMessage\":\"{\\\"encryptedMessage\\\":\\\"YSSGK9yFdKP+mJB5+wAjnOujnThPM1E/KbbJxd3MDzPVI66ip1DBESldvQXYjjeLq6Rf1tKE9oLwwaj6u0/gU7Z9t3g1MoW+9YoEE1bs1IxImif7IQGAosfYjjbBBfDkOaqEs2JJC5qt6xjKO9lQ/E6JPkPFGqF7+OJ1vzmD83Pi3sHWkVge5MhxXQ3yBNhrjus3kV7zUoYA+uqNrciWcWypc1NndF/tiwSkvUTzM6n4dS8X84fkJiSO7PZ65C0yw0mdybRRnyL2fFdWGssve1zZFAvYfzcpNamyuZGGlu/SCoayitojmMsqe5Cu0efD9+WvvDr9PA+Vo1gzuz7LmiZe81SGvdFhRoq62FBAUiwSsi2A3pWinZxM2XbYNph+HJ5FCNspWhz4ur9JG4ZMLemCXuaybvL++W6PWywAtoiE0mQcBIX3vhOq5itv0RkaKVe6nbcAS2UryRz2u/nDCJLKpIv2Wi11NtCUT2mgD8F6qfcXhvVZHyeLqZ1OLgCudTTSdKirzezbgPTg4tQpW++KufeD7bgG+01XhCWt+7/ftqcSf8n//gSRINne8j2G6w+2\\\",\\\"ephemeralPublicKey\\\":\\\"BLY2+R8C0T+BSf/W3HEq305qH63IGmJxMVmbfJ6+x1V7GQg9W9v7eHc3j+8TeypVn+nRlPu98tivuMXECg+rWZs\\\\u003d\\\",\\\"tag\\\":\\\"MmEjNdLfsDNfYd/FRUjoJ4/IfLypNRqx8zgHfa6Ftmo\\\\u003d\\\"}\"}" + + address = Address() + address.address_line_1 = "Big Street" + address.address_line_2 = "no 2 ap 6" + address.country = "FR" + address.city = "Lyon" + address.postal_code = "68400" + + pay_in.billing = Billing(first_name="John", last_name="Doe", address=address) + pay_in.shipping = Shipping(first_name="John", last_name="Doe", address=address) + pay_in.statement_descriptor = "test" + + result = GooglePayDirectPayIn(**pay_in.save()) + fetched = GooglePayDirectPayIn().get(result.id) + + self.assertIsNotNone(result) + self.assertIsNotNone(fetched) + self.assertEqual(result.id, fetched.id) + + self.assertEqual("REGULAR", result.nature) + self.assertEqual("DIRECT", result.execution_type) + self.assertEqual("GOOGLE_PAY", result.payment_type) + self.assertEqual("PAYIN", result.type) + + def test_PayIns_MbwayWeb_Create(self): user = BaseTestLive.get_john(True) # create wallet @@ -1154,6 +1192,227 @@ def test_PayIns_MbwayDirect_Create(self): self.assertEqual("CREATED", result.status) self.assertEqual("REGULAR", result.nature) - self.assertEqual("DIRECT", result.execution_type) + self.assertEqual("WEB", 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" + pay_in.shipping_preference = "NO_SHIPPING" + + 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) + + def test_PayIns_MultibancoWeb_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 = MultibancoPayIn() + 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.statement_descriptor = 'test' + pay_in.redirect_url = 'https://r3.girogate.de/ti/multibanco?tx=140066339483&rs=XOj6bbIqBxdIHjdDmb1o90RoCiKp8iwj&cs=162f500c5754acdebc8379df496cc6c5ababe4dbe15e3ccda1d691de5e87af26' + pay_in.return_url = 'http://www.my-site.com/returnURL?transactionId=wt_8362acb9-6dbc-4660-b826-b9acb9b850b1' + pay_in.tag = 'Multibanco tag' + + result = MultibancoPayIn(**pay_in.save()) + fetched = MultibancoPayIn().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("MULTIBANCO", result.payment_type) + self.assertEqual("PAYIN", result.type) + + def test_PayIns_SatispayWeb_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 = SatispayPayIn() + pay_in.author = user + pay_in.credited_wallet = credited_wallet + pay_in.fees = Money() + pay_in.fees.amount = 200 + pay_in.fees.currency = 'EUR' + pay_in.debited_funds = Money() + pay_in.debited_funds.amount = 2000 + pay_in.debited_funds.currency = 'EUR' + pay_in.statement_descriptor = 'test' + pay_in.return_url = 'http://www.my-site.com/returnURL?transactionId=wt_71a08458-b0cc-468d-98f7-1302591fc238' + pay_in.tag = 'Satispay tag' + pay_in.country = 'IT' + + result = SatispayPayIn(**pay_in.save()) + fetched = SatispayPayIn().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("SATISPAY", result.payment_type) + self.assertEqual("PAYIN", result.type) + + def test_PayIns_BlikWeb_Create(self): + user = BaseTestLive.get_john(True) + + # create wallet + credited_wallet = Wallet() + credited_wallet.owners = (user,) + credited_wallet.currency = 'PLN' + credited_wallet.description = 'WALLET IN PLN' + credited_wallet = Wallet(**credited_wallet.save()) + + pay_in = BlikPayIn() + pay_in.author = user + pay_in.credited_wallet = credited_wallet + pay_in.fees = Money() + pay_in.fees.amount = 300 + pay_in.fees.currency = 'PLN' + pay_in.debited_funds = Money() + pay_in.debited_funds.amount = 1000 + pay_in.debited_funds.currency = 'PLN' + pay_in.statement_descriptor = 'test' + pay_in.return_url = 'https://example.com?transactionId=wt_57b8f69d-cbcc-4202-9a4f-9a3f3668240b' + pay_in.redirect_url = 'https://r3.girogate.de/ti/dumbdummy?tx=140079495229&rs=oHkl4WvsgwtWpMptWpqWlFa90j0EzzO9&cs=e43baf1ae4a556dfb823fd304acc408580c193e04c1a9bcb26699b4185393b05' + pay_in.tag = 'Blik tag' + + result = BlikPayIn(**pay_in.save()) + fetched = BlikPayIn().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("BLIK", result.payment_type) + self.assertEqual("PAYIN", result.type) + + def test_PayIns_KlarnaWeb_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 = KlarnaPayIn() + pay_in.author = user + pay_in.debited_funds = Money() + pay_in.debited_funds.amount = 1000 + pay_in.debited_funds.currency = "EUR" + pay_in.fees = Money() + pay_in.fees.amount = 100 + pay_in.fees.currency = "EUR" + + pay_in.return_url = "http://www.my-site.com/returnURL" + + line_item = LineItem() + line_item.name = "test" + line_item.quantity = 1 + line_item.unit_amount = 1000 + line_item.tax_amount = 0 + pay_in.line_items = [line_item] + + pay_in.country = 'FR' + pay_in.culture = 'FR' + pay_in.phone = "33#607080900" + pay_in.email = "mango@mangopay.com" + pay_in.additional_data = "{}" + + address = Address() + address.address_line_1 = "Big Street" + address.address_line_2 = "no 2 ap 6" + address.country = "FR" + address.city = "Lyon" + address.postal_code = "68400" + address.region = "Ile de France" + pay_in.billing = Billing(first_name="John", last_name="Doe", address=address) + pay_in.shipping = Shipping(first_name="John", last_name="Doe", address=address) + + pay_in.merchant_order_id = "afd48-879d-48fg" + + pay_in.statement_descriptor = "test" + pay_in.tag = "test tag" + + pay_in.credited_wallet = credited_wallet + + result = KlarnaPayIn(**pay_in.save()) + fetched = KlarnaPayIn().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("KLARNA", result.payment_type) + self.assertEqual("PAYIN", result.type)