Ejemplo n.º 1
0
def request_payout_ex(
        user_name, amount, description, proc_id,
        proc_detail, email, mobile, currency=None):
    '''Request for a one-time payout.

    user_name - the name of the individual that will receive the payout.
    amount - the amount to be given as payout.
    description - a short description for this transaction.
    proc_id - the processor id; see list of processors via get_processors
        method.
    proc_detail - the processor detail.
    email - the email of the individual that will receive the payout.
    mobile - the mobile number of the individual.
    currency - the currency to be used, defaults to PHP when None.

    Note:
      - Payout transaction fees are not subtracted to the amount but
        will be shouldered by the merchant. So if we send amount=500,
        with a processor whose fee is PhP 15, PhP 515 will be deducted
        from our DragonPay account.
      - Dragonpay will send a POST request to a registered endpoint url
        to notify us of the status of a payout transaction. See
        forms.DragonpayPayoutCallbackForm for the payload format.
    '''

    txn_id = generate_txn_id()
    context = {
        'txn_id': txn_id,
        'user_name': user_name,
        'amount': amount,
        'currency': currency,
        'description': description,
        'processor_id': proc_id,
        'processor_detail': proc_detail,
        'timestamp': datetime.now(),
        'email': email,
        'mobile': mobile,
    }

    response_code = _dragonpay_get_wrapper(
        'RequestPayoutEx', context=context, payout=True)

    if response_code == '0':
        # save the dragonpay payout transaction to the database
        DragonpayPayout.create_from_dict(context)
    else:
        try:
            logger.error(
                '[%s] %s', response_code,
                DRAGONPAY_PAYOUT_ERROR_CODES[response_code])
        except KeyError:
            # Error is not in listed keys
            logger.error(
                'Error code [%s] not in DRAGONPAY_PAYOUT_ERROR_CODES',
                response_code)

    return response_code, txn_id
Ejemplo n.º 2
0
def get_txn_token(amount, description, email, txn_id=None, **params):
    '''Requests for a new DragonPay transaction and returns its txn_id and token.
    If not txn_id is passed, this method will generate one.

    return (tuple) - (txn_id, token)'''

    logger.debug('get_txn_token %s %s %s %s', email, amount, description,
                 params)

    txn_id = txn_id or generate_txn_id()
    context = {
        'txn_id': txn_id,
        'amount': amount,
        'email': email,
        'description': description
    }

    logger.debug('params %s', params)
    # include the params in the context
    for key, value in params.iteritems():
        if dp_settings.DRAGONPAY_ENCRYPT_PARAMS:
            # we cannot have a value of more than 47 chars since the
            # equivalent encrypted value will be more than 80 chars
            if len(value) > 47:
                raise ParamTooLong('Param %s when encrypted is > 80 chars')

            # Encrypt the params to obfuscate the payload
            logger.debug('Encrypting %s', value)
            value = encrypt_data(value)

        else:
            if len(value) > 80:
                raise ParamTooLong('Param %s length is > 80 chars')

        context[key] = value

    logger.debug('get_txn_token payload: %s', context)
    token = _dragonpay_get_wrapper('GetTxnToken', context=context)

    context['token'] = token
    context.update(params)  # include the raw params back to context
    DragonpayTransaction.create_from_dict(context)

    # check if the response token is an error code
    if len(token) < 4:
        msg = '[%s] %s' % (token, DRAGONPAY_ERROR_CODES[token])
        logger.error(msg)
        raise DragonpayException(msg)

    logger.debug('[%s] token %s for %s PhP %s', txn_id, token, email, amount)

    return txn_id, token
Ejemplo n.º 3
0
def get_txn_token(amount, description, email, txn_id=None, **params):
    '''Requests for a new DragonPay transaction and returns its txn_id and token.
    If not txn_id is passed, this method will generate one.

    return (tuple) - (txn_id, token)'''

    logger.debug('get_txn_token %s %s %s %s', email, amount, description,
                 params)

    txn_id = txn_id or generate_txn_id()
    context = {
        'txn_id': txn_id,
        'amount': amount,
        'email': email,
        'description': 'description'
    }

    logger.debug('params %s', params)
    # include the params in the context
    for key, value in params.iteritems():
        if dp_settings.DRAGONPAY_ENCRYPT_PARAMS:
            # Encrypt the params to obfuscate the payload
            logger.debug('Encrypting %s', value)
            value = encrypt_data(value)

        context[key] = value

    logger.debug('get_txn_token payload: %s', context)
    token = _dragonpay_get_wrapper('GetTxnToken', context=context)

    context['token'] = token
    context.update(params)  # include the raw params back to context
    DragonpayTransaction.create_from_dict(context)

    # check if the response token is an error code
    if len(token) < 4:
        logger.error('[%s] Dragonpay Error: %s', token,
                     DRAGONPAY_ERROR_CODES[token])

        return

    logger.debug('[%s] token %s for %s PhP %s', txn_id, token, email, amount)

    return txn_id, token