Exemplo n.º 1
1
 public static function google_redirect($description, $amount, $user_id, $invoice_payment_id, $invoice_id, $currency_id)
 {
     chdir(dirname(__FILE__));
     //'includes/plugin_paymethod_google/');
     require_once 'library/googlecart.php';
     require_once 'library/googleitem.php';
     $server_type = self::is_sandbox() ? "sandbox" : '';
     $currency = module_config::get_currency($currency_id);
     self::add_payment_data($invoice_payment_id, 'log', 'Starting payment of ' . $server_type . ' in currency ' . $currency['code']);
     $cart = new GoogleCart(self::get_merchant_id(), self::get_merchant_key(), $server_type, $currency['code']);
     $total_count = 1;
     //  Check this URL for more info about the two types of digital Delivery
     //  http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html
     //  Key/URL delivery
     self::add_payment_data($invoice_payment_id, 'log', 'Adding ' . $total_count . 'x ' . $description . ' (' . $amount . ' ' . $currency['code'] . ')');
     $item_1 = new GoogleItem($description, "", $total_count, $amount);
     // Unit price
     //$item_1->SetURLDigitalContent(module_invoice::link_receipt($invoice_payment_id),
     $item_1->SetURLDigitalContent(module_invoice::link_public_print($invoice_id), '', _l("Payment Receipt"));
     $cart->AddItem($item_1);
     $private_data = new MerchantPrivateData(array('invoice_id' => $invoice_id, 'amount' => $amount, 'currency_id' => $currency_id, 'invoice_payment_id' => $invoice_payment_id));
     $cart->SetMerchantPrivateData($private_data);
     // Specify <edit-cart-url>
     $cart->SetEditCartUrl(module_invoice::link_public($invoice_id));
     // Specify "Return to xyz" link
     $cart->SetContinueShoppingUrl(module_invoice::link_public($invoice_id));
     // Request buyer's phone number
     //$cart->SetRequestBuyerPhone(true);
     // This will do a server-2-server cart post and send an HTTP 302 redirect status
     // This is the best way to do it if implementing digital delivery
     // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
     list($status, $error) = $cart->CheckoutServer2Server();
     // if i reach this point, something was wrong
     echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
     echo "<br />Error message:<br />";
     echo $error;
     exit;
 }
Exemplo n.º 2
0
function buy_diamonds($item_name, $item_description, $diamonds, $item_price, $udid, $callback_url = NULL)
{
    $merchant_id = MERCHANT_ID;
    // Your Merchant ID
    $merchant_key = MERCHANT_KEY;
    // Your Merchant Key
    $server_type = CHECKOUT_SERVER_TYPE;
    $currency = CHECKOUT_CURRENCY;
    //print_r($_SESSION);
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $total_count = 1;
    $item_1 = new GoogleItem($item_name, $item_description, $total_count, $item_price);
    $item_1->SetMerchantPrivateItemData(new MerchantPrivateItemData(array("user-id" => $udid, "diamonds" => $diamonds)));
    $cart->AddItem($item_1);
    // Specify "Return to xyz" link
    if ($callback_url != NULL) {
        $cart->SetContinueShoppingUrl($callback_url);
    } else {
        $cart->SetContinueShoppingUrl(CHECKOUT_COUNTINUE_URL . "?success=1&amount=" . $diamonds);
    }
    // This will do a server-2-server cart post and send an HTTP 302 redirect status
    // This is the best way to do it if implementing digital delivery
    // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
    /*		echo "<PRE>";
    		print_r($cart);
    		echo "</PRE>";
    		die();*/
    list($status, $error) = $cart->CheckoutServer2Server();
    // if i reach this point, something was wrong
    echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
    echo "<br />Error message:<br />";
    echo $error;
}
function Usecase()
{
    $merchant_id = "";
    // Your Merchant ID
    $merchant_key = "";
    // Your Merchant Key
    $server_type = "sandbox";
    $currency = "USD";
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $total_count = 1;
    $certificate_path = "";
    // set your SSL CA cert path
    //  Check this URL for more info about the two types of digital Delivery
    //  http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html
    //  Key/URL delivery
    $item_1 = new GoogleItem("Download Digital Item1", "With S/N", $total_count, 10.99);
    // Unit price
    $item_1->SetURLDigitalContent('http://example.com/download.php?id=15', 'S/N: 123.123123-3213', "Download Item1");
    $cart->AddItem($item_1);
    //  Email delivery
    $item_2 = new GoogleItem("Email Digital Item2", "An email will be sent by the merchant", $total_count, 9.19);
    // Unit price
    $item_2->SetEmailDigitalDelivery('true');
    $cart->AddItem($item_2);
    // Add tax rules
    $tax_rule = new GoogleDefaultTaxRule(0.05);
    $tax_rule->SetStateAreas(array("MA", "FL", "CA"));
    $cart->AddDefaultTaxRules($tax_rule);
    // Specify <edit-cart-url>
    $cart->SetEditCartUrl("https://www.example.com/cart/");
    // Specify "Return to xyz" link
    $cart->SetContinueShoppingUrl("https://www.example.com/goods/");
    // Request buyer's phone number
    $cart->SetRequestBuyerPhone(true);
    // Add analytics data to the cart if its setted
    if (isset($_POST['analyticsdata']) && !empty($_POST['analyticsdata'])) {
        $cart->SetAnalyticsData($_POST['analyticsdata']);
    }
    // This will do a server-2-server cart post and send an HTTP 302 redirect status
    // This is the best way to do it if implementing digital delivery
    // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
    list($status, $error) = $cart->CheckoutServer2Server('', $certificate_path);
    // if i reach this point, something was wrong
    echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
    echo "<br />Error message:<br />";
    echo $error;
    //
}
Exemplo n.º 4
0
 function googlecheckout()
 {
     if ($this->input->post('googlesubmit')) {
         $this->load->model('payment_model');
         $paymentGateways_google = $this->payment_model->getPaymentSettings();
         $payment_amount = $this->input->post('item_price_1');
         $tr_id = $this->input->post('trans');
         $this->session->set_userdata('tr_id', $tr_id);
         $merchant_id = $paymentGateways_google['gch']['mail_id'];
         // Your Merchant ID
         $merchant_key = $paymentGateways_google['gch']['url'];
         // Your Merchant Key
         if ($paymentGateways_google['gch']['url_status'] == 0) {
             $server_type = "sandbox";
         } else {
             $server_type = "Live";
         }
         $currency = "USD";
         $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
         $total_count = 1;
         //  Check this URL for more info about the two types of digital Delivery
         //  http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html
         //Get the language details
         $item_1 = new GoogleItem($this->config->item('site_name') . 'Account Deposit', ' Account Deposit ', '1', $payment_amount);
         // Unit price
         // $item_1->SetURLDigitalContent('http://example.com/download.php?id=15','S/N: 123.123123-3213', "Download Item1");
         $cart->AddItem($item_1);
         $cart->SetMerchantPrivateData(new MerchantPrivateData(array("transaction-id" => $tr_id)));
         // Specify "Return to xyz" link
         $cart->SetContinueShoppingUrl(site_url('payment/checkoutSuccess'));
         // Request buyer's phone number
         $cart->SetRequestBuyerPhone(true);
         // Add analytics data to the cart if its setted
         if (isset($_POST['analyticsdata']) && !empty($_POST['analyticsdata'])) {
             $cart->SetAnalyticsData($_POST['analyticsdata']);
         }
         // This will do a server-2-server cart post and send an HTTP 302 redirect status
         // This is the best way to do it if implementing digital delivery
         // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
         list($status, $error) = $cart->CheckoutServer2Server();
         // if i reach this point, something was wrong
         echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
         echo "<br />Error message:<br />";
         echo $error;
         //
     }
 }
Exemplo n.º 5
0
 function process()
 {
     $this->order->load($this->order->getReference());
     $results = $this->modelPayment->get_orderstatus_id($this->language->get('order_status_paid_unconfirmed'), $this->language->getId());
     //$sql = "select `order_status_id` from `order_status` where `name` = '?' and `language_id` = '?'";
     //$parsed = $this->database->parse($sql, $this->language->get('order_status_paid_unconfirmed'), $this->language->getId());
     //$results = $this->database->getRow($parsed);
     if ($results) {
         // copy cart and order-total to a new GoogleCart object
         $merchantId = $this->config->get('google_merchantid');
         $merchantKey = $this->config->get('google_merchantkey');
         chdir('library/google');
         require_once 'library/googlecart.php';
         require_once 'library/googleitem.php';
         require_once 'library/googleshipping.php';
         require_once 'library/googletax.php';
         $serverType = $this->config->get('google_test') ? 'sandbox' : 'production';
         $currencyGoogle = $this->config->get('google_currency');
         $currencyCart = $this->currency->getCode();
         $totalCart = $this->order->get('total');
         if ($currencyCart != $currencyGoogle) {
             $result = $this->modelPayment->get_currency($currencyCart);
             $baseValCart = isset($result['value']) ? $result['value'] : NULL;
             $result = $this->modelPayment->get_currency($currencyGoogle);
             $baseValGoogle = isset($result['value']) ? $result['value'] : NULL;
             if ($baseValCart == NULL || $baseValGoogle == NULL) {
                 // this should never happen, we use cart's currency let GoogleCheckout return an error
                 $totalGoogle = $totalCart;
                 $currencyGoogle = $currencyCart;
             } else {
                 // convert cart's total into the currency used by Google Checkout
                 $totalGoogle = round($totalCart * $baseValCart / $baseValGoogle);
             }
         } else {
             $totalGoogle = $totalCart;
         }
         $cart = new GoogleCart($merchantId, $merchantKey, $serverType, $currencyGoogle);
         $item_1 = new GoogleItem($this->config->get('config_store'), 'order# ' . $this->order->getReference(), 1, $totalGoogle);
         $item_1->SetTaxTableSelector("including all taxes");
         $cart->AddItem($item_1);
         $tax_table = new GoogleAlternateTaxTable("including all taxes");
         $tax_rule_1 = new GoogleAlternateTaxRule(0.0);
         $tax_rule_1->SetWorldArea(true);
         $tax_table->AddAlternateTaxRules($tax_rule_1);
         $cart->AddAlternateTaxTables($tax_table);
         //			$tax_rule_1 = new GoogleDefaultTaxRule(0.175);
         //			$tax_rule_1->SetWorldArea(true);
         //			$cart->AddDefaultTaxRules($tax_rule_1);
         // Have AlegroCart process the order and remove its cart from the session.
         // AlegroCart will store it in the database with a 'Paid Unconfirmed' order status.
         $this->order->process($results['order_status_id']);
         $this->cart->clear();
         // This will do a server-to-server Google cart post and send an HTTP 302 redirect status
         // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
         list($status, $error) = $cart->CheckoutServer2Server();
         return TRUE;
         // If it reaches this point then something went wrong
         echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
         echo "<br />Error message:<br />";
         echo $error;
         echo "<br />";
         exit;
     } else {
         // I think it may be better to die here with a message as it is
         // a major configuration problem that should be found by even
         // the most basic testing and hence not impact upon a customer.
         die('Configuration error: You MUST have created an order status for "Paid Unconfirmed" for every installed language.');
         //  The following is a reasonable alternative but there is no way without making
         //  changes to checkout_failure, to get a user defined message to the that page.
         //  The message, as above, is a big help in tracking any teething problems with this code.
         //$this->response->redirect($this->url->ssl('checkout_failure'));
     }
 }