Esempio n. 1
0
function test_mtgox_withdraw_fiat_coupon()
{
    $mtgox = new MtGox_API(MTGOX_KEY, MTGOX_SECRET);
    $ret = $mtgox->deposit_coupon("MTGOX-USD-EUSCF-JFLF2-ALZ7F-AE50E");
    // $ret = $mtgox->withdraw_fiat_coupon('0.01');
    var_dump($ret);
}
Esempio n. 2
0
function redeem_mtgox_fiat_voucher($code)
{
    global $is_logged_in;
    if (!ENABLE_MTGOX_VOUCHERS) {
        throw Error('MtGox vouchers are not enabled on this site', 'Redeeming MtGox voucher codes is disabled.');
    }
    $mtgox = new MtGox_API(MTGOX_KEY, MTGOX_SECRET);
    $result = $mtgox->deposit_coupon($code);
    // echo "result: <pre>" . var_dump($result) . "</pre><br/>\n";
    // successful coupon deposit:
    //
    // array(4) {
    //   ["amount"]=>  float(0.01)
    //   ["currency"]=>  string(3) "BTC"
    //   ["reference"]=>  string(36) "beabf9ce-07b6-4852-ae71-4cfc671ff35d"
    //   ["status"]=>     string(49) "Your account has been credited by 0.01000000 BTC"
    // }
    // trying to redeem an already-spent code - note no 'status':
    //
    // array(1) {
    //   ["error"]=>  string(59) "This code cannot be redeemed (non existing or already used)"
    // }
    if (isset($result['error'])) {
        throw new Exception($result['error']);
    }
    $amount = numstr_to_internal(cleanup_string($result['amount']));
    $curr_type = cleanup_string($result['currency']);
    // $reference = cleanup_string($result['reference'], '-');
    $status = cleanup_string($result['status']);
    // echo "<p>When we tried to redeem that voucher into our account, MtGox said: <strong>$status</strong></p>\n";
    $commission = commission_on_deposit_mtgox_fiat_voucher($amount);
    $amount = gmp_strval(gmp_sub($amount, $commission));
    $query = "\n        INSERT INTO requests (req_type, uid, amount, commission, curr_type, status)\n        VALUES ('DEPOS', '{$is_logged_in}', '{$amount}', '{$commission}', '{$curr_type}', 'FINAL');\n    ";
    do_query($query);
    add_funds(1, $commission, $curr_type);
    add_funds($is_logged_in, $amount, $curr_type);
    return array($curr_type, $amount);
}