示例#1
0
<?php

require_once 'CoinJar.php';
require_once 'config.php';
$coinjar = new CoinJar($user, $secret, $apikey, true);
// data from the post (it's supposed to be sent by CoinJar, is sent by POST!)
if (isset($_POST['uuid']) && isset($_POST['amount']) && isset($_POST['currency']) && isset($_POST['status']) && isset($_POST['ipn_digest'])) {
    if ($_POST['status'] == 'COMPLETED') {
        // calculate digest
        $digest = $coinjar->IPNDigest($_POST['uuid'], $_POST['amount'], $_POST['currency'], $_POST['status']);
        if ($digest == $_POST['ipn_digest']) {
            $order = json_decode($coinjar->order($_POST['uuid']));
            if ($order != null) {
                if ($_POST['amount'] == $order->order->amount && $_POST['currency'] == $order->order->currency && $_POST['status'] == $order->order->status) {
                    echo "THE REQUEST IS OK!";
                } else {
                    echo "WRONG REQUEST! (data does not match)";
                }
            } else {
                echo "WRONG REQUEST! (order does not exists)";
            }
        } else {
            echo "WRONG REQUEST! (IPN digest is not correct)";
        }
    } else {
        echo "WRONG REQUEST! (status is not COMPLETED)";
    }
} else {
    echo "WRONG REQUEST! (missing fields)";
}
示例#2
0
 public static function processPayment()
 {
     if (osc_get_preference('coinjar_sandbox', 'payment') != 1) {
         $coinjar = new CoinJar(payment_decrypt(osc_get_preference('coinjar_merchant_user', 'payment')), payment_decrypt(osc_get_preference('coinjar_merchant_password', 'payment')), payment_decrypt(osc_get_preference('coinjar_api_key', 'payment')));
     } else {
         $coinjar = new CoinJar(payment_decrypt(osc_get_preference('coinjar_sb_merchant_user', 'payment')), payment_decrypt(osc_get_preference('coinjar_sb_merchant_password', 'payment')), payment_decrypt(osc_get_preference('coinjar_sb_api_key', 'payment')), true);
     }
     // data from the post (it's supposed to be sent by CoinJar, is sent by POST!)
     if (Params::existParam('uuid') && Params::existParam('amount') && Params::existParam('currency') && Params::existParam('status') && Params::existParam('ipn_digest')) {
         if (Params::getParam('status') == 'COMPLETED') {
             $digest = $coinjar->IPNDigest(Params::getParam('uuid'), Params::getParam('amount'), Params::getParam('currency'), Params::getParam('status'));
             if ($digest == Params::getParam('ipn_digest')) {
                 $order = json_decode($coinjar->order(Params::getParam('uuid')));
                 if ($order != null) {
                     if (Params::getParam('amount') == $order->order->amount && Params::getParam('currency') == $order->order->currency && Params::getParam('status') == $order->order->status) {
                         $payment = ModelPayment::newInstance()->getPayment($order->order->uuid);
                         if (!$payment) {
                             $data = payment_get_custom(Params::getParam('extra'));
                             $product_type = explode('x', Params::getParam('item_number'));
                             // SAVE TRANSACTION LOG
                             $payment_id = ModelPayment::newInstance()->saveLog($data['concept'], $order->order->uuid, $order->order->amount, $order->order->currenct, $data['email'], $data['user'], $data['itemid'], $product_type[0], 'COINJAR');
                             //source
                             if ($product_type[0] == '101') {
                                 ModelPayment::newInstance()->payPublishFee($product_type[2], $payment_id);
                             } else {
                                 if ($product_type[0] == '201') {
                                     ModelPayment::newInstance()->payPremiumFee($product_type[2], $payment_id);
                                 } else {
                                     ModelPayment::newInstance()->addWallet($data['user'], $order->order->amount);
                                 }
                             }
                             return PAYMENT_COMPLETED;
                         } else {
                             return PAYMENT_ALREADY_PAID;
                         }
                     }
                 }
             }
         }
     }
     return PAYMENT_PENDING;
 }
示例#3
0
<?php

require_once 'CoinJar.php';
require_once 'config.php';
$coinjar = new CoinJar($user, $secret, $apikey, true);
$account = $coinjar->accountInformation();
print_r($account);
$items[0]['name'] = 'Name';
$items[0]['quantity'] = 1;
$items[0]['amount'] = 2;
$order = $coinjar->createOrder($items, 'USD', 'invoice#1', 'coinjar-php', 'notify-url', 'retrn-url', 'cancel-url');
print_r($order);
//$ipn = $coinjar->simulateIPN('notify-url', 'uuid', 'amount', 'fee', 'currency', 'bitcoin_amount', 'bitcoin_address', 'merchant_reference', 'merchant_invoice');
//print_r($ipn);