Пример #1
0
def payin_bank_wire(db, participant, debit_amount):
    """Prepare to receive a bank wire payin.

    The amount should be how much the user intends to send, not how much will
    arrive in the wallet.
    """

    route = ExchangeRoute.from_network(participant, 'mango-bw')
    if not route:
        route = ExchangeRoute.insert(participant, 'mango-bw', 'x')

    amount, fee, vat = skim_amount(debit_amount, FEE_PAYIN_BANK_WIRE)

    e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre')
    payin = PayIn()
    payin.AuthorId = participant.mangopay_user_id
    if not participant.mangopay_wallet_id:
        create_wallet(db, participant)
    payin.CreditedWalletId = participant.mangopay_wallet_id
    payin.ExecutionDetails = PayInExecutionDetailsDirect()
    payin.PaymentDetails = PayInPaymentDetailsBankWire(
        DeclaredDebitedFunds=Money(int(debit_amount * 100), 'EUR'),
        DeclaredFees=Money(int(fee * 100), 'EUR'),
    )
    payin.Tag = str(e_id)
    try:
        test_hook()
        payin = mangoapi.payIns.Create(payin)
    except Exception as e:
        error = repr_exception(e)
        return None, record_exchange_result(db, e_id, 'failed', error, participant)

    e = record_exchange_result(db, e_id, payin.Status.lower(), repr_error(payin), participant)
    return payin, e
Пример #2
0
	def create_payin_direct_card(card, data):
		# create pay-in CARD DIRECT
		payIn = PayIn()
		payIn.CreditedWalletId = data['wallet'].Id
		payIn.AuthorId = data['wallet'].Owners[0]
		payIn.DebitedFunds = Money()
		payIn.DebitedFunds.Amount = data.amount
		payIn.DebitedFunds.Currency = 'EUR'
		payIn.Fees = Money()
		payIn.Fees.Amount = data.fee
		payIn.Fees.Currency = 'EUR'

		# payment type as CARD
		payIn.PaymentDetails = PayInPaymentDetailsCard()
		if (card.CardType == 'CB' or card.CardType == 'VISA' or card.CardType == 'MASTERCARD' or card.CardType == CardType.CB_VISA_MASTERCARD):
			payIn.PaymentDetails.CardType = CardType.CB_VISA_MASTERCARD
		elif (card.CardType == CardType.AMEX):
			payIn.PaymentDetails.CardType = CardType.AMEX

		# execution type as DIRECT
		payIn.ExecutionDetails = PayInExecutionDetailsDirect()
		payIn.ExecutionDetails.CardId = card.Id
		payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'
		
		return self.sdk.payIns.Create(payIn)
Пример #3
0
    def getJohnsPayInCardDirect(self, wallet = None):
        """Creates Pay-In Card Direct object
        return PayIn
        """
        if wallet == None:
            wallet = self.getJohnsWallet()

        cardRegistration = CardRegistration()
        cardRegistration.UserId = wallet.Owners[0]
        cardRegistration.Currency = 'EUR'
        cardRegistration = self.sdk.cardRegistrations.Create(cardRegistration)
        cardRegistration.RegistrationData = self.getPaylineCorrectRegistartionData(cardRegistration)
        cardRegistration = self.sdk.cardRegistrations.Update(cardRegistration)
        card = self.sdk.cards.Get(cardRegistration.CardId)
            
        # create pay-in CARD DIRECT
        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = wallet.Owners[0]
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 10000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 0
        payIn.Fees.Currency = 'EUR'
        # payment type as CARD
        payIn.PaymentDetails = PayInPaymentDetailsCard()
        payIn.PaymentDetails.CardType = card.CardType
        # execution type as DIRECT
        payIn.ExecutionDetails = PayInExecutionDetailsDirect()
        payIn.ExecutionDetails.CardId = card.Id
        payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'
        return self.sdk.payIns.Create(payIn)
Пример #4
0
def payin_bank_wire(db, participant, debit_amount):
    """Prepare to receive a bank wire payin.

    The amount should be how much the user intends to send, not how much will
    arrive in the wallet.
    """

    route = ExchangeRoute.from_network(participant, 'mango-bw')
    if not route:
        route = ExchangeRoute.insert(participant, 'mango-bw', 'x')

    amount, fee, vat = skim_amount(debit_amount, FEE_PAYIN_BANK_WIRE)

    e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre')
    payin = PayIn()
    payin.AuthorId = participant.mangopay_user_id
    if not participant.mangopay_wallet_id:
        create_wallet(db, participant)
    payin.CreditedWalletId = participant.mangopay_wallet_id
    payin.ExecutionDetails = PayInExecutionDetailsDirect()
    payin.PaymentDetails = PayInPaymentDetailsBankWire(
        DeclaredDebitedFunds=Money(int(debit_amount * 100), 'EUR'),
        DeclaredFees=Money(int(fee * 100), 'EUR'),
    )
    payin.Tag = str(e_id)
    try:
        test_hook()
        payin = mangoapi.payIns.Create(payin)
    except Exception as e:
        error = repr_exception(e)
        return None, record_exchange_result(db, e_id, 'failed', error, participant)

    e = record_exchange_result(db, e_id, payin.Status.lower(), repr_error(payin), participant)
    return payin, e
    def getJohnsPayInCardDirect(self, wallet=None):
        """Creates Pay-In Card Direct object
        return PayIn
        """
        if wallet == None:
            wallet = self.getJohnsWallet()

        cardRegistration = CardRegistration()
        cardRegistration.UserId = wallet.Owners[0]
        cardRegistration.Currency = 'EUR'
        cardRegistration = self.sdk.cardRegistrations.Create(cardRegistration)
        cardRegistration.RegistrationData = self.getPaylineCorrectRegistartionData(
            cardRegistration)
        cardRegistration = self.sdk.cardRegistrations.Update(cardRegistration)
        card = self.sdk.cards.Get(cardRegistration.CardId)

        # create pay-in CARD DIRECT
        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = wallet.Owners[0]
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 10000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 0
        payIn.Fees.Currency = 'EUR'
        # payment type as CARD
        payIn.PaymentDetails = PayInPaymentDetailsCard()
        payIn.PaymentDetails.CardType = card.CardType
        # execution type as DIRECT
        payIn.ExecutionDetails = PayInExecutionDetailsDirect()
        payIn.ExecutionDetails.CardId = card.Id
        payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'
        return self.sdk.payIns.Create(payIn)
Пример #6
0
    def create(self, debited_funds, fees=None, secure_mode_return_url=None):
        pay_in = PayIn()
        pay_in.AuthorId = self.mangopay_user.mangopay_id
        pay_in.CreditedUserId = self.mangopay_wallet.mangopay_user.mangopay_id
        pay_in.CreditedWalletId = self.mangopay_wallet.mangopay_id
        pay_in.DebitedFunds = python_money_to_mangopay_money(debited_funds)
        if not fees:
            fees = PythonMoney(0, debited_funds.currency)
        pay_in.Fees = python_money_to_mangopay_money(fees)

        payment_details = PayInPaymentDetailsCard()
        payment_details.CardType = "CB_VISA_MASTERCARD"
        pay_in.PaymentDetails = payment_details

        execution_details = PayInExecutionDetailsDirect()
        execution_details.CardId = self.mangopay_card.mangopay_id
        execution_details.SecureModeReturnURL = secure_mode_return_url
        execution_details.SecureMode = "DEFAULT"
        pay_in.ExecutionDetails = execution_details

        client = get_mangopay_api_client()
        created_pay_in = client.payIns.Create(pay_in)

        self.mangopay_id = created_pay_in.Id
        self._update(created_pay_in)
Пример #7
0
 def test_PayIns_PreAuthorizedDirect(self):
     cardPreAuthorization = self.getJohnsCardPreAuthorization()
     wallet = self.getJohnsWalletWithMoney()
     user = self.getJohn()
     # create pay-in PRE-AUTHORIZED DIRECT
     payIn = PayIn()
     payIn.CreditedWalletId = wallet.Id
     payIn.AuthorId = user.Id
     payIn.DebitedFunds = Money()
     payIn.DebitedFunds.Amount = 1000
     payIn.DebitedFunds.Currency = 'EUR'
     payIn.Fees = Money()
     payIn.Fees.Amount = 0
     payIn.Fees.Currency = 'EUR'
     # payment type as CARD
     payIn.PaymentDetails = PayInPaymentDetailsPreAuthorized()
     payIn.PaymentDetails.PreauthorizationId = cardPreAuthorization.Id
     # execution type as DIRECT
     payIn.ExecutionDetails = PayInExecutionDetailsDirect()
     payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'
     
     createPayIn = self.sdk.payIns.Create(payIn)
     
     self.assertTrue(len(createPayIn.Id) > 0)
     self.assertEqual(wallet.Id, createPayIn.CreditedWalletId)
     self.assertEqual('PREAUTHORIZED', createPayIn.PaymentType)
     self.assertIsInstance(createPayIn.PaymentDetails, PayInPaymentDetailsPreAuthorized)
     self.assertEqual('DIRECT', createPayIn.ExecutionType)
     self.assertIsInstance(createPayIn.ExecutionDetails, PayInExecutionDetailsDirect)
     self.assertIsInstance(createPayIn.DebitedFunds, Money)
     self.assertIsInstance(createPayIn.CreditedFunds, Money)
     self.assertIsInstance(createPayIn.Fees, Money)
     self.assertEqual(user.Id, createPayIn.AuthorId)
     self.assertEqual('SUCCEEDED', createPayIn.Status)
     self.assertEqual('PAYIN', createPayIn.Type)
Пример #8
0
    def test_PayIns_Create_DirectDebitDirect(self):
        #	! IMPORTANT NOTE !
        #
        # This test needs your manual confirmation on the web page (see note below)
        # Comment out line below to test payins with a mandate.
        return

        wallet = self.getJohnsWallet()
        user = self.getJohn()
        bankAccountId = self.getJohnsAccount().Id
        returnUrl = 'http://test.test'
        mandatePost = Mandate()
        mandatePost.BankAccountId = bankAccountId
        mandatePost.Culture = 'EN'
        mandatePost.ReturnURL = returnUrl
        mandate = self.sdk.mandates.Create(mandatePost)

        #	! IMPORTANT NOTE !
        #
        #	In order to make this test pass, at this place you have to set a breakpoint,
        #	navigate to URL the mandate.RedirectURL property points to and click "CONFIRM" button.

        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = user.Id
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 1000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 1
        payIn.Fees.Currency = 'EUR'

        payIn.PaymentDetails = PayInPaymentDetailsDirectDebit()
        payIn.PaymentDetails.MandateId = mandate.Id
        payIn.ExecutionDetails = PayInExecutionDetailsDirect()

        createPayIn = self.sdk.payIns.Create(payIn)

        self.assertTrue(int(createPayIn.Id) > 0)
        self.assertEqual(wallet.Id, createPayIn.CreditedWalletId)
        self.assertEqual('DIRECT_DEBIT', createPayIn.PaymentType)
        self.assertIsInstance(createPayIn.PaymentDetails,
                              PayInPaymentDetailsDirectDebit)
        self.assertEqual(createPayIn.PaymentDetails.MandateId, mandate.Id)
        self.assertEqual('DIRECT', createPayIn.ExecutionType)
        self.assertIsInstance(createPayIn.ExecutionDetails,
                              PayInExecutionDetailsDirect)
        self.assertEqual(user.Id, createPayIn.AuthorId)
        self.assertEqual('CREATED', createPayIn.Status)
        self.assertEqual('PAYIN', createPayIn.Type)
        self.assertIsInstance(createPayIn.DebitedFunds, Money)
        self.assertEqual(1000, createPayIn.DebitedFunds.Amount)
        self.assertEqual('EUR', createPayIn.DebitedFunds.Currency)
        self.assertIsInstance(createPayIn.Fees, Money)
        self.assertEqual(1, createPayIn.Fees.Amount)
        self.assertEqual('EUR', createPayIn.Fees.Currency)
Пример #9
0
    def test_PayIns_Create_DirectDebitDirect(self):
        #	! IMPORTANT NOTE !
        #
		# This test needs your manual confirmation on the web page (see note below)
        # Comment out line below to test payins with a mandate.
        return

        wallet = self.getJohnsWallet()
        user = self.getJohn()
        bankAccountId = self.getJohnsAccount().Id
        returnUrl = 'http://test.test'
        mandatePost = Mandate()
        mandatePost.BankAccountId = bankAccountId
        mandatePost.Culture = 'EN'
        mandatePost.ReturnURL = returnUrl
        mandate = self.sdk.mandates.Create(mandatePost)


        #	! IMPORTANT NOTE !
		#	
		#	In order to make this test pass, at this place you have to set a breakpoint,
		#	navigate to URL the mandate.RedirectURL property points to and click "CONFIRM" button.


        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = user.Id
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 1000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 1
        payIn.Fees.Currency = 'EUR'
        
        payIn.PaymentDetails = PayInPaymentDetailsDirectDebit()
        payIn.PaymentDetails.MandateId = mandate.Id
        payIn.ExecutionDetails = PayInExecutionDetailsDirect()

        createPayIn = self.sdk.payIns.Create(payIn)

        self.assertTrue(int(createPayIn.Id) > 0)
        self.assertEqual(wallet.Id, createPayIn.CreditedWalletId)
        self.assertEqual('DIRECT_DEBIT', createPayIn.PaymentType)
        self.assertIsInstance(createPayIn.PaymentDetails, PayInPaymentDetailsDirectDebit)
        self.assertEqual(createPayIn.PaymentDetails.MandateId, mandate.Id)
        self.assertEqual('DIRECT', createPayIn.ExecutionType)
        self.assertIsInstance(createPayIn.ExecutionDetails, PayInExecutionDetailsDirect)
        self.assertEqual(user.Id, createPayIn.AuthorId)
        self.assertEqual('CREATED', createPayIn.Status)
        self.assertEqual('PAYIN', createPayIn.Type)
        self.assertIsInstance(createPayIn.DebitedFunds, Money)
        self.assertEqual(1000, createPayIn.DebitedFunds.Amount)
        self.assertEqual('EUR', createPayIn.DebitedFunds.Currency)
        self.assertIsInstance(createPayIn.Fees, Money)
        self.assertEqual(1, createPayIn.Fees.Amount)
        self.assertEqual('EUR', createPayIn.Fees.Currency)
Пример #10
0
    def test_PayIns_Create_DirectDebitWeb(self):
        wallet = self.getJohnsWallet()
        user = self.getJohn()
        # create pay-in PRE-AUTHORIZED DIRECT
        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = user.Id
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 10000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 100
        payIn.Fees.Currency = 'EUR'

        # payment type as CARD
        payIn.PaymentDetails = PayInPaymentDetailsDirectDebit()
        payIn.PaymentDetails.DirectDebitType = 'GIROPAY'
        payIn.ExecutionDetails = PayInExecutionDetailsWeb()
        payIn.ExecutionDetails.ReturnURL = 'http://www.mysite.com/returnURL/'
        payIn.ExecutionDetails.Culture = 'FR'
        payIn.ExecutionDetails.TemplateURLOptions = PayInTemplateURLOptions()
        payIn.ExecutionDetails.TemplateURLOptions.PAYLINE = 'https://www.maysite.com/payline_template/'

        createPayIn = self.sdk.payIns.Create(payIn)

        self.assertTrue(int(createPayIn.Id) > 0)
        self.assertEqual(wallet.Id, createPayIn.CreditedWalletId)
        self.assertEqual('DIRECT_DEBIT', createPayIn.PaymentType)
        self.assertIsInstance(createPayIn.PaymentDetails,
                              PayInPaymentDetailsDirectDebit)
        self.assertEqual(createPayIn.PaymentDetails.DirectDebitType, 'GIROPAY')
        self.assertEqual('WEB', createPayIn.ExecutionType)
        self.assertIsInstance(createPayIn.ExecutionDetails,
                              PayInExecutionDetailsWeb)
        self.assertEqual('FR', createPayIn.ExecutionDetails.Culture)
        self.assertEqual(user.Id, createPayIn.AuthorId)
        self.assertEqual('CREATED', createPayIn.Status)
        self.assertEqual('PAYIN', createPayIn.Type)
        self.assertIsInstance(createPayIn.DebitedFunds, Money)
        self.assertEqual(10000, createPayIn.DebitedFunds.Amount)
        self.assertEqual('EUR', createPayIn.DebitedFunds.Currency)
        self.assertIsInstance(createPayIn.CreditedFunds, Money)
        self.assertEqual(9900, createPayIn.CreditedFunds.Amount)
        self.assertEqual('EUR', createPayIn.CreditedFunds.Currency)
        self.assertIsInstance(createPayIn.Fees, Money)
        self.assertEqual(100, createPayIn.Fees.Amount)
        self.assertEqual('EUR', createPayIn.Fees.Currency)
        self.assertIsNotNone(createPayIn.ExecutionDetails.ReturnURL)
        self.assertIsNotNone(createPayIn.ExecutionDetails.RedirectURL)
        self.assertIsNotNone(createPayIn.ExecutionDetails.TemplateURL)
Пример #11
0
 def create(self, tag=None):
     pay_in = PayIn()
     pay_in.Tag = tag
     pay_in.AuthorId = self.mangopay_user.mangopay_id
     pay_in.CreditedUserId = self.mangopay_user.mangopay_id
     pay_in.CreditedWalletId = self.mangopay_wallet.mangopay_id
     pay_in.DebitedFunds = python_money_to_mangopay_money(
         self.debited_funds)
     pay_in.Fees = python_money_to_mangopay_money(self.fees)
     pay_in.PaymentDetails = self._get_payment_details()
     pay_in.ExecutionDetails = self._get_execution_details()
     client = get_mangopay_api_client()
     created_pay_in = client.payIns.Create(pay_in)
     self.mangopay_id = created_pay_in.Id
     self._update(created_pay_in)
Пример #12
0
 def create(self, tag=None):
     pay_in = PayIn()
     pay_in.Tag = tag
     pay_in.AuthorId = self.mangopay_user.mangopay_id
     pay_in.CreditedUserId = self.mangopay_user.mangopay_id
     pay_in.CreditedWalletId = self.mangopay_wallet.mangopay_id
     pay_in.DebitedFunds = python_money_to_mangopay_money(
         self.debited_funds)
     pay_in.Fees = python_money_to_mangopay_money(self.fees)
     pay_in.PaymentDetails = self._get_payment_details()
     pay_in.ExecutionDetails = self._get_execution_details()
     client = get_mangopay_api_client()
     created_pay_in = client.payIns.Create(pay_in)
     self.mangopay_id = created_pay_in.Id
     self._update(created_pay_in)
Пример #13
0
    def test_PayIns_Create_DirectDebitWeb(self):
        wallet = self.getJohnsWallet()
        user = self.getJohn()
        # create pay-in PRE-AUTHORIZED DIRECT
        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = user.Id
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 10000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 100
        payIn.Fees.Currency = 'EUR'
        
        # payment type as CARD
        payIn.PaymentDetails = PayInPaymentDetailsDirectDebit()
        payIn.PaymentDetails.DirectDebitType = 'GIROPAY'
        payIn.ExecutionDetails = PayInExecutionDetailsWeb()
        payIn.ExecutionDetails.ReturnURL = 'http://www.mysite.com/returnURL/'
        payIn.ExecutionDetails.Culture = 'FR'
        payIn.ExecutionDetails.TemplateURLOptions = PayInTemplateURLOptions()
        payIn.ExecutionDetails.TemplateURLOptions.PAYLINE = 'https://www.maysite.com/payline_template/'

        createPayIn = self.sdk.payIns.Create(payIn)

        self.assertTrue(int(createPayIn.Id) > 0)
        self.assertEqual(wallet.Id, createPayIn.CreditedWalletId)
        self.assertEqual('DIRECT_DEBIT', createPayIn.PaymentType)
        self.assertIsInstance(createPayIn.PaymentDetails, PayInPaymentDetailsDirectDebit)
        self.assertEqual(createPayIn.PaymentDetails.DirectDebitType, 'GIROPAY')
        self.assertEqual('WEB', createPayIn.ExecutionType)
        self.assertIsInstance(createPayIn.ExecutionDetails, PayInExecutionDetailsWeb)
        self.assertEqual('FR', createPayIn.ExecutionDetails.Culture)
        self.assertEqual(user.Id, createPayIn.AuthorId)
        self.assertEqual('CREATED', createPayIn.Status)
        self.assertEqual('PAYIN', createPayIn.Type)
        self.assertIsInstance(createPayIn.DebitedFunds, Money)
        self.assertEqual(10000, createPayIn.DebitedFunds.Amount)
        self.assertEqual('EUR', createPayIn.DebitedFunds.Currency)
        self.assertIsInstance(createPayIn.CreditedFunds, Money)
        self.assertEqual(9900, createPayIn.CreditedFunds.Amount)
        self.assertEqual('EUR', createPayIn.CreditedFunds.Currency)
        self.assertIsInstance(createPayIn.Fees, Money)
        self.assertEqual(100, createPayIn.Fees.Amount)
        self.assertEqual('EUR', createPayIn.Fees.Currency)
        self.assertIsNotNone(createPayIn.ExecutionDetails.ReturnURL)
        self.assertIsNotNone(createPayIn.ExecutionDetails.RedirectURL)
        self.assertIsNotNone(createPayIn.ExecutionDetails.TemplateURL)
Пример #14
0
    def getJohnsWalletWithMoney(self, amount=10000):
        """Creates static JohnsWallet (wallets belonging to John) if not created yet
        return Wallet
        """
        if self._johnsWalletWithMoney == None:
            john = self.getJohn()
            wallet = Wallet()
            wallet.Owners = [john.Id]
            wallet.Currency = 'EUR'
            wallet.Description = 'WALLET IN EUR'
            wallet = self.sdk.wallets.Create(wallet)
            cardRegistration = CardRegistration()
            cardRegistration.UserId = wallet.Owners[0]
            cardRegistration.Currency = 'EUR'
            cardRegistration = self.sdk.cardRegistrations.Create(
                cardRegistration)
            cardRegistration.RegistrationData = self.getPaylineCorrectRegistartionData(
                cardRegistration)
            cardRegistration = self.sdk.cardRegistrations.Update(
                cardRegistration)
            card = self.sdk.cards.Get(cardRegistration.CardId)
            # create pay-in CARD DIRECT
            payIn = PayIn()
            payIn.CreditedWalletId = wallet.Id
            payIn.AuthorId = cardRegistration.UserId
            payIn.DebitedFunds = Money()
            payIn.DebitedFunds.Amount = amount
            payIn.DebitedFunds.Currency = 'EUR'
            payIn.Fees = Money()
            payIn.Fees.Amount = 0
            payIn.Fees.Currency = 'EUR'
            # payment type as CARD
            payIn.PaymentDetails = PayInPaymentDetailsCard()
            if (card.CardType == 'CB' or card.CardType == 'VISA'
                    or card.CardType == 'MASTERCARD'
                    or card.CardType == CardType.CB_VISA_MASTERCARD):
                payIn.PaymentDetails.CardType = CardType.CB_VISA_MASTERCARD
            # elif (card.CardType == CardType.AMEX):
            #    payIn.PaymentDetails.CardType = CardType.AMEX

            # execution type as DIRECT
            payIn.ExecutionDetails = PayInExecutionDetailsDirect()
            payIn.ExecutionDetails.CardId = card.Id
            payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'
            # create Pay-In
            self.sdk.payIns.Create(payIn)
            self._johnsWalletWithMoney = self.sdk.wallets.Get(wallet.Id)
        return self._johnsWalletWithMoney
Пример #15
0
def charge(db, participant, amount, return_url):
    """Charge the participant's credit card.

    Amount should be the nominal amount. We'll compute fees below this function
    and add it to amount to end up with charge_amount.

    """
    typecheck(amount, Decimal)

    if participant.is_suspicious:
        raise UserIsSuspicious

    route = ExchangeRoute.from_network(participant, 'mango-cc')
    assert route

    charge_amount, fee = upcharge(amount)
    amount = charge_amount - fee

    e_id = record_exchange(db, route, amount, fee, participant, 'pre')
    payin = PayIn()
    payin.AuthorId = participant.mangopay_user_id
    if not participant.mangopay_wallet_id:
        create_wallet(db, participant)
    payin.CreditedWalletId = participant.mangopay_wallet_id
    payin.DebitedFunds = Money(int(charge_amount * 100), 'EUR')
    payin.ExecutionDetails = PayInExecutionDetailsDirect(
        CardId=route.address,
        SecureModeReturnURL=return_url,
    )
    payin.Fees = Money(int(fee * 100), 'EUR')
    payin.PaymentDetails = PayInPaymentDetailsCard(
        CardType='CB_VISA_MASTERCARD')
    payin.Tag = str(e_id)
    try:
        test_hook()
        payin = mangoapi.payIns.Create(payin)
    except Exception as e:
        error = repr_exception(e)
        return record_exchange_result(db, e_id, 'failed', error, participant)

    if payin.ExecutionDetails.SecureModeRedirectURL:
        raise Response(
            302,
            headers={'Location': payin.ExecutionDetails.SecureModeRedirectURL})

    return record_exchange_result(db, e_id, 'succeeded', None, participant)
Пример #16
0
    def getJohnsPayInCardWeb(self):
        """Creates Pay-In Card Web object"""
        wallet = self.getJohnsWallet()
        user = self.getJohn()

        payIn = PayIn()
        payIn.AuthorId = user.Id
        payIn.CreditedUserId = user.Id
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.DebitedFunds.Amount = 1000
        payIn.Fees = Money()
        payIn.Fees.Currency = 'EUR'
        payIn.Fees.Amount = 5
        payIn.CreditedWalletId = wallet.Id
        payIn.PaymentDetails = self.getPayInPaymentDetailsCard()
        payIn.ExecutionDetails = self.getPayInExecutionDetailsWeb()
        return self.sdk.payIns.Create(payIn)
Пример #17
0
 def getJohnsPayInCardWeb(self):
     """Creates Pay-In Card Web object"""       
     wallet = self.getJohnsWallet()
     user = self.getJohn()
         
     payIn = PayIn()
     payIn.AuthorId = user.Id
     payIn.CreditedUserId = user.Id
     payIn.DebitedFunds = Money()
     payIn.DebitedFunds.Currency = 'EUR'
     payIn.DebitedFunds.Amount = 1000
     payIn.Fees = Money()
     payIn.Fees.Currency = 'EUR'
     payIn.Fees.Amount = 5
     payIn.CreditedWalletId = wallet.Id
     payIn.PaymentDetails = self.getPayInPaymentDetailsCard()
     payIn.ExecutionDetails = self.getPayInExecutionDetailsWeb()
     return self.sdk.payIns.Create(payIn)
Пример #18
0
    def getJohnsPayInBankWireDirect(self):
        wallet = self.getJohnsWallet()
        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = wallet.Owners[0]

        # payment type as CARD
        payIn.PaymentDetails = PayInPaymentDetailsBankWire()
        payIn.PaymentDetails.DeclaredDebitedFunds = Money()
        payIn.PaymentDetails.DeclaredFees = Money()
        payIn.PaymentDetails.DeclaredDebitedFunds.Currency = 'EUR'
        payIn.PaymentDetails.DeclaredFees.Currency = 'EUR'
        payIn.PaymentDetails.DeclaredDebitedFunds.Amount = 10000
        payIn.PaymentDetails.DeclaredFees.Amount = 1000

        # execution type as DIRECT
        payIn.ExecutionDetails = PayInExecutionDetailsDirect()
        payIn.ExecutionType = ExecutionType.DIRECT
        return self.sdk.payIns.Create(payIn)
Пример #19
0
def charge(db, participant, amount, return_url):
    """Charge the participant's credit card.

    Amount should be the nominal amount. We'll compute fees below this function
    and add it to amount to end up with charge_amount.

    """
    typecheck(amount, Decimal)

    if participant.is_suspicious:
        raise UserIsSuspicious

    route = ExchangeRoute.from_network(participant, 'mango-cc')
    assert route

    charge_amount, fee = upcharge(amount)
    amount = charge_amount - fee

    e_id = record_exchange(db, route, amount, fee, participant, 'pre')
    payin = PayIn()
    payin.AuthorId = participant.mangopay_user_id
    if not participant.mangopay_wallet_id:
        create_wallet(db, participant)
    payin.CreditedWalletId = participant.mangopay_wallet_id
    payin.DebitedFunds = Money(int(charge_amount * 100), 'EUR')
    payin.ExecutionDetails = PayInExecutionDetailsDirect(
        CardId=route.address,
        SecureModeReturnURL=return_url,
    )
    payin.Fees = Money(int(fee * 100), 'EUR')
    payin.PaymentDetails = PayInPaymentDetailsCard(CardType='CB_VISA_MASTERCARD')
    payin.Tag = str(e_id)
    try:
        test_hook()
        payin = mangoapi.payIns.Create(payin)
    except Exception as e:
        error = repr_exception(e)
        return record_exchange_result(db, e_id, 'failed', error, participant)

    if payin.ExecutionDetails.SecureModeRedirectURL:
        raise Response(302, headers={'Location': payin.ExecutionDetails.SecureModeRedirectURL})

    return record_exchange_result(db, e_id, 'succeeded', None, participant)
Пример #20
0
    def getJohnsWalletWithMoney(self, amount = 10000):
        """Creates static JohnsWallet (wallets belonging to John) if not created yet
        return Wallet
        """
        if self._johnsWalletWithMoney == None:
            john = self.getJohn()
            wallet = Wallet()
            wallet.Owners = [john.Id]
            wallet.Currency = 'EUR'
            wallet.Description = 'WALLET IN EUR'            
            wallet = self.sdk.wallets.Create(wallet)    
            cardRegistration = CardRegistration()
            cardRegistration.UserId = wallet.Owners[0]
            cardRegistration.Currency = 'EUR'
            cardRegistration = self.sdk.cardRegistrations.Create(cardRegistration)
            cardRegistration.RegistrationData = self.getPaylineCorrectRegistartionData(cardRegistration)
            cardRegistration = self.sdk.cardRegistrations.Update(cardRegistration)
            card = self.sdk.cards.Get(cardRegistration.CardId)
            # create pay-in CARD DIRECT
            payIn = PayIn()
            payIn.CreditedWalletId = wallet.Id
            payIn.AuthorId = cardRegistration.UserId
            payIn.DebitedFunds = Money()
            payIn.DebitedFunds.Amount = amount
            payIn.DebitedFunds.Currency = 'EUR'
            payIn.Fees = Money()
            payIn.Fees.Amount = 0
            payIn.Fees.Currency = 'EUR'
            # payment type as CARD
            payIn.PaymentDetails = PayInPaymentDetailsCard()
            if (card.CardType == 'CB' or card.CardType == 'VISA' or card.CardType == 'MASTERCARD' or card.CardType == CardType.CB_VISA_MASTERCARD):
                payIn.PaymentDetails.CardType = CardType.CB_VISA_MASTERCARD
            # elif (card.CardType == CardType.AMEX):
            #    payIn.PaymentDetails.CardType = CardType.AMEX

            # execution type as DIRECT
            payIn.ExecutionDetails = PayInExecutionDetailsDirect()
            payIn.ExecutionDetails.CardId = card.Id
            payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'
            # create Pay-In
            self.sdk.payIns.Create(payIn)
            self._johnsWalletWithMoney = self.sdk.wallets.Get(wallet.Id)
        return self._johnsWalletWithMoney
Пример #21
0
 def getJohnsPayInBankWireDirect(self):
     wallet = self.getJohnsWallet()        
     payIn = PayIn()
     payIn.CreditedWalletId = wallet.Id
     payIn.AuthorId = wallet.Owners[0]
    
     # payment type as CARD
     payIn.PaymentDetails = PayInPaymentDetailsBankWire()
     payIn.PaymentDetails.DeclaredDebitedFunds = Money()
     payIn.PaymentDetails.DeclaredFees = Money()
     payIn.PaymentDetails.DeclaredDebitedFunds.Currency = 'EUR'
     payIn.PaymentDetails.DeclaredFees.Currency = 'EUR'
     payIn.PaymentDetails.DeclaredDebitedFunds.Amount = 10000
     payIn.PaymentDetails.DeclaredFees.Amount = 1000
    
     # execution type as DIRECT
     payIn.ExecutionDetails = PayInExecutionDetailsDirect()
     payIn.ExecutionType = ExecutionType.DIRECT
     return self.sdk.payIns.Create(payIn)
Пример #22
0
    def test_PayIns_PreAuthorizedDirect(self):
        cardPreAuthorization = self.getJohnsCardPreAuthorization()
        wallet = self.getJohnsWalletWithMoney()
        user = self.getJohn()
        # create pay-in PRE-AUTHORIZED DIRECT
        payIn = PayIn()
        payIn.CreditedWalletId = wallet.Id
        payIn.AuthorId = user.Id
        payIn.DebitedFunds = Money()
        payIn.DebitedFunds.Amount = 1000
        payIn.DebitedFunds.Currency = 'EUR'
        payIn.Fees = Money()
        payIn.Fees.Amount = 0
        payIn.Fees.Currency = 'EUR'
        # payment type as CARD
        payIn.PaymentDetails = PayInPaymentDetailsPreAuthorized()
        payIn.PaymentDetails.PreauthorizationId = cardPreAuthorization.Id
        # execution type as DIRECT
        payIn.ExecutionDetails = PayInExecutionDetailsDirect()
        payIn.ExecutionDetails.SecureModeReturnURL = 'http://test.com'

        createPayIn = self.sdk.payIns.Create(payIn)

        self.assertTrue(len(createPayIn.Id) > 0)
        self.assertEqual(wallet.Id, createPayIn.CreditedWalletId)
        self.assertEqual('PREAUTHORIZED', createPayIn.PaymentType)
        self.assertIsInstance(createPayIn.PaymentDetails,
                              PayInPaymentDetailsPreAuthorized)
        self.assertEqual('DIRECT', createPayIn.ExecutionType)
        self.assertIsInstance(createPayIn.ExecutionDetails,
                              PayInExecutionDetailsDirect)
        self.assertIsInstance(createPayIn.DebitedFunds, Money)
        self.assertIsInstance(createPayIn.CreditedFunds, Money)
        self.assertIsInstance(createPayIn.Fees, Money)
        self.assertEqual(user.Id, createPayIn.AuthorId)
        self.assertEqual('SUCCEEDED', createPayIn.Status)
        self.assertEqual('PAYIN', createPayIn.Type)
Пример #23
0
    def create(self, secure_mode_return_url):
        pay_in = PayIn()
        pay_in.AuthorId = self.mangopay_user.mangopay_id
        pay_in.CreditedUserId = self.mangopay_user.mangopay_id
        pay_in.CreditedWalletId = self.mangopay_wallet.mangopay_id
        pay_in.DebitedFunds = python_money_to_mangopay_money(
            self.debited_funds)
        pay_in.Fees = python_money_to_mangopay_money(self.fees)

        payment_details = PayInPaymentDetailsCard()
        payment_details.CardType = "CB_VISA_MASTERCARD"
        pay_in.PaymentDetails = payment_details

        execution_details = PayInExecutionDetailsDirect()
        execution_details.CardId = self.mangopay_card.mangopay_id
        execution_details.SecureModeReturnURL = secure_mode_return_url
        execution_details.SecureMode = "DEFAULT"
        pay_in.ExecutionDetails = execution_details

        client = get_mangopay_api_client()
        created_pay_in = client.payIns.Create(pay_in)

        self.mangopay_id = created_pay_in.Id
        self._update(created_pay_in)