public static function createOrder()
 {
     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);
     }
     $items[0]['name'] = Params::getParam('description');
     $items[0]['quantity'] = 1;
     $items[0]['amount'] = payment_get_amount(Params::getParam('itemnumber'));
     $order_json = $coinjar->createOrder($items, osc_get_preference('currency', 'payment'), Params::getParam('itemnumber'), osc_get_preference('coinjar_merchant_reference', 'payment'), osc_route_url('coinjar-notify', array('extra' => Params::getParam('extra'))), osc_route_url('coinjar-return', array('extra' => Params::getParam('extra'))), osc_route_url('coinjar-cancel', array('extra' => Params::getParam('extra'))));
     $order = json_decode($order_json);
     if (isset($order->order->uuid)) {
         echo json_encode(array('url' => $coinjar->orderPage($order->order->uuid), 'error' => 0));
     } else {
         echo json_encode(array('error' => 1, 'status' => @$order->order->status, 'msg' => @$order->order->error));
     }
 }
 public static function processPayment()
 {
     require_once osc_plugins_path() . osc_plugin_folder(__FILE__) . 'lib/Stripe.php';
     if (osc_get_preference('stripe_sandbox', 'payment') == 0) {
         $stripe = array("secret_key" => osc_get_preference('stripe_secret_key', 'payment'), "publishable_key" => osc_get_preference('stripe_public_key', 'payment'));
     } else {
         $stripe = array("secret_key" => osc_get_preference('stripe_secret_key_test', 'payment'), "publishable_key" => osc_get_preference('stripe_public_key_test', 'payment'));
     }
     Stripe::setApiKey($stripe['secret_key']);
     $token = Params::getParam('stripeToken');
     $data = payment_get_custom(Params::getParam('extra'));
     $amount = payment_get_amount($data['product']);
     if ($amount <= 0) {
         return PAYMENT_FAILED;
     }
     $customer = Stripe_Customer::create(array('email' => $data['email'], 'card' => $token));
     try {
         $charge = @Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $amount * 100, 'currency' => osc_get_preference("currency", "payment")));
         if ($charge->__get('paid') == 1) {
             $exists = ModelPayment::newInstance()->getPaymentByCode($charge->__get('id'), 'STRIPE');
             if (isset($exists['pk_i_id'])) {
                 return PAYMENT_ALREADY_PAID;
             }
             $product_type = explode('x', $data['product']);
             Params::setParam('stripe_transaction_id', $charge->__get('id'));
             // SAVE TRANSACTION LOG
             $payment_id = ModelPayment::newInstance()->saveLog($data['concept'], $charge->__get('id'), $charge->__get('amount') / 100, $charge->__get('currency'), $data['email'], $data['user'], $data['itemid'], $product_type[0], 'STRIPE');
             //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'], $charge->__get('amount') / 100);
                 }
             }
             return PAYMENT_COMPLETED;
         }
         return PAYMENT_FAILED;
     } catch (Stripe_CardError $e) {
         return PAYMENT_FAILED;
     }
     return PAYMENT_FAILED;
 }
 public static function processPayment()
 {
     require_once osc_plugins_path() . osc_plugin_folder(__FILE__) . 'lib/Braintree.php';
     Braintree_Configuration::environment(osc_get_preference('braintree_sandbox', 'payment'));
     Braintree_Configuration::merchantId(payment_decrypt(osc_get_preference('braintree_merchant_id', 'payment')));
     Braintree_Configuration::publicKey(payment_decrypt(osc_get_preference('braintree_public_key', 'payment')));
     Braintree_Configuration::privateKey(payment_decrypt(osc_get_preference('braintree_private_key', 'payment')));
     $data = payment_get_custom(Params::getParam('extra'));
     $amount = payment_get_amount($data['product']);
     if ($amount <= 0) {
         return PAYMENT_FAILED;
     }
     $result = Braintree_Transaction::sale(array('amount' => $amount, 'creditCard' => array('number' => Params::getParam('braintree_number'), 'cvv' => Params::getParam('braintree_cvv'), 'expirationMonth' => Params::getParam('braintree_month'), 'expirationYear' => Params::getParam('braintree_year')), 'options' => array('submitForSettlement' => true)));
     if ($result->success == 1) {
         Params::setParam('braintree_transaction_id', $result->transaction->id);
         $exists = ModelPayment::newInstance()->getPaymentByCode($result->transaction->id, 'BRAINTREE');
         if (isset($exists['pk_i_id'])) {
             return PAYMENT_ALREADY_PAID;
         }
         $product_type = explode('x', $data['product']);
         // SAVE TRANSACTION LOG
         $payment_id = ModelPayment::newInstance()->saveLog($data['concept'], $result->transaction->id, $result->transaction->amount, $result->transaction->currencyIsoCode, $data['email'], $data['user'], $data['itemid'], $product_type[0], 'BRAINTREE');
         //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'], $result->transaction->amount);
             }
         }
         return PAYMENT_COMPLETED;
     } else {
         return PAYMENT_FAILED;
     }
 }