0
votes

Hi all i don't know if i'm doing this right or not but i can't understand how google checkout works. I have the php code that sends the XML to the google checkout everything is ok i reach on the checkout process taxes prices shipping is ok.

$_currency    = $params['currency'];
            $base_domain  = 'https://' . (($params['mode'] == 'transaction') ? 'checkout.google.com' : 'sandbox.google.com/checkout');
            $base_url     = $base_domain . '/cws/v2/Merchant/' . $params['merchantId'] . '/checkout';

            // Form XML array with cart items
            $_items = '';

            $google_products = $this->CI->go_cart->contents();

            foreach ($google_products as $k => $v) {
                $item_options = '';

                if (isset($v['options'])) {
                    foreach ($v['options'] as $name => $value) {
                        if (is_array($value)) {
                            foreach ($value as $item) {
                                $item_options .= $item;
                            }
                        } else {
                            $item_options .= $value;
                        }
                    }
                }


                $_items .= '<item>' . '<merchant-item-id>' . $v['id'] . '</merchant-item-id>' . '<item-name>' . strip_tags($v['name']) . ' ' . $item_options . '</item-name>' . '<item-description>' . substr(strip_tags($item_options), 0, 299) . '</item-description>' . "<unit-price currency='" . $_currency . "'>" . $v['price'] . '</unit-price>' . '<quantity>' . $v['quantity'] . '</quantity>' . '</item>';
            }

$xml_cart = "<?xml version='1.0' encoding='UTF-8'?>
    <checkout-shopping-cart xmlns='http://checkout.google.com/schema/2'>
      <shopping-cart>
        <merchant-private-data>
            <additional_data>
                <session_id>" . base64_encode($customer['bill_address']["email"] . date('h:i:s')) . "</session_id>
                <currency_code>" . $_currency . "</currency_code>
                <payment_id>" . base64_encode($customer['bill_address']["email"] . date('h:i:s')) . "</payment_id>
                " . $private_ship_data . "
            </additional_data>
        </merchant-private-data>
        <items>" . $_items . "</items>
      </shopping-cart>
      <checkout-flow-support>
        <merchant-checkout-flow-support>
          <platform-id>971865505315434</platform-id>
          <request-buyer-phone-number>true</request-buyer-phone-number>
          <edit-cart-url>" . $edit_cart_url . "</edit-cart-url>
          <merchant-calculations>
            <merchant-calculations-url>" . $calculation_url . "</merchant-calculations-url>
          </merchant-calculations>
          <continue-shopping-url>" . $return_url . "</continue-shopping-url>
          " . $shippings . $taxes . "
        </merchant-checkout-flow-support>
      </checkout-flow-support>
    </checkout-shopping-cart>";

            $signature     = $this->fn_calc_hmac_sha1($xml_cart, $params['merchantKey']);
            $b64_cart      = base64_encode($xml_cart);
            $b64_signature = base64_encode($signature);


            echo '<form method="post" action="' . $base_url . '" name="BB_BuyButtonForm">
        <input type="hidden" name="cart" value="' . $b64_cart . '" />
        <input type="hidden" name="signature" value="' . $b64_signature . '" />
        <input alt="" src="' . $base_domain . '/buttons/checkout.gif?merchant_id=' . $params['merchantId'] . '&amp;w=160&amp;h=43&amp;style=' . 'white' . '&amp;variant=text&amp;loc=en_US" type="image"/>
        </form>';

            exit;
        }

After i click on submit payment i'm then redirected to a page with successfull message and with a link to return to my website. I'm wondering how can i check if the payment was or not successfully. Also there is a callback that i don't know exactly what is supposed to do. Please help me understand better

I have attached the code below.

1
Google will send a notification. How to setup and configure notifications you can find here: developers.google.com/checkout/developer/…Matoha

1 Answers

0
votes

Disclaimer: Am not a PHP dev.

  • Your code above is known as Part 1. Checkout API documented here. It covers how you get your data/cart to Google for Checkout

  • Part II. Order Processing covers how to get data from Google (into your systems). A tutorial is provided here. This is where you provide a Callback API URL that listens to (waits for) HTTP POSTs from Google and proceed to process the data.