Use GooglePay
Last updated: 22-Oct-2024
Rate this article:
Overview
GooglePay has over 150 million users across 42 global markets using the app each month. The wallet is used on nearly 800.000 websites as a secure payment gateway. Roughly 20% of all mobile purchases are made using this digital payment gateway.
Supported currencies
GooglePay supports EUR, USD, GBP, CHF, DKK, NOK and SEK transactions.
Workflow
- Follow the Google Pay Web documentation (https://developers.google.com/pay/api/web/overview) to add a Google Pay button to your web page.
-
Use 2Checkout's Google merchant ID when building the
merchantInfo
object.{ "merchantInfo": { "merchantId": "BCR2DN6T2OAK7HIW" } }
-
Set gateway to verifone and gatewayMerchantId to your 2Checkout's gateway ID found below when building the tokenizationSpecification object.
{ "tokenizationSpecification": { "type": "PAYMENT_GATEWAY", "parameters": { "gateway": "verifone", "gatewayMerchantId": "1ab01f9d-10a6-43fe-9c9e-941798a0813b" } } }
- After the shopper authorizes the payment, pass the token from the Google response to Verifone to process the payment. To do this, encode the token to base64 and add it to the
placeOrder
call payload in thePaymentToken
property.
Request Parameters
Parameters | Type/Description |
---|---|
sessionID | Required (string) Session identifier, the output of the Login method. Include sessionID into all your requests. 2Checkout throws an exception if the values are incorrect. The sessionID expires in 10 minutes. |
Order | Required (Object) Object designed to collect all data necessary for an order, including billing, product/subscription plan and payment details. See code sample for more details. |
Request Example
<?php
declare(strict_types=1);
class Configuration
{
public const MERCHANT_CODE = 'your_code';
public const MERCHANT_KEY = 'SECRET_KEY';
public const URL = 'https://api.2checkout.com/rpc/6.0';
public const ACTION = 'placeOrder';
//array or JSON
public const PAYLOAD = <<<JSON
{
"Currency": "usd",
"Language": "en",
"Country": "us",
"Source": "API",
"Affiliate": {
"AffiliateCode": "ABCDE1234"
},
"Items": [
{
"Code": "WP1",
"Quantity": 2
}
],
"BillingDetails": {
"Address1": "Test Address",
"City": "LA",
"State": "California",
"CountryCode": "US",
"Email": "testcustomer@2Checkout.com",
"FirstName": "Customer",
"LastName": "2Checkout",
"Zip": "12345"
},
"PaymentDetails": {
"Type": "GOOGLEPAY",
"Currency": "USD",
"PaymentMethod": {
"RecurringEnabled": true,
"PaymentToken": "eyJzaWduYXR1cmUiOiJNRVlDSVFDVDBrek53RDFpcmRqTlYxZDJXT2k4eFplSDBhdnRwNXFsVWVoejdsenpkd0loQUxYdWlzNlMwNnJPemNZdUVPYW0rb0tiUDZzd3J5K1dMcnA1ajVGRkhialIiLCJpbnRlcm1lZGlhdGVTaWduaW5nS2V5Ijp7InNpZ25lZEtleSI6IntcImtleVZhbHVlXCI6XCJNRmt3RXdZSEtvWkl6ajBDQVFZSUtvWkl6ajBEQVFjRFFnQUUyZjBxZllRMHZ1OTlzNFlXOUwzZ3RERUZYdW5yMmhhRUdMSTI1Q3ZObkxzMk9tV3FHbW8zSFZHYnVhL1IvamQyWHNWeFFBbFVPdDRzUFBpQ0RMQ3pHQVxcdTAwM2RcXHUwMDNkXCIsXCJrZXlFeHBpcmF0aW9uXCI6XCIxNjkzMjk2NjUzNTAwXCJ9Iiwic2lnbmF0dXJlcyI6WyJNRVVDSVFEQUFPQmJlQXpDWWF4VWVWbmNMekg0L3ZpSGNZTUFrNUU1Z3RUc0NoWGJsZ0lnRi81eDAzM2d2a25kQ1V6WmJVTzJnbjBuZ001cEFWbEZkNXhlNFE2b3pnSVx1MDAzZCJdfSwicHJvdG9jb2xWZXJzaW9uIjoiRUN2MiIsInNpZ25lZE1lc3N"
}
}
}
JSON;
}
class Client
{
private const LOGIN_METHOD = 'login';
private $calls = 1;
private $sessionId;
private function generateAuth(): array
{
$merchantCode = Configuration::MERCHANT_CODE;
$key = Configuration::MERCHANT_KEY;
$date = gmdate('Y-m-d H:i:s');
$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$algo = 'sha256';
$hash = hash_hmac($algo, $string, $key);
return compact('merchantCode', 'date', 'hash', 'algo');
}
public function login(string $url)
{
$payload = $this->generateAuth();
$response = $this->call($url, array_values($payload), self::LOGIN_METHOD);
$this->sessionId = $response['result'];
}
public function call(
string $url = Configuration::URL,
$payload = Configuration::PAYLOAD,
string $action = Configuration::ACTION
): ?array {
if (empty($this->sessionId) && $action !== self::LOGIN_METHOD) {
$this->login($url);
}
if(is_string($payload)) {
$payload = json_decode($payload, true);
}
if (!empty($this->sessionId)) {
$payload = [$this->sessionId, $payload];
}
$payload = array_filter($payload);
$request = json_encode([
'jsonrpc' => '2.0',
'method' => $action,
'params' => $payload,
'id' => $this->calls++,
]);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSLVERSION, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Cookie: XDEBUG_SESSION=PHPSTORM'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($curl);
if(empty($response)) {
die('Server unavailable');
}
echo $response . '</br>';
return json_decode($response, true);;
}
}
$client = new Client();
$result = $client->call();
var_dump($result);
}
Response Parameters
Parameter | Type/Description |
---|---|
Order information | Object Object containing order information. |
Response Example
{
"RefNo": "74980739",
"OrderNo": 0,
"ExternalReference": "1692609928",
"ShopperRefNo": null,
"Status": "AUTHRECEIVED",
"ApproveStatus": "WAITING",
"VendorApproveStatus": "OK",
"MerchantCode": "uniqueVendorCode123",
"Language": "en",
"OrderDate": "2023-08-21 13:26:10",
"FinishDate": null,
"Source": "API",
"WSOrder": null,
"HasShipping": false,
"BillingDetails": {
"FirstName": "John",
"LastName": "Doe",
"Company": "Wayne corp",
"Email": "jhonnydoe@example.com",
"Address1": "Street 223",
"Address2": null,
"City": "Bucharest",
"Zip": "10460",
"CountryCode": "ro",
"State": "Bucharest",
"FiscalCode": null,
"TaxOffice": null,
"Phone": null
},
"DeliveryDetails": {
"FirstName": "John",
"LastName": "Doe",
"Company": "Wayne corp",
"Email": "jhonnydoe@example.com",
"Address1": "Street 223",
"Address2": null,
"City": "Bucharest",
"Zip": "2002",
"CountryCode": "ro",
"State": "Bucharest",
"Phone": null
},
"PaymentDetails": {
"Type": "GOOGLEPAY",
"Currency": "usd",
"CustomerIP": "172.18.0.1"
},
"CustomerDetails": null,
"Origin": "API",
"AvangateCommission": 0,
"OrderFlow": "REGULAR",
"GiftDetails": null,
"PODetails": null,
"ExtraInformation": null,
"PartnerCode": null,
"PartnerMargin": null,
"PartnerMarginPercent": null,
"ExtraMargin": null,
"ExtraMarginPercent": null,
"ExtraDiscount": null,
"ExtraDiscountPercent": null,
"LocalTime": null,
"TestOrder": false,
"FxRate": 1,
"FxMarkup": 0,
"PayoutCurrency": "USD",
"DeliveryFinalized": false,
"Errors": null,
"Items": [
{
"PurchaseType": "PRODUCT",
"Code": "M5S5M35YX1",
"ExternalReference": "",
"Quantity": 1,
"PriceOptions": [],
"SKU": null,
"Price": {
"Currency": "usd",
"NetPrice": 10,
"GrossPrice": 11.9,
"NetDiscountedPrice": 10,
"GrossDiscountedPrice": 11.9,
"Discount": 0,
"VAT": 1.9,
"AffiliateCommission": 0,
"UnitNetPrice": 10,
"UnitGrossPrice": 11.9,
"UnitVAT": 1.9,
"UnitDiscount": 0,
"UnitNetDiscountedPrice": 10,
"UnitGrossDiscountedPrice": 11.9,
"UnitAffiliateCommission": 0,
"ItemUnitNetPrice": null,
"ItemUnitGrossPrice": null,
"ItemNetPrice": null,
"ItemGrossPrice": null,
"VATPercent": 19,
"HandlingFeeNetPrice": 0,
"HandlingFeeGrossPrice": 0
},
"CrossSell": null,
"Trial": null,
"AdditionalFields": null,
"Promotion": null,
"RecurringOptions": null,
"SubscriptionStartDate": null,
"SubscriptionCustomSettings": null,
"UpSell": null,
"ProductDetails": {
"Name": "AntiVirus123Subscription",
"ShortDescription": "",
"Tangible": false,
"IsDynamic": false,
"ExtraInfo": null,
"RenewalStatus": false,
"Subscriptions": null,
"DeliveryInformation": {
"Delivery": "NO_DELIVERY",
"DownloadFile": null,
"DeliveryDescription": "",
"CodesDescription": "",
"Codes": []
}
},
"LineItemReference": "2bc911a264d3b92750fbd06363465f408f2a89d8"
}
],
"Promotions": [],
"AdditionalFields": null,
"Currency": "usd",
"NetPrice": 10,
"GrossPrice": 11.9,
"NetDiscountedPrice": 10,
"GrossDiscountedPrice": 11.9,
"Discount": 0,
"VAT": 1.9,
"AffiliateCommission": 0,
"CustomParameters": null,
"Refunds": null,
"ContainsRenewableProducts": null,
"RequestDeliveryData": false
}
Rate this article: