【问题标题】:google checkout php callback explainedgoogle checkout php回调解释
【发布时间】:2013-05-01 15:40:39
【问题描述】:

大家好,我不知道我这样做是否正确,但我不明白 google checkout 是如何工作的。 我有将 XML 发送到谷歌结帐的 php 代码,一切正常,我在结帐过程中达到的税费价格还可以。

$_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;
        }

点击提交付款后,我被重定向到一个页面,其中包含成功消息和返回我网站的链接。 我想知道如何检查付款是否成功。 还有一个回调,我不知道到底应该做什么。 请帮助我更好地理解

我已经附上了下面的代码。

【问题讨论】:

标签: php google-checkout


【解决方案1】:

免责声明:我不是 PHP 开发人员。

  • 您上面的代码称为Part 1. Checkout APIdocumented here。它介绍了如何将您的数据/购物车发送到 Google 进行结帐

  • Part II. Order Processing 介绍了如何从 Google 获取数据(进入您的系统)。提供教程here。您可以在此处提供Callback API URL侦听来自 Google 的 HTTP POST 并继续处理数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多