Beispiel #1
0
function test_voucher_comm($v)
{
    echo "commission on voucher for " . internal_to_numstr($v, 2) . " is " . internal_to_numstr(commission_on_deposit_mtgox_fiat_voucher($v), 4) . "<br/>\n";
}
Beispiel #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);
}