Exemplo n.º 1
0
    def test_PreAuthorizations_CreateDirect(self):
        user = BaseTestLive.get_john()
        card_registration = CardRegistration()
        card_registration.user = user
        card_registration.currency = "EUR"

        saved_registration = card_registration.save()
        data = {
            'cardNumber': '4972485830400049',
            'cardCvx': '123',
            'cardExpirationDate': '0821',
            '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 = Card.get(updated_registration['card_id'])
        pre_authorization = PreAuthorization()
        pre_authorization.card = card
        pre_authorization.author = user
        pre_authorization.debited_funds = Money()
        pre_authorization.debited_funds.currency = "EUR"
        pre_authorization.debited_funds.amount = 500
        pre_authorization.remaining_funds = Money()
        pre_authorization.remaining_funds.currency = "EUR"
        pre_authorization.remaining_funds.amount = 500
        pre_authorization.secure_mode_return_url = "http://www.example.com/"
        billing = Billing()
        billing.address = Address()
        billing.address.address_line_1 = "Main Street"
        billing.address.address_line_2 = "no. 5 ap. 6"
        billing.address.country = "FR"
        billing.address.city = "Lyon"
        billing.address.postal_code = "65400"
        pre_authorization.billing = billing

        saved_pre_authorization = pre_authorization.save()

        wallet = BaseTestLive.get_johns_wallet()

        payin = PreAuthorizedPayIn()
        payin.author = BaseTestLive.get_john()
        payin.debited_funds = Money(amount=500, currency='EUR')
        payin.credited_wallet = wallet
        payin.secure_mode_return_url = "http://test.com"
        payin.secure_mode = 'DEFAULT'
        payin.preauthorization = pre_authorization
        payin.fees = Money(amount=0, currency='EUR')
        payin.culture = 'fr'
        BaseTestLive._johns_payin = PreAuthorizedPayIn(**payin.save())

        transactions = pre_authorization.get_transactions()

        self.assertIsNotNone(saved_pre_authorization)
        security_info = saved_pre_authorization['security_info']
        self.assertIsInstance(security_info, SecurityInfo)
        self.assertEqual(security_info.avs_result, "NO_CHECK")
        self.assertEqual(payin.status, "SUCCEEDED")
        self.assertEqual(transactions[0].status, "SUCCEEDED")
Exemplo n.º 2
0
    def test_create_failed_preauthorized_payin(self):
        self.mock_natural_user()
        self.mock_legal_user()
        self.mock_user_wallet()
        self.mock_card()

        self.register_mock([{
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/users/1167495',
            'body': {
                "FirstName": "Victor",
                "LastName": "Hugo",
                "Address": {
                    "AddressLine1": "AddressLine1",
                    "AddressLine2": "AddressLine2",
                    "City": "City",
                    "Region": "Region",
                    "PostalCode": "11222",
                    "Country": "FR"
                },
                "Birthday": int(time.mktime(date.today().timetuple())),
                "Nationality": "FR",
                "CountryOfResidence": "FR",
                "Occupation": "Writer",
                "IncomeRange": 6,
                "ProofOfIdentity": None,
                "ProofOfAddress": None,
                "PersonType": "NATURAL",
                "Email": "*****@*****.**",
                "Id": "1167495",
                "Tag": "custom tag",
                "CreationDate": 1383321421,
                "KYCLevel": "LIGHT"
            },
            'status':
            200
        }, {
            'method':
            responses.POST,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/preauthorizations/card/direct',
            'body': {
                "Id": "1209003",
                "Tag": None,
                "CreationDate": 1388653234,
                "AuthorId": "1208974",
                "DebitedFunds": {
                    "Currency": "EUR",
                    "Amount": 10000
                },
                "AuthorizationDate": 1388653377,
                "Status": "SUCCEEDED",
                "PaymentStatus": "WAITING",
                "ExpirationDate": 1389258177,
                "PayInId": "1209008",
                "ResultCode": "000000",
                "ResultMessage": "Success",
                "SecureMode": "DEFAULT",
                "CardId": "1208983",
                "SecureModeRedirectURL":
                "https://api-test.mangopay.com:443/Redirect/ACSWithoutValidation?token=8139ca555fd74fbbba14a50b7151a3e9",
                "SecureModeNeeded": True,
                "PaymentType": "CARD",
                "ExecutionType": "DIRECT"
            },
            'status':
            200
        }, {
            'method':
            responses.POST,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/payins/PreAuthorized/direct',
            'body': {
                "Id": "1209008",
                "Tag": None,
                "CreationDate": 1388653621,
                "ResultCode": "000000",
                "ResultMessage": "Success",
                "AuthorId": "1208974",
                "CreditedUserId": "1208974",
                "DebitedFunds": {
                    "Currency": "EUR",
                    "Amount": 30000
                },
                "CreditedFunds": {
                    "Currency": "EUR",
                    "Amount": 900
                },
                "Fees": {
                    "Currency": "EUR",
                    "Amount": 100
                },
                "Status": "FAILED",
                "ExecutionDate": 1388653622,
                "Type": "PAYIN",
                "Nature": "REGULAR",
                "CreditedWalletId": "1208991",
                "DebitedWalletId": None,
                "PaymentType": "PREAUTHORIZED",
                "ExecutionType": "DIRECT",
                "PreauthorizationId": "1209003"
            },
            'status':
            200
        }])

        params = {
            "author": self.card.user,
            "card": self.card,
            "debited_funds": Money(amount=10000, currency='EUR'),
            "remaining_funds": Money(amount=500, currency='EUR'),
            "secure_mode": "DEFAULT",
            "secure_mode_return_url": "http://www.ulule.com/"
        }
        preauthorization = PreAuthorization(**params)
        preauthorization.save()

        self.assertEqual(preauthorization.status, 'SUCCEEDED')
        self.assertEqual(preauthorization.payment_status, 'WAITING')

        params = {
            "author": self.card.user,
            "debited_funds": Money(amount=30000,
                                   currency='EUR'),  # Amount is too high
            "fees": Money(amount=1, currency='EUR'),
            "credited_wallet": self.legal_user_wallet,
            "preauthorization": preauthorization,
            "secure_mode_url": "http://www.ulule.com/"
        }
        preauthorized_payin = PreAuthorizedPayIn(**params)
        preauthorized_payin.save()

        self.assertEqual(preauthorized_payin.status, 'FAILED')
        self.assertEqual(preauthorized_payin.payment_type, 'PREAUTHORIZED')