コード例 #1
0
 def test_payin_bank_wire_callback(self, Get):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x')
     for status in ('failed', 'succeeded'):
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         e_id = record_exchange(self.db, route, 11, 0, 0, homer, 'pre')
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_"+status_up+"&RessourceId=123456790"
         payin = PayIn()
         payin.Status = status_up
         payin.ResultCode = '000001' if error else '000000'
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         payin.Tag = str(e_id)
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 11
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         assert status[:4] in emails[0]['subject']
         homer.update_status('active')  # reset for next loop run
コード例 #2
0
ファイル: exchanges.py プロジェクト: fracolo/liberapay.com
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
コード例 #3
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
コード例 #4
0
ファイル: models.py プロジェクト: webu/django-mangopay
 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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
0
ファイル: exchanges.py プロジェクト: Changaco/liberapay.com
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)
コード例 #8
0
 def test_payin_bank_wire_callback(self, Get):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x')
     for status in ('failed', 'succeeded'):
         status_up = status.upper()
         error = 'FOO' if status == 'failed' else None
         e_id = record_exchange(self.db, route, 11, 0, 0, homer, 'pre')
         assert homer.balance == 0
         homer.close(None)
         assert homer.status == 'closed'
         qs = "EventType=PAYIN_NORMAL_" + status_up + "&RessourceId=123456790"
         payin = PayIn()
         payin.Status = status_up
         payin.ResultCode = '000001' if error else '000000'
         payin.ResultMessage = error
         payin.AuthorId = homer.mangopay_user_id
         payin.PaymentType = 'BANK_WIRE'
         pd = payin.PaymentDetails = PayInPaymentDetailsBankWire()
         pd.DeclaredDebitedFunds = Money(1100, 'EUR').__dict__
         pd.DeclaredFees = Money(0, 'EUR').__dict__
         payin.CreditedFunds = Money(1100, 'EUR')
         payin.Tag = str(e_id)
         Get.return_value = payin
         r = self.callback(qs)
         assert r.code == 200, r.text
         homer = homer.refetch()
         if status == 'succeeded':
             assert homer.balance == 11
             assert homer.status == 'active'
         else:
             assert homer.balance == 0
             assert homer.status == 'closed'
         emails = self.get_emails()
         assert len(emails) == 1
         assert emails[0]['to'][0] == 'homer <%s>' % homer.email
         assert status[:4] in emails[0]['subject']
         homer.update_status('active')  # reset for next loop run
コード例 #9
0
 def _test_payin_bank_wire_callback_amount_mismatch(self, Get, fee):
     homer = self.homer
     route = ExchangeRoute.insert(homer, 'mango-bw', 'x')
     e_id = record_exchange(self.db, route, 11, 0, 0, homer, 'pre')
     assert homer.balance == 0
     homer.close(None)
     assert homer.status == 'closed'
     qs = "EventType=PAYIN_NORMAL_SUCCEEDED&RessourceId=123456790"
     payin = PayIn()
     payin.Status = 'SUCCEEDED'
     payin.ResultCode = '000000'
     payin.ResultMessage = None
     payin.AuthorId = homer.mangopay_user_id
     payin.PaymentType = 'BANK_WIRE'
     pd = payin.PaymentDetails = PayInPaymentDetailsBankWire()
     pd.DeclaredDebitedFunds = Money(4500, 'EUR').__dict__
     pd.DeclaredFees = Money(100, 'EUR').__dict__
     payin.DebitedFunds = Money(302, 'EUR')
     payin.Fees = Money(fee, 'EUR')
     payin.CreditedFunds = Money(302 - fee, 'EUR')
     payin.Tag = str(e_id)
     Get.return_value = payin
     r = self.callback(qs)
     assert r.code == 200, r.text
     e = self.db.one("SELECT * FROM exchanges WHERE id = %s", (e_id, ))
     assert e.amount == D(payin.CreditedFunds.Amount) / D(100)
     assert e.fee == D(fee) / D(100)
     assert e.vat == D('0.01')
     assert e.status == 'succeeded'
     homer = homer.refetch()
     assert homer.balance == e.amount
     assert homer.status == 'active'
     emails = self.get_emails()
     assert len(emails) == 1
     assert emails[0]['to'][0] == 'homer <%s>' % homer.email
     assert 'succ' in emails[0]['subject']