Skip to content

Commit

Permalink
Merge pull request #346 from Mangopay/feature/implement_cardinfo
Browse files Browse the repository at this point in the history
feature/ Added CardInfo to 4 entities
  • Loading branch information
silvianagh authored Dec 22, 2023
2 parents 88218a2 + e03c64e commit f524063
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 17 deletions.
30 changes: 29 additions & 1 deletion mangopay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Reason, ReportTransactionsFilters, ReportWalletsFilters, \
PlatformCategorization, Billing, SecurityInfo, Birthplace, ApplepayPaymentData, GooglepayPaymentData, \
ScopeBlocked, BrowserInfo, Shipping, CurrentState, FallbackReason, InstantPayout, CountryAuthorizationData, \
PayinsLinked, ConversionRate
PayinsLinked, ConversionRate, CardInfo


class FieldDescriptor(object):
Expand Down Expand Up @@ -889,3 +889,31 @@ def api_value(self, value):
}

return value


class CardInfoField(Field):
def python_value(self, value):
if value is not None:
return CardInfo(
bin=value['BIN'],
issuing_bank=value['IssuingBank'],
issuer_country_code=value['IssuerCountryCode'],
type=value['Type'],
brand=value['Brand'],
sub_type=value['SubType'])
return value

def api_value(self, value):
value = super(CardInfoField, self).api_value(value)

if isinstance(value, CardInfo):
value = {
'BIN': value.bin,
'IssuingBank': value.issuing_bank,
'IssuerCountryCode': value.issuer_country_code,
'Type': value.type,
'Brand': value.brand,
'SubType': value.sub_type,
}

return value
15 changes: 12 additions & 3 deletions mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ReportWalletsFiltersField, BillingField, SecurityInfoField, PlatformCategorizationField,
BirthplaceField, ApplepayPaymentDataField, GooglepayPaymentDataField, ScopeBlockedField,
BrowserInfoField, ShippingField, CurrentStateField, FallbackReasonField, InstantPayoutField,
CountryAuthorizationDataField, PayinsLinkedField, ConversionRateField)
CountryAuthorizationDataField, PayinsLinkedField, ConversionRateField, CardInfoField)
from .query import InsertQuery, UpdateQuery, SelectQuery, ActionQuery


Expand Down Expand Up @@ -264,6 +264,7 @@ def get(cls, *args, **kwargs):
return ClientWallet.get(*tuple(args[0].split('_')), **kwargs)
return super(Wallet, cls).get(*args, **kwargs)


@python_2_unicode_compatible
class ConversionRate(BaseModel):
debited_currency = CharField(api_name='DebitedCurrency', required=True)
Expand All @@ -282,9 +283,10 @@ class Meta:
verbose_name = 'conversion_rate'
verbose_name_plural = 'conversion_rates'
url = {
'GET_CONVERSION_RATE' : '/conversion/rate/%(debited_currency)s/%(credited_currency)s'
'GET_CONVERSION_RATE': '/conversion/rate/%(debited_currency)s/%(credited_currency)s'
}


@python_2_unicode_compatible
class InstantConversion(BaseModel):
author = ForeignKeyField(User, api_name='AuthorId', required=True)
Expand Down Expand Up @@ -318,7 +320,7 @@ class Meta:
verbose_name = 'instant_conversion'
verbose_name_plural = 'instant_conversions'
url = {
'CREATE_INSTANT_CONVERSION' : '/instant-conversion',
'CREATE_INSTANT_CONVERSION': '/instant-conversion',
'GET_INSTANT_CONVERSION': '/instant-conversion/%(id)s'
}

Expand Down Expand Up @@ -636,6 +638,7 @@ class RecurringPayInCIT(PayIn):
secure_mode_redirect_url = CharField(api_name='SecureModeRedirectURL')
security_info = SecurityInfoField(api_name='SecurityInfo')
shipping = ShippingField(api_name='Shipping')
card_info = CardInfoField(api_name='CardInfo')

def get_read_only_properties(self):
read_only = ["AuthorId", "Applied3DSVersion", "CardId", "CreationDate", "Culture", "SecureModeNeeded"
Expand Down Expand Up @@ -672,6 +675,7 @@ class RecurringPayInMIT(PayIn):
secure_mode_redirect_url = CharField(api_name='SecureModeRedirectURL')
security_info = SecurityInfoField(api_name='SecurityInfo')
shipping = ShippingField(api_name='Shipping')
card_info = CardInfoField(api_name='CardInfo')

def get_read_only_properties(self):
read_only = ["AuthorId", "Applied3DSVersion", "CardId", "CreationDate", "Culture", "SecureModeNeeded"
Expand Down Expand Up @@ -711,6 +715,7 @@ class DirectPayIn(PayIn):
shipping = ShippingField(api_name='Shipping')
requested_3ds_version = CharField(api_name='Requested3DSVersion')
applied_3ds_version = CharField(api_name='Applied3DSVersion')
card_info = CardInfoField(api_name='CardInfo')

class Meta:
verbose_name = 'payin'
Expand Down Expand Up @@ -989,6 +994,7 @@ class Meta:
SelectQuery.identifier: '/payins'
}


class IdealPayIn(PayIn):
author = ForeignKeyField(User, api_name='AuthorId', required=True)
credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True)
Expand All @@ -1009,6 +1015,7 @@ class Meta:
SelectQuery.identifier: '/payins'
}


class GiropayPayIn(PayIn):
author = ForeignKeyField(User, api_name='AuthorId', required=True)
credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True)
Expand Down Expand Up @@ -1111,6 +1118,7 @@ class CardPreAuthorizedDepositPayIn(BaseModel):
debited_funds = MoneyField(api_name='DebitedFunds')
credited_funds = MoneyField(api_name='CreditedFunds')
fees = MoneyField(api_name='Fees')
card_info = CardInfoField(api_name='CardInfo')

class Meta:
verbose_name = 'card_preauthorized_deposit_payin'
Expand Down Expand Up @@ -1148,6 +1156,7 @@ class PreAuthorization(BaseModel):
shipping = ShippingField(api_name='Shipping')
requested_3ds_version = CharField(api_name='Requested3DSVersion')
applied_3ds_version = CharField(api_name='Applied3DSVersion')
card_info = CardInfoField(api_name='CardInfo')

def get_transactions(self, *args, **kwargs):
kwargs['id'] = self.id
Expand Down
44 changes: 33 additions & 11 deletions mangopay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def __init__(self, first_name=None, last_name=None, address=None):

def __str__(self):
return 'Billing: %s' % \
(self.first_name, self.last_name, self.address)
(self.first_name, self.last_name, self.address)


@add_camelcase_aliases
Expand All @@ -253,7 +253,7 @@ def __init__(self, code=None, message=None):

def __str__(self):
return 'FallbackReason: %s' % \
(self.code, self.message)
(self.code, self.message)


@add_camelcase_aliases
Expand All @@ -264,7 +264,7 @@ def __init__(self, is_reachable=None, unreachable_reason=None):

def __str__(self):
return 'InstantPayout: %s' % \
(self.code, self.message)
(self.code, self.message)


@add_camelcase_aliases
Expand All @@ -289,7 +289,7 @@ def __init__(self, owner_name=None, account_number=None, iban=None,

def __str__(self):
return 'DebitedBankAccount: %s' % \
(self.owner_name, self.account_number, self.iban, self.bic, self.type, self.country)
(self.owner_name, self.account_number, self.iban, self.bic, self.type, self.country)

def __eq__(self, other):
if isinstance(other, DebitedBankAccount):
Expand Down Expand Up @@ -317,7 +317,7 @@ def __init__(self, address_line_1=None, address_line_2=None, city=None, region=N

def __str__(self):
return 'Address: %s, %s , %s, %s, %s , %s' % \
(self.address_line_1, self.address_line_2, self.postal_code, self.city, self.region, self.country)
(self.address_line_1, self.address_line_2, self.postal_code, self.city, self.region, self.country)

def __eq__(self, other):
if isinstance(other, Address):
Expand Down Expand Up @@ -542,7 +542,7 @@ def __init__(self, first_name=None, last_name=None, address=None):

def __str__(self):
return 'Shipping: %s' % \
(self.first_name, self.last_name, self.address)
(self.first_name, self.last_name, self.address)


@add_camelcase_aliases
Expand All @@ -556,7 +556,7 @@ def __init__(self, payins_linked=None, cumulated_debited_amount=None, cumulated_

def __str__(self):
return 'CurrentState: %s' % \
(self.cumulated_debited_amount, self.cumulated_debited_fees, self.last_payin_id, self.payins_linked)
(self.cumulated_debited_amount, self.cumulated_debited_fees, self.last_payin_id, self.payins_linked)


@add_camelcase_aliases
Expand Down Expand Up @@ -891,7 +891,7 @@ def __init__(self, block_user_creation=None, block_bank_account_creation=None, b

def __str__(self):
return 'CountryAuthorizationData: %s, %s , %s' % \
(self.block_user_creation, self.block_bank_account_creation, self.block_payout)
(self.block_user_creation, self.block_bank_account_creation, self.block_payout)

def __eq__(self, other):
if isinstance(other, CountryAuthorizationData):
Expand All @@ -916,7 +916,7 @@ def __init__(self, payin_capture_id=None, payin_complement_id=None):

def __str__(self):
return 'PayinsLinked: %s, %s' % \
(self.payin_capture_id, self.payin_complement_id)
(self.payin_capture_id, self.payin_complement_id)

def to_api_json(self):
return {
Expand All @@ -935,7 +935,7 @@ def __init__(self, name=None, quantity=None, unit_amount=None, tax_amount=None,

def __str__(self):
return 'LineItem: %s %s %s %s %s' % \
(self.name, self.quantity, self.unit_amount, self.tax_amount, self.description)
(self.name, self.quantity, self.unit_amount, self.tax_amount, self.description)

def to_api_json(self):
return {
Expand All @@ -946,6 +946,7 @@ def to_api_json(self):
"Description": self.description
}


@add_camelcase_aliases
class ConversionRate(object):
def __init__(self, client_rate=None, market_rate=None):
Expand All @@ -954,4 +955,25 @@ def __init__(self, client_rate=None, market_rate=None):

def __str__(self):
return 'Conversion rate: %s' % \
(self.client_rate, self.market_rate)
(self.client_rate, self.market_rate)


@add_camelcase_aliases
class CardInfo(object):
def __init__(self,
bin=None,
issuing_bank=None,
issuer_country_code=None,
type=None,
brand=None,
sub_type=None):
self.bin = bin
self.issuing_bank = issuing_bank
self.issuer_country_code = issuer_country_code
self.type = type
self.brand = brand
self.sub_type = sub_type

def __str__(self):
return 'Card info: %s' % \
(self.bin, self.issuing_bank, self.issuer_country_code, self.type, self.brand, self.sub_type)
Loading

0 comments on commit f524063

Please sign in to comment.