public static function processPayment()
 {
     $working_key = osc_get_preference('ccavenue_working_key', 'payment_pro');
     $Merchant_Id = Params::getParam('Merchant_Id');
     $Amount = Params::getParam('Amount');
     $Order_Id = Params::getParam('Order_Id');
     $Checksum = Params::getParam('Checksum');
     $AuthDesc = Params::getParam('AuthDesc');
     $extra = Params::getParam('Merchant_Param');
     $verify = self::_verifyCheckSum($Merchant_Id, $Order_Id, $Amount, $AuthDesc, $Checksum, $working_key);
     $data = payment_pro_get_custom($extra);
     if (empty($data['items']) || !$verify || $AuthDesc == 'N') {
         return PAYMENT_PRO_FAILED;
     }
     $status = payment_pro_check_items($data['items'], $Amount);
     if ($AuthDesc == "B") {
         return PAYMENT_PRO_PENDING;
     }
     $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($Order_Id, $Amount, $status, osc_get_preference("currency", 'payment_pro'), $data['email'], $data['user'], 'CCAVENUE', $data['items']);
     if ($status == PAYMENT_PRO_COMPLETED) {
         foreach ($data['items'] as $item) {
             if (substr($item['id'], 0, 3) == 'PUB') {
                 $tmp = explode("-", $item['id']);
                 ModelPaymentPro::newInstance()->payPublishFee($tmp[count($tmp) - 1], $invoiceId);
             } else {
                 if (substr($item['id'], 0, 3) == 'PRM') {
                     $tmp = explode("-", $item['id']);
                     ModelPaymentPro::newInstance()->payPremiumFee($tmp[count($tmp) - 1], $invoiceId);
                 } else {
                     if (substr($item['id'], 0, 3) == 'WLT') {
                         ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                     } else {
                         osc_run_hook('payment_pro_item_paid', $item);
                     }
                 }
             }
         }
     }
     return PAYMENT_PRO_COMPLETED;
 }
 public static function processStandardPayment()
 {
     if (Params::getParam('payment_status') == 'Completed' || Params::getParam('st') == 'Completed') {
         // Have we processed the payment already?
         $tx = Params::getParam('tx') != '' ? Params::getParam('tx') : Params::getParam('txn_id');
         $payment = ModelPaymentPro::newInstance()->getPaymentByCode($tx, 'PAYPAL', PAYMENT_PRO_COMPLETED);
         if (!isset($payment['pk_i_id'])) {
             if (Params::getParam('cm') != '') {
                 $data = Params::getParam('cm');
             } else {
                 if (Params::getParam('custom') != '') {
                     $data = Params::getParam('custom');
                 } else {
                     $data = Params::getParam('extra');
                 }
             }
             $data = payment_pro_get_custom($data);
             $items = array();
             $num_items = (int) Params::getParam('num_cart_items');
             for ($i = 1; $i <= $num_items; $i++) {
                 $id = Params::getParam('item_number' . $i);
                 $tmp = explode("-", $id);
                 $items[] = array('id' => $tmp[0], 'description' => Params::getParam('item_name' . $i), 'amount' => Params::getParam('mc_gross_' . $i), 'quantity' => Params::getParam('quantity' . $i), 'item_id' => $tmp[1]);
             }
             $total_amount = Params::getParam('payment_gross') != '' ? Params::getParam('payment_gross') : Params::getParam('mc_gross');
             $status = payment_pro_check_items($items, $total_amount);
             $product_type = explode('x', Params::getParam('item_number'));
             // SAVE TRANSACTION LOG
             $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($tx, $total_amount, $status, Params::getParam('mc_currency'), Params::getParam('payer_email') != '' ? Params::getParam('payer_email') : '', @$data['user'], 'PAYPAL', $items);
             if ($status == PAYMENT_PRO_COMPLETED) {
                 foreach ($items as $item) {
                     if (substr($item['id'], 0, 3) == 'PUB') {
                         ModelPaymentPro::newInstance()->payPublishFee($item['item_id'], $invoiceId);
                     } else {
                         if (substr($item['id'], 0, 3) == 'PRM') {
                             ModelPaymentPro::newInstance()->payPremiumFee($item['item_id'], $invoiceId);
                         } else {
                             if (substr($item['id'], 0, 3) == 'WLT') {
                                 ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                             } else {
                                 osc_run_hook('payment_pro_item_paid', $item);
                             }
                         }
                     }
                 }
             }
             return PAYMENT_PRO_COMPLETED;
         }
         return PAYMENT_PRO_ALREADY_PAID;
     }
     return PAYMENT_PRO_PENDING;
 }
 public static function processPayment()
 {
     $sale = new AuthorizeNetAIM();
     $data = payment_pro_get_custom(Params::getParam('extra'));
     $sale->amount = $data['amount'];
     $sale->card_num = Params::getParam('authorize_number');
     $sale->exp_date = Params::getParam('authorize_month') . Params::getParam('authorize_year');
     $response = $sale->authorizeAndCapture();
     $status = payment_pro_check_items($data['items'], $response->amount);
     if ($response->approved) {
         Params::setParam('authorize_transaction_id', $response->transaction_id);
         $exists = ModelPaymentPro::newInstance()->getPaymentByCode($response->transaction_id, 'AUTHORIZE', PAYMENT_PRO_COMPLETED);
         if (isset($exists['pk_i_id'])) {
             return PAYMENT_PRO_ALREADY_PAID;
         }
         // SAVE TRANSACTION LOG
         $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($response->transaction_id, $response->amount, $status, 'USD', $data['email'], $data['user'], 'AUTHORIZE', $data['items']);
         //source
         if ($status == PAYMENT_PRO_COMPLETED) {
             foreach ($data['items'] as $item) {
                 if (substr($item['id'], 0, 3) == 'PUB') {
                     $tmp = explode("-", $item['id']);
                     ModelPaymentPro::newInstance()->payPublishFee($tmp[count($tmp) - 1], $invoiceId);
                 } else {
                     if (substr($item['id'], 0, 3) == 'PRM') {
                         $tmp = explode("-", $item['id']);
                         ModelPaymentPro::newInstance()->payPremiumFee($tmp[count($tmp) - 1], $invoiceId);
                     } else {
                         if (substr($item['id'], 0, 3) == 'WLT') {
                             ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                         } else {
                             osc_run_hook('payment_pro_item_paid', $item);
                         }
                     }
                 }
             }
         }
         return PAYMENT_PRO_COMPLETED;
     } else {
         $tmp = explode("Reason Text: ", $response->error_message);
         Params::setParam('authorize_error', $tmp[count($tmp) - 1]);
     }
     return PAYMENT_PRO_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_pro'));
     Braintree_Configuration::merchantId(payment_pro_decrypt(osc_get_preference('braintree_merchant_id', 'payment_pro')));
     Braintree_Configuration::publicKey(payment_pro_decrypt(osc_get_preference('braintree_public_key', 'payment_pro')));
     Braintree_Configuration::privateKey(payment_pro_decrypt(osc_get_preference('braintree_private_key', 'payment_pro')));
     $data = payment_pro_get_custom(Params::getParam('extra'));
     if (!isset($data['items']) || !isset($data['amount']) || $data['amount'] <= 0) {
         return PAYMENT_PRO_FAILED;
     }
     $status = payment_pro_check_items($data['items'], $data['amount']);
     $result = Braintree_Transaction::sale(array('amount' => $data['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 = ModelPaymentPro::newInstance()->getPaymentByCode($result->transaction->id, 'BRAINTREE', PAYMENT_PRO_COMPLETED);
         if (isset($exists['pk_i_id'])) {
             return PAYMENT_PRO_ALREADY_PAID;
         }
         // SAVE TRANSACTION LOG
         $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($result->transaction->id, $result->transaction->amount, $status, $result->transaction->currencyIsoCode, $data['email'], $data['user'], 'BRAINTREE', $data['items']);
         //source
         if ($status == PAYMENT_PRO_COMPLETED) {
             foreach ($data['items'] as $item) {
                 if (substr($item['id'], 0, 3) == 'PUB') {
                     $tmp = explode("-", $item['id']);
                     ModelPaymentPro::newInstance()->payPublishFee($tmp[count($tmp) - 1], $invoiceId);
                 } else {
                     if (substr($item['id'], 0, 3) == 'PRM') {
                         $tmp = explode("-", $item['id']);
                         ModelPaymentPro::newInstance()->payPremiumFee($tmp[count($tmp) - 1], $invoiceId);
                     } else {
                         if (substr($item['id'], 0, 3) == 'WLT') {
                             ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                         } else {
                             osc_run_hook('payment_pro_item_paid', $item);
                         }
                     }
                 }
             }
         }
         return PAYMENT_PRO_COMPLETED;
     } else {
         return PAYMENT_PRO_FAILED;
     }
 }
 public static function processPayment()
 {
     require_once dirname(__FILE__) . '/lib/Stripe.php';
     if (osc_get_preference('stripe_sandbox', 'payment_pro') == 0) {
         $stripe = array("secret_key" => payment_pro_decrypt(osc_get_preference('stripe_secret_key', 'payment_pro')), "publishable_key" => payment_pro_decrypt(osc_get_preference('stripe_public_key', 'payment_pro')));
     } else {
         $stripe = array("secret_key" => payment_pro_decrypt(osc_get_preference('stripe_secret_key_test', 'payment_pro')), "publishable_key" => payment_pro_decrypt(osc_get_preference('stripe_public_key_test', 'payment_pro')));
     }
     Stripe::setApiKey($stripe['secret_key']);
     $token = Params::getParam('stripeToken');
     $data = payment_pro_get_custom(Params::getParam('extra'));
     if (!isset($data['items']) || !isset($data['amount']) || $data['amount'] <= 0) {
         return PAYMENT_PRO_FAILED;
     }
     $status = payment_pro_check_items($data['items'], $data['amount']);
     $customer = Stripe_Customer::create(array('email' => $data['email'], 'card' => $token));
     try {
         $charge = @Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $data['amount'] * 100, 'currency' => strtoupper(osc_get_preference("currency", 'payment_pro'))));
         if ($charge->__get('paid') == 1) {
             $exists = ModelPaymentPro::newInstance()->getPaymentByCode($charge->__get('id'), 'STRIPE', PAYMENT_PRO_COMPLETED);
             if (isset($exists['pk_i_id'])) {
                 return PAYMENT_PRO_ALREADY_PAID;
             }
             Params::setParam('stripe_transaction_id', $charge->__get('id'));
             // SAVE TRANSACTION LOG
             $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($charge->__get('id'), $charge->__get('amount') / 100, $status, strtoupper($charge->__get('currency')), @$data['email'], @$data['user'], 'STRIPE', $data['items']);
             if ($status == PAYMENT_PRO_COMPLETED) {
                 foreach ($data['items'] as $item) {
                     if (substr($item['id'], 0, 3) == 'PUB') {
                         $tmp = explode("-", $item['id']);
                         ModelPaymentPro::newInstance()->payPublishFee($tmp[count($tmp) - 1], $invoiceId);
                     } else {
                         if (substr($item['id'], 0, 3) == 'PRM') {
                             $tmp = explode("-", $item['id']);
                             ModelPaymentPro::newInstance()->payPremiumFee($tmp[count($tmp) - 1], $invoiceId);
                         } else {
                             if (substr($item['id'], 0, 3) == 'WLT') {
                                 ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                             } else {
                                 osc_run_hook('payment_pro_item_paid', $item);
                             }
                         }
                     }
                 }
             }
             return PAYMENT_PRO_COMPLETED;
         }
         return PAYMENT_PRO_FAILED;
     } catch (Stripe_CardError $e) {
         return PAYMENT_PRO_FAILED;
     }
     return PAYMENT_PRO_FAILED;
 }
 public static function processPayment()
 {
     if (Params::getParam('test') == true) {
         return PAYMENT_PRO_FAILED;
     }
     $extra = explode("?", Params::getParam('extra'));
     $data = payment_pro_get_custom(str_replace("@", "+", $extra[0]));
     unset($extra);
     $data['items'] = ModelPaymentPro::newInstance()->getPending(@$data['tx']);
     $transaction_hash = Params::getParam('transaction_hash');
     $value_in_btc = Params::getParam('value') / 100000000;
     $my_bitcoin_address = osc_get_preference('blockchain_btc_address', 'payment_pro');
     if (empty($data['items'])) {
         return PAYMENT_PRO_FAILED;
     }
     if (osc_get_preference('currency', 'payment_pro') == 'BTC') {
         $status = payment_pro_check_items($data['items'], $value_in_btc);
     } else {
         $status = payment_pro_check_items_blockchain($data['items'], $value_in_btc, $data['xrate']);
     }
     if (Params::getParam('address') != $my_bitcoin_address) {
         return PAYMENT_PRO_FAILED;
     }
     foreach ($data['items'] as $k => $v) {
         $data['items'][$k]['amount'] = $v['amount'] / 1000000;
     }
     $hosts = gethostbynamel('blockchain.info');
     foreach ($hosts as $ip) {
         // Check payment came from one of blockchain.info's IP
         if ($_SERVER['REMOTE_ADDR'] == $ip) {
             $exists = ModelPaymentPro::newInstance()->getPaymentByCode($transaction_hash, 'BLOCKCHAIN', PAYMENT_PRO_COMPLETED);
             if (isset($exists['pk_i_id'])) {
                 return PAYMENT_PRO_ALREADY_PAID;
             }
             if (is_numeric(Params::getParam('confirmations')) && Params::getParam('confirmations') >= osc_get_preference('blockchain_confirmations', 'payment_pro') || Params::getParam('anonymous') == true) {
                 // SAVE TRANSACTION LOG
                 $invoiceId = ModelPaymentPro::newInstance()->saveInvoice($transaction_hash, $value_in_btc, $status, 'BTC', $data['email'], $data['user'], 'BLOCKCHAIN', $data['items']);
                 if ($status == PAYMENT_PRO_COMPLETED) {
                     foreach ($data['items'] as $item) {
                         if (substr($item['id'], 0, 3) == 'PUB') {
                             $tmp = explode("-", $item['id']);
                             ModelPaymentPro::newInstance()->payPublishFee($tmp[count($tmp) - 1], $invoiceId);
                         } else {
                             if (substr($item['id'], 0, 3) == 'PRM') {
                                 $tmp = explode("-", $item['id']);
                                 ModelPaymentPro::newInstance()->payPremiumFee($tmp[count($tmp) - 1], $invoiceId);
                             } else {
                                 if (substr($item['id'], 0, 3) == 'WLT') {
                                     ModelPaymentPro::newInstance()->addWallet($data['user'], $item['amount']);
                                 } else {
                                     osc_run_hook('payment_pro_item_paid', $item);
                                 }
                             }
                         }
                     }
                     ModelPaymentPro::newInstance()->deletePending($data['tx']);
                 }
                 return PAYMENT_PRO_COMPLETED;
             } else {
                 // Maybe we could do something here (the payment was correct, but it didn't get enought confirmations yet)
                 return PAYMENT_PRO_PENDING;
             }
             break;
         }
     }
     return $status = PAYMENT_PRO_FAILED;
 }