Esempio n. 1
0
def charge(db, route, amount, return_url, billing_address=None):
    """Charge the given credit card (`route`).

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

    """
    assert isinstance(amount, (Decimal, Money)), type(amount)
    assert route
    assert route.network == 'mango-cc'

    participant = route.participant

    amount = Money(amount, 'EUR') if isinstance(amount, Decimal) else amount
    charge_amount, fee, vat = upcharge_card(amount)
    amount = charge_amount - fee

    wallet = participant.get_current_wallet(amount.currency, create=True)
    e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre').id
    payin = DirectPayIn()
    payin.AuthorId = participant.mangopay_user_id
    if billing_address:
        payin.Billing = {'Address': billing_address}
    payin.CreditedWalletId = wallet.remote_id
    payin.DebitedFunds = charge_amount.int()
    payin.CardId = route.address
    payin.SecureMode = 'FORCE'
    payin.SecureModeReturnURL = return_url
    payin.Fees = fee.int()
    payin.Tag = str(e_id)
    try:
        test_hook()
        payin.save()
    except Exception as e:
        error = repr_exception(e)
        return record_exchange_result(db, e_id, '', 'failed', error,
                                      participant)

    if payin.SecureModeRedirectURL:
        raise Redirect(payin.SecureModeRedirectURL)

    return record_exchange_result(db, e_id, payin.Id, payin.Status.lower(),
                                  repr_error(payin), participant)
Esempio n. 2
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)

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

    charge_amount, fee, vat = upcharge_card(amount)
    amount = charge_amount - fee

    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.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 Redirect(payin.ExecutionDetails.SecureModeRedirectURL)

    return record_exchange_result(db, e_id, payin.Status.lower(),
                                  repr_error(payin), participant)
Esempio n. 3
0
def charge(db, route, amount, return_url):
    """Charge the given credit card (`route`).

    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)
    assert route
    assert route.network == 'mango-cc'

    participant = route.participant

    charge_amount, fee, vat = upcharge_card(amount)
    amount = charge_amount - fee

    if not participant.mangopay_wallet_id:
        create_wallet(db, participant)

    e_id = record_exchange(db, route, amount, fee, vat, participant, 'pre').id
    payin = DirectPayIn()
    payin.AuthorId = participant.mangopay_user_id
    payin.CreditedWalletId = participant.mangopay_wallet_id
    payin.DebitedFunds = Money(int(charge_amount * 100), 'EUR')
    payin.CardId = route.address
    payin.SecureModeReturnURL = return_url
    payin.Fees = Money(int(fee * 100), 'EUR')
    payin.Tag = str(e_id)
    try:
        test_hook()
        payin.save()
    except Exception as e:
        error = repr_exception(e)
        return record_exchange_result(db, e_id, '', 'failed', error,
                                      participant)

    if payin.SecureModeRedirectURL:
        raise Redirect(payin.SecureModeRedirectURL)

    return record_exchange_result(db, e_id, payin.Id, payin.Status.lower(),
                                  repr_error(payin), participant)