Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG-2067: Update mangopay sdk #6

Merged
merged 21 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: python
python:
#- '2.7'
- '3.5'
- '3.6'
install:
- pip install -r requirements/base.txt
- pip install -r requirements/development.txt
script: nosetests
script:
- if [ $TRAVIS_BRANCH != "release" ]; then nosetests; fi
sudo: required
dist: xenial
deploy:
Expand All @@ -17,8 +18,8 @@ deploy:
repo: Mangopay/mangopay2-python-sdk
branch: release
tags: false
python: 3.5
condition: $TRAVIS_PYTHON_VERSION = "3.5"
python: 3.6
condition: $TRAVIS_PYTHON_VERSION = "3.6"
env:
global:
- secure: eDsZz0hrnLpBmkFvHMeczHHjytOMJpOZMc21nVR/vRLnjZ7eLmXaklvdy3AQ5SJz+l1neVVihHNX6MyBJ0s63UKatLP7catl++yyqPj5/0C7C0a07ZvJHhUzqnEdYLNOMauy7p5rPMldLOiT1dgQlL1f1FG31BHJ5UkAnrhwvdU=
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 3.9.0
- 3DS2 integration with Shipping and Billing objects, including FirstName and LastName fields
The objects Billing and Shipping may be included on all calls to the following endpoints:
- /preauthorizations/card/direct
- /payins/card/direct
- /payins/card/web
- Enable Instant Payment for payouts by adding a new parameter PayoutModeRequested on the following endpoint /payouts/bankwire
- The new parameter PayoutModeRequested can take two differents values : "INSTANT_PAYMENT" or "STANDARD" (STANDARD = the way we procede normaly a payout request)
- This new parameter is not mandatory and if empty or not present, the payout will be "STANDARD" by default
- Instant Payment is in beta all over Europe - SEPA region
- Changed date to dateTime and fixed tests
- Changed User-Agent
- Fixed typo on IpAddress, FirstName & LastName
## 3.8.4
- Added 'Regulatory' endpoint to allow checks of User Block Status
- Added support for Regulatory -> Blocked Status Hooks
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ MangopaySDK is distributed under MIT license, see LICENSE file.

Contact
-------------------------------------------------
Report bugs or suggest features using [issue tracker at GitHub](https://github.com/MangoPay/mangopay2-python-sdk-v2).
Report bugs or suggest features using [issue tracker at GitHub](https://github.com/Mangopay/mangopay2-python-sdk/issues).


Account creation
-------------------------------------------------
You can get yourself a [free sandbox account](https://www.mangopay.com/signup/create-sandbox/) or sign up for a [production account](https://www.mangopay.com/signup/production-account/) (note that validation of your production account can take a few days, so think about doing it in advance of when you actually want to go live).
You can get yourself a free sandbox account or sign up for a production account by [registering on the Mangopay site](https://www.mangopay.com/start/) (note that validation of your production account involves several steps, so think about doing it in advance of when you actually want to go live).

Inspiration
-----------
Expand Down
2 changes: 1 addition & 1 deletion mangopay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def custom_request(self, method, url, data=None, idempotency_key=None, oauth_req
headers = {}

if is_mangopay_request:
headers['User-Agent'] = 'MangoPay V2 SDK Python ' + str(mangopay.package_version)
headers['User-Agent'] = 'MangoPay V2 Python/' + str(mangopay.package_version)
if oauth_request:
headers['Authorization'] = self.auth_manager.basic_token()
headers['Content-Type'] = 'application/x-www-form-urlencoded'
Expand Down
10 changes: 7 additions & 3 deletions mangopay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,16 @@ def api_value(self, value):
class BillingField(Field):
def python_value(self, value):
if value is not None:
return Billing(address=value['Address'])
return Billing(first_name=value['FirstName'], last_name=value['LastName'], address=value['Address'])
return value

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

if isinstance(value, Billing):
value = {
'FirstName': value.first_name,
'LastName': value.last_name,
'Address': value.address
}

Expand Down Expand Up @@ -750,14 +752,16 @@ def api_value(self, value):
class ShippingField(Field):
def python_value(self, value):
if value is not None:
return Shipping(address=value['Address'])
return Shipping(first_name=value['FirstName'], last_name=value['LastName'], address=value['Address'])
return value

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

if isinstance(value, Billing):
if isinstance(value, Shipping):
value = {
'FirstName': value.first_name,
'LastName': value.last_name,
'Address': value.address
}

Expand Down
7 changes: 4 additions & 3 deletions mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class DirectPayIn(PayIn):
billing = BillingField(api_name='Billing')
security_info = SecurityInfoField(api_name='SecurityInfo')
culture = CharField(api_name='Culture')
ip_address = CharField(api_name='IpAdress')
ip_address = CharField(api_name='IpAddress')
browser_info = BrowserInfoField(api_name='BrowserInfo')
shipping = ShippingField(api_name='Shipping')

Expand Down Expand Up @@ -689,7 +689,7 @@ class PreAuthorization(BaseModel):
billing = BillingField(api_name='Billing')
security_info = SecurityInfoField(api_name='SecurityInfo')
multi_capture = BooleanField(api_name='MultiCapture')
ip_address = CharField(api_name='IpAdress')
ip_address = CharField(api_name='IpAddress')
browser_info = BrowserInfoField(api_name='BrowserInfo')
shipping = ShippingField(api_name='Shipping')

Expand Down Expand Up @@ -809,8 +809,9 @@ class BankWirePayOut(BaseModel):
payment_type = CharField(api_name='PaymentType', choices=constants.PAYOUT_PAYMENT_TYPE, default=None)
execution_type = CharField(api_name='ExecutionType', choices=constants.EXECUTION_TYPE_CHOICES, default=None)
bank_wire_ref = CharField(api_name='BankWireRef')
payout_mode_requested = CharField(api_name='PayoutModeRequested')
credited_user = ForeignKeyField(User, api_name='CreditedUserId')
creation_date = DateField(api_name='CreationDate')
creation_date = DateTimeField(api_name='CreationDate')

def get_refunds(self, *args, **kwargs):
kwargs['id'] = self.id
Expand Down
14 changes: 10 additions & 4 deletions mangopay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,14 @@ def __str__(self):

@add_camelcase_aliases
class Billing(object):
def __init__(self, address=None):
def __init__(self, first_name=None, last_name=None, address=None):
self.first_name = first_name
self.last_name = last_name
self.address = address

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


@add_camelcase_aliases
Expand Down Expand Up @@ -510,11 +513,14 @@ def to_api_json(self):

@add_camelcase_aliases
class Shipping(object):
def __init__(self, address=None):
def __init__(self, first_name=None, last_name=None, address=None):
self.first_name = first_name
self.last_name = last_name
self.address = address

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


@add_camelcase_aliases
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='mangopaysdk',
version='3.8.4',
version='3.9.0',
description='A client library written in python to work with mangopay v2 api',
long_description='This SDK is a client library for interacting with the Mangopay API.',
url='https://github.com/Mangopay/mangopay2-python-sdk',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def test_PayIns_CardDirect_CreateWithAvs(self):
address.country = "FR"
address.city = "Lyon"
address.postal_code = "68400"
pay_in.billing = Billing(address=address)
pay_in.billing = Billing(first_name="John", last_name="Doe", address=address)

result = pay_in.save()

Expand Down
4 changes: 3 additions & 1 deletion tests/test_payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_create_bank_wire_payout(self):
"Id": 30047,
"CreditedFunds": None,
"BankWireRef": "John Doe's trousers",
"PayoutModeRequested": "INSTANT_PAYMENT",
"DebitedFunds": {"Currency": "EUR", "Amount": 1000},
"BankAccountId": 6784645,
"AuthorId": 6784642,
Expand Down Expand Up @@ -82,7 +83,8 @@ def test_create_bank_wire_payout(self):
"Nature": "NORMAL",
"DebitedWalletId": "30025",
"BankAccountId": "30027",
"BankWireRef": "John Doe's trousers"
"BankWireRef": "John Doe's trousers",
"PayoutModeRequested": "INSTANT_PAYMENT"
},
'status': 200
}])
Expand Down
4 changes: 4 additions & 0 deletions tests/test_preauthorizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ def test_PreAuthorizations_CreateWithAvs(self):
billing.address.country = "FR"
billing.address.city = "Lyon"
billing.address.postal_code = "65400"
billing.last_name = "Doe"
billing.first_name = "John"
pre_authorization.billing = billing

saved_pre_authorization = pre_authorization.save()
Expand Down Expand Up @@ -754,6 +756,8 @@ def test_PreAuthorizations_CreateDirect(self):
billing.address.country = "FR"
billing.address.city = "Lyon"
billing.address.postal_code = "65400"
billing.last_name = "Doe"
billing.first_name = "John"
pre_authorization.billing = billing

saved_pre_authorization = pre_authorization.save()
Expand Down
25 changes: 13 additions & 12 deletions tests/test_transactions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
import time
from datetime import date, datetime

import responses

from mangopay.utils import Money, timestamp_from_date
from tests import settings
from tests.resources import Transfer, Transaction
from tests.test_base import BaseTest

from mangopay.utils import Money

from datetime import date

import responses
import time

today = datetime.utcnow().date()
today_timestamp = timestamp_from_date(today)

class TransactionsTest(BaseTest):
@responses.activate
Expand Down Expand Up @@ -43,7 +44,7 @@ def test_retrieve_transactions(self):
"Status": "SUCCEEDED",
"ResultCode": "000000",
"ResultMessage": "Success",
"ExecutionDate": int(time.mktime(date.today().timetuple())),
"ExecutionDate": today_timestamp,
"Type": "TRANSFER",
"Nature": "REGULAR",
"DebitedWalletId": "1167496",
Expand Down Expand Up @@ -74,7 +75,7 @@ def test_retrieve_transactions(self):
"Status": "CREATED",
"ResultCode": "000000",
"ResultMessage": "Success",
"ExecutionDate": "2015-05-15",
"ExecutionDate": today_timestamp,
"Type": "TRANSFER",
"Nature": "REFUND",
"DebitedWalletId": "1174774"
Expand Down Expand Up @@ -106,7 +107,7 @@ def test_retrieve_transactions(self):
"Status": "CREATED",
"ResultCode": "000000",
"ResultMessage": "Success",
"ExecutionDate": "2015-05-15",
"ExecutionDate": today_timestamp,
"Type": "TRANSFER",
"Nature": "REFUND",
"DebitedWalletId": "1174774"
Expand Down Expand Up @@ -138,7 +139,7 @@ def test_retrieve_transactions(self):
"Status": "FAILED",
"ResultCode": "000000",
"ResultMessage": "Success",
"ExecutionDate": "2015-05-15",
"ExecutionDate": today_timestamp,
"Type": "TRANSFER",
"Nature": "REFUND",
"DebitedWalletId": "1174774"
Expand Down Expand Up @@ -172,7 +173,7 @@ def test_retrieve_transactions(self):
"Status": "CREATED",
"ResultCode": "000000",
"ResultMessage": "Success",
"ExecutionDate": 1383156788,
"ExecutionDate": today_timestamp,
"Type": "TRANSFER",
"Nature": "REGULAR",
"CreditedWalletId": "1167504",
Expand Down