public function start_ipn($data, $config)
    {
        require_once 'assets/google-checkout/library/googlecart.php';
        require_once 'assets/google-checkout/library/googleitem.php';
        require_once 'assets/google-checkout/library/googleshipping.php';
        require_once 'assets/google-checkout/library/googletax.php';
        $merchant_id = $config['merchant_id'];
        // Your Merchant ID
        $merchant_key = $config['merchant_key'];
        // Your Merchant Key
        $server_type = $config['sandbox'];
        $currency = "USD";
        $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
        $cart->SetMerchantPrivateData(new MerchantPrivateData(array("transaction_id" => $data['transaction_id'])));
        $i = 1;
        foreach ($data["cart"]["items"] as $items) {
            ${'item_' . $i} = new GoogleItem($items['title'], "", $items['quantity'], $this->_currency_round($items["price"]));
            ${'item_' . $i}->SetMerchantItemId($items["product_id"]);
            $cart->AddItem(${'item_' . $i});
            $i++;
        }
        // Applying a discount
        if ($data['cart_discount'] != 0) {
            ${'item_' . $i} = new GoogleItem("Discount Applied", "", 1, "-" . $this->_currency_round($data['cart_discount']));
            $cart->AddItem(${'item_' . $i});
        }
        // Calculating the Tax by taking the subtotal, subtracting the discount and
        // dividing by the pre-calculated rate.
        // -- Then formatting the number by 2 decimal places
        if ($data['cart_tax'] == 0) {
            $taxrate = 0;
        } else {
            $taxrate = number_format($data['cart_subtotal'] - $data['cart_discount'] / $data['cart_tax'], 2);
        }
        $tax_rule = new GoogleDefaultTaxRule($taxrate);
        $tax_rule->SetWorldArea(true);
        $cart->AddDefaultTaxRules($tax_rule);
        $ship_1 = new GoogleFlatRateShipping("Shipping", $data['cart_shipping']);
        $cart->AddShipping($ship_1);
        // Specify <edit-cart-url>
        $cart->SetEditCartUrl($data['return']);
        // Specify "Return to xyz" link
        $cart->SetContinueShoppingUrl($data['cancel_return']);
        // Define rounding policy
        $cart->AddRoundingPolicy("CEILING", "TOTAL");
        echo '	<html>
   	        			<head>
   	        				<title>Google Checkout</title>
   	        			</head>
   	        			<body onLoad="document.forms[\'gateway_form\'].submit();">
							<form method="post" name="gateway_form" action="' . $cart->checkout_url . '">
			    				<input type="hidden" name="cart" value="' . base64_encode($cart->GetXML()) . '"/>
								<input type="hidden" name="signature" value="' . base64_encode($cart->CalcHmacSha1($cart->GetXML())) . '" />
								<p style="text-align:center;">
									Your order is being processed... will be redirected to the payment website.
								 	<br />
								 	<br />
								 	If you are not automatically redirected to Google Checkout within 5 seconds...<br /><br />
									<input type="submit" value="Click Here">
								</p>
							</form>
						</body>
					</html>';
    }
Exemplo n.º 2
1
 /**
  * Sets appropriate parameters for checking out to google
  *
  * @param array $params name value pair of contribution datat
  *
  * @param $component
  * @throws Exception
  * @return void
  */
 function doTransferCheckout(&$params, $component)
 {
     $component = strtolower($component);
     $url = rtrim($this->_paymentProcessor['url_site'], '/') . '/cws/v2/Merchant/' . $this->_paymentProcessor['user_name'] . '/checkout';
     //Create a new shopping cart object
     // Merchant ID
     $merchant_id = $this->_paymentProcessor['user_name'];
     // Merchant Key
     $merchant_key = $this->_paymentProcessor['password'];
     $server_type = $this->_mode == 'test' ? 'sandbox' : '';
     $cart = new GoogleCart($merchant_id, $merchant_key, $server_type);
     $item1 = new GoogleItem($params['item_name'], '', 1, $params['amount'], $params['currencyID']);
     $cart->AddItem($item1);
     if ($component == "event") {
         $privateData = "contactID={$params['contactID']},contributionID={$params['contributionID']},contributionTypeID={$params['contributionTypeID']},eventID={$params['eventID']},participantID={$params['participantID']},invoiceID={$params['invoiceID']}";
     } elseif ($component == "contribute") {
         $privateData = "contactID={$params['contactID']},contributionID={$params['contributionID']},contributionTypeID={$params['contributionTypeID']},invoiceID={$params['invoiceID']}";
         $membershipID = CRM_Utils_Array::value('membershipID', $params);
         if ($membershipID) {
             $privateData .= ",membershipID={$membershipID}";
         }
         $relatedContactID = CRM_Utils_Array::value('related_contact', $params);
         if ($relatedContactID) {
             $privateData .= ",relatedContactID={$relatedContactID}";
             $onBehalfDupeAlert = CRM_Utils_Array::value('onbehalf_dupe_alert', $params);
             if ($onBehalfDupeAlert) {
                 $privateData .= ",onBehalfDupeAlert={$onBehalfDupeAlert}";
             }
         }
     }
     // Allow further manipulation of the arguments via custom hooks ..
     CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $privateData);
     $cart->SetMerchantPrivateData($privateData);
     if ($component == "event") {
         $returnURL = CRM_Utils_System::url('civicrm/event/register', "_qf_ThankYou_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
     } elseif ($component == "contribute") {
         $returnURL = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
     }
     $cart->SetContinueShoppingUrl($returnURL);
     $cartVal = base64_encode($cart->GetXML());
     $signatureVal = base64_encode($cart->CalcHmacSha1($cart->GetXML()));
     $googleParams = array('cart' => $cartVal, 'signature' => $signatureVal);
     require_once 'HTTP/Request.php';
     $params = array('method' => HTTP_REQUEST_METHOD_POST, 'allowRedirects' => FALSE);
     $request = new HTTP_Request($url, $params);
     foreach ($googleParams as $key => $value) {
         $request->addPostData($key, $value);
     }
     $result = $request->sendRequest();
     if (PEAR::isError($result)) {
         CRM_Core_Error::fatal($result->getMessage());
     }
     if ($request->getResponseCode() != 302) {
         CRM_Core_Error::fatal(ts('Invalid response code received from Google Checkout: %1', array(1 => $request->getResponseCode())));
     }
     CRM_Utils_System::redirect($request->getResponseHeader('location'));
     exit;
 }
Exemplo n.º 3
0
function UseCase3()
{
    //Create a new shopping cart object
    $merchant_id = "";
    //Your Merchant ID
    $merchant_key = "";
    //Your Merchant Key
    $server_type = "sandbox";
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type);
    //Add items to the cart
    $item1 = new GoogleItem("Dry Food Pack AA1453", " pack of highly nutritious dried food for emergency", 1, 35);
    $item2 = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 178);
    $item3 = new GoogleItem("AA Rechargeable Battery Pack", "Battery pack containing four AA rechargeable batteries", 1, 12);
    $cart->AddItem($item1);
    $cart->AddItem($item2);
    $cart->AddItem($item3);
    //Set request buyer phone
    $cart->SetRequestBuyerPhone("true");
    //Add merchant calculations options
    $cart->SetMerchantCalculations("https://www.example.com/shopping/merchantCalc", "true", "true", "true");
    $ship = new GoogleShipping("merchant-calc", "merchant-calculated", 5, "USD", "ALL");
    $ship->SetAllowedStateAreas(array("NY", "CA"));
    $cart->AddShipping($ship);
    $tax_rule = new GoogleTaxRule("default", 0.2);
    $tax_rule->SetStateAreas(array("CA", "NY"));
    $tax_table = new GoogleTaxTable("default");
    $tax_table->AddTaxRules($tax_rule);
    $cart->AddTaxTables($tax_table);
    //Display XML data
    echo htmlentities($cart->GetXML());
    //Display a disabled, small button with a white background
    echo $cart->CheckoutButtonCode("small", "white", "disabled");
}
function UseCase2()
{
    // Create a new shopping cart object
    $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);
    // Add items to the cart
    $item_1 = new GoogleItem("Dry Food Pack AA1453", "A pack of highly nutritious dried food for emergency", 2, 24.99);
    $item_1->SetTaxTableSelector("food");
    $item_2 = new GoogleItem("MegaSound 2GB MP3 Player", "Portable MP3 player - stores 500 songs", 1, 175.49);
    $item_2->SetMerchantPrivateItemData(new MerchantPrivateItemData(array("color" => "blue", "weight" => "3.2")));
    $item_2->SetMerchantItemId("Item#012345");
    $cart->AddItem($item_1);
    $cart->AddItem($item_2);
    // Add shipping options
    $ship_1 = new GoogleFlatRateShipping("Ground", 15);
    $restriction_1 = new GoogleShippingFilters();
    $restriction_1->SetAllowedWorldArea(true);
    $ship_1->AddShippingRestrictions($restriction_1);
    $ship_2 = new GooglePickup("Pick Up", 5);
    $cart->AddShipping($ship_1);
    $cart->AddShipping($ship_2);
    // Add default tax rules
    $tax_rule_1 = new GoogleDefaultTaxRule(0.17);
    $tax_rule_1->AddPostalArea("GB", "SW*");
    $tax_rule_1->AddPostalArea("FR");
    $tax_rule_1->AddPostalArea("DE");
    $tax_rule_2 = new GoogleDefaultTaxRule(0.1);
    $tax_rule_2->SetWorldArea(true);
    $cart->AddDefaultTaxRules($tax_rule_1);
    $cart->AddDefaultTaxRules($tax_rule_2);
    // Add alternate tax table
    $tax_table = new GoogleAlternateTaxTable("food");
    $tax_rule_1 = new GoogleAlternateTaxRule(0.05);
    $tax_rule_1->AddPostalArea("GB");
    $tax_rule_1->AddPostalArea("FR");
    $tax_rule_1->AddPostalArea("DE");
    $tax_rule_2 = new GoogleAlternateTaxRule(0.03);
    $tax_rule_2->SetWorldArea(true);
    $tax_table->AddAlternateTaxRules($tax_rule_1);
    $tax_table->AddAlternateTaxRules($tax_rule_2);
    $cart->AddAlternateTaxTables($tax_table);
    // Add <merchant-private-data>
    $cart->SetMerchantPrivateData(new MerchantPrivateData(array("animals" => array("type" => "cat,dog"))));
    // Specify <edit-cart-url>
    $cart->SetEditCartUrl("http://www.example.com/edit");
    // Specify "Return to xyz" link
    $cart->SetContinueShoppingUrl("http://www.example.com/continue");
    // Request buyer's phone number
    $cart->SetRequestBuyerPhone(true);
    // Define rounding policy
    $cart->AddRoundingPolicy("CEILING", "TOTAL");
    // Display XML data
    // echo "<pre>";
    // echo htmlentities($cart->GetXML());
    // echo "</pre>";
    // Display a medium size button
    echo $cart->GetXML();
}
Exemplo n.º 5
-1
 public function preparePayment()
 {
     if ($this->testmode == true) {
         $environment = 'sandbox';
     } else {
         $environment = 'production';
     }
     $Gcart = new GoogleCart($this->arr_settings['account'], $this->arr_settings['secret'], $environment, $this->arr_order['currency']);
     $Gcart->SetContinueShoppingUrl($this->url_return_success);
     $Gitem = new GoogleItem($this->arr_order['id'], "Your Purchase (Order reference #" . $this->arr_order['id'] . ")", 1, $this->arr_order['total']);
     $Gcart->AddItem($Gitem);
     $Gcart->SetMerchantPrivateData(new MerchantPrivateData(array('shopguid' => $this->arr_settings['shopguid'], 'orderguid' => $this->arr_order['guid'], 'ip-address' => $this->arr_settings['ip'])));
     $GcartXML = $Gcart->GetXML();
     $Grequest = new GoogleRequest($Gcart->merchant_id, $Gcart->merchant_key, $environment, $Gcart->currency);
     list($status, $this->url_integration) = $Grequest->SendServer2ServerCart($GcartXML, false);
     if ($this->url_integration == "") {
         echo "An error occurred while sending the basket to google. Check the google checkout 'Integration console'.";
         die;
     }
 }