Skip to content

Commit

Permalink
OctopusDeploy release: 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
securesubmit-buildmaster committed Jun 7, 2022
1 parent a150c33 commit 7f34519
Show file tree
Hide file tree
Showing 52 changed files with 3,654 additions and 2,355 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

## Latest version
#### Enhancements:
- GP-ECOM: Add payment scheduler
- GP-ECOM/GP-API: Structure refacto
- Upgrade to min PHP 7.1

## v3.1.1 (05/17/2022)
#### Enhancements:
- GP-ECOM: Add HPP capture billing/shipping address
- Add intl and mbstring extensions on composer
- GP-API: Refacto reporting for disputes / search stored payment methods / LodgingData
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This SDK makes it easy to integrate your PHP application with our Card Not Prese

## Requirements

- PHP 5.5.9+
- PHP 7.1.0+
- OpenSSL 1.0.1+
- PHP Curl extension
- PHP DOM extension
Expand Down Expand Up @@ -64,7 +64,7 @@ In addition you can find working examples in the our example code repository.

*Quick Tip*: The included [test suite](https://github.com/globalpayments/php-sdk/tree/master/test) can be a great source of code samples for using the SDK!

#### Process a Payment Example
### Process a Payment Example

```csharp
$card = new CreditCardData();
Expand All @@ -85,7 +85,7 @@ try {
}
```

#### Test Card Data
### Test Card Data

Name | Number | Exp Month | Exp Year | CVN
----------- | ---------------- | --------- | -------- | ----
Expand All @@ -97,7 +97,7 @@ Amex | 374101000000608 | 12 | 2025 | 1234
JCB | 3566000000000000 | 12 | 2025 | 123
Diners Club | 36256000000725 | 12 | 2025 | 123

#### Testing Exceptions
### Testing Exceptions

During your integration you will want to test for specific issuer responses such as 'Card Declined'. Because our sandbox environments do not actually reach out to issuing banks for authorizations, there are specific transaction amounts and/or card numbers that will trigger gateway and issuing bank responses. Please contact your support representative for a complete listing of values used to simulate transaction AVS/CVV results, declines, errors, and other responses that can be caught in your code. Example error handling code:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": ">= 5.5.9",
"php": "^7.1",
"ext-curl": "*",
"ext-dom": "*",
"ext-openssl": "*",
Expand Down
56 changes: 56 additions & 0 deletions examples/gp-api/google-pay/charge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

require_once ('../.././../vendor/autoload.php');

use GlobalPayments\Api\Entities\Enums\EncyptedMobileType;
use GlobalPayments\Api\Entities\Enums\Environment;
use GlobalPayments\Api\Entities\Enums\Channel;
use GlobalPayments\Api\Entities\Enums\TransactionModifier;
use GlobalPayments\Api\PaymentMethods\CreditCardData;
use GlobalPayments\Api\ServiceConfigs\Gateways\GpApiConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\Api\Utils\Logging\Logger;
use GlobalPayments\Api\Utils\Logging\SampleRequestLogger;

$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

/**
* The Google Pay token. If you have any input filtering on $_POST, you will need
* to use htmlspecialchars_decode, otherwise this will not be a valid JSON anymore
* and the API will throw an error
*/
$googlePayToken = htmlspecialchars_decode($_POST['googlePayToken']);

/**
* Replace the '\\' with '\' so the encoded characters won't be decoded.
* If your code adds extra backslashes ('\') the the string, you will need to manipulate it
* in order to look like the one from test/Integration/Gateways/GpApiConnector/GpApiDigitalWalletTest.php
*/
$googlePayToken = str_replace('\\\\', '\\', $googlePayToken);

$config = new GpApiConfig();
$config->appId = 'i872l4VgZRtSrykvSn8Lkah8RE1jihvT';
$config->appKey = '9pArW2uWoA8enxKc';
$config->environment = Environment::TEST;
$config->channel = Channel::CardNotPresent;
$config->requestLogger = new SampleRequestLogger(new Logger("logs"));

ServicesContainer::configureService($config);

$card = new CreditCardData();
$card->token = $googlePayToken;
$card->mobileType = EncyptedMobileType::GOOGLE_PAY;

try {
$transaction = $card->charge('10')
->withCurrency('GBP')
->withModifier(TransactionModifier::ENCRYPTED_MOBILE)
->execute();

echo '<b>Transaction successful, your transaction id is: </b>' . $transaction->transactionId;
echo '<br />';
echo '<b>Transaction status: </b>' . $transaction->responseMessage;
} catch (\Exception $e) {
echo 'Failure: ' . $e->getMessage();
exit;
}
19 changes: 19 additions & 0 deletions examples/gp-api/google-pay/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Global Payments Google Pay with GP-API example</title>
<link rel="stylesheet" href="styles.css" />
<script defer src="main.js"></script>
<script defer
src="https://pay.google.com/gp/p/js/pay.js"
onload="onGooglePayLoaded()"></script>
</head>
<body>
<div id="container"></div>
<p class="error hide">In order to process payments via Google Pay, please switch to HTTPS.</p>
<form id="form" action="charge.php" method="POST">
<input type="hidden" id="googlePayToken" name="googlePayToken" />
</form>
</body>
</html>
257 changes: 257 additions & 0 deletions examples/gp-api/google-pay/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
/**
* Config for Google Pay
*/
const config = {
googleMerchant: '12345678901234567890', // The Merchant id Provided by Google, it can be empty in Sandbox
globalPaymentsMerchant: 'gpapiqa1', // The Merchant Id provided by Global Payments
environment: 'TEST',
countryCode: 'GB',
currencyCode: 'GBP',
amount: '10.00',
buttonColor: 'black'
}

/**
* Define the version of the Google Pay API referenced when creating your
* configuration
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest|apiVersion in PaymentDataRequest}
*/
const baseRequest = {
apiVersion: 2,
apiVersionMinor: 0
};

/**
* Card networks supported by your site and your gateway
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}
* @todo confirm card networks supported by your site and gateway
*/
const allowedCardNetworks = ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"];

/**
* Card authentication methods supported by your site and your gateway
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}
* @todo confirm your processor supports Android device tokens for your
* supported card networks
*/
const allowedCardAuthMethods = ["PAN_ONLY", "CRYPTOGRAM_3DS"];

/**
* Identify your gateway and your site's gateway merchant identifier
*
* The Google Pay API response will return an encrypted payment method capable
* of being charged by a supported gateway after payer authorization
*
* @todo check with your gateway on the parameters to pass
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#gateway|PaymentMethodTokenizationSpecification}
*/
const tokenizationSpecification = {
type: 'PAYMENT_GATEWAY',
parameters: {
'gateway': 'globalpayments',
'gatewayMerchantId': config.globalPaymentsMerchant
}
};

/**
* Describe your site's support for the CARD payment method and its required
* fields
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}
*/
const baseCardPaymentMethod = {
type: 'CARD',
parameters: {
allowedAuthMethods: allowedCardAuthMethods,
allowedCardNetworks: allowedCardNetworks
}
};

/**
* Describe your site's support for the CARD payment method including optional
* fields
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#CardParameters|CardParameters}
*/
const cardPaymentMethod = Object.assign(
{},
baseCardPaymentMethod,
{
tokenizationSpecification: tokenizationSpecification
}
);

/**
* An initialized google.payments.api.PaymentsClient object or null if not yet set
*
* @see {@link getGooglePaymentsClient}
*/
let paymentsClient = null;

/**
* Configure your site's support for payment methods supported by the Google Pay
* API.
*
* Each member of allowedPaymentMethods should contain only the required fields,
* allowing reuse of this base request when determining a viewer's ability
* to pay and later requesting a supported payment method
*
* @returns {object} Google Pay API version, payment methods supported by the site
*/
function getGoogleIsReadyToPayRequest() {
return Object.assign(
{},
baseRequest,
{
allowedPaymentMethods: [baseCardPaymentMethod]
}
);
}

/**
* Configure support for the Google Pay API
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest|PaymentDataRequest}
* @returns {object} PaymentDataRequest fields
*/
function getGooglePaymentDataRequest() {
const paymentDataRequest = Object.assign({}, baseRequest);
paymentDataRequest.allowedPaymentMethods = [cardPaymentMethod];
paymentDataRequest.transactionInfo = getGoogleTransactionInfo();
paymentDataRequest.merchantInfo = {
// @todo a merchant ID is available for a production environment after approval by Google
// See {@link https://developers.google.com/pay/api/web/guides/test-and-deploy/integration-checklist|Integration checklist}
merchantId: config.googleMerchant
};
return paymentDataRequest;
}

/**
* Return an active PaymentsClient or initialize
*
* @see {@link https://developers.google.com/pay/api/web/reference/client#PaymentsClient|PaymentsClient constructor}
* @returns {google.payments.api.PaymentsClient} Google Pay API client
*/
function getGooglePaymentsClient() {
if (paymentsClient === null) {
paymentsClient = new google.payments.api.PaymentsClient({environment: config.environment});
}
return paymentsClient;
}

/**
* Initialize Google PaymentsClient after Google-hosted JavaScript has loaded
*
* Display a Google Pay payment button after confirmation of the viewer's
* ability to pay.
*/
function onGooglePayLoaded() {
if (!deviceSupported()) {
showError();
return false;
}

const paymentsClient = getGooglePaymentsClient();
paymentsClient.isReadyToPay(getGoogleIsReadyToPayRequest())
.then(function(response) {
if (response.result) {
addGooglePayButton();
}
})
.catch(function(err) {
// show error in developer console for debugging
console.error(err);
});
}


/**
* Add a Google Pay purchase button alongside an existing checkout button
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#ButtonOptions|Button options}
* @see {@link https://developers.google.com/pay/api/web/guides/brand-guidelines|Google Pay brand guidelines}
*/
function addGooglePayButton() {
const paymentsClient = getGooglePaymentsClient();
const button = paymentsClient.createButton(
{
buttonColor: config.buttonColor,
onClick: onGooglePaymentButtonClicked
}
);
document.querySelector('#container').appendChild(button);
}

/**
* Provide Google Pay API with a payment amount, currency, and amount status
*
* @see {@link https://developers.google.com/pay/api/web/reference/request-objects#TransactionInfo|TransactionInfo}
* @returns {object} transaction info, suitable for use as transactionInfo property of PaymentDataRequest
*/
function getGoogleTransactionInfo() {
return {
countryCode: config.countryCode,
currencyCode: config.currencyCode,
totalPriceStatus: 'FINAL',
// set to cart total
totalPrice: config.amount
};
}

/**
* Show Google Pay payment sheet when Google Pay payment button is clicked
*/
function onGooglePaymentButtonClicked() {
const paymentDataRequest = getGooglePaymentDataRequest();
paymentDataRequest.transactionInfo = getGoogleTransactionInfo();

const paymentsClient = getGooglePaymentsClient();
paymentsClient.loadPaymentData(paymentDataRequest)
.then(function(paymentData) {
// handle the response
processPayment(paymentData);
})
.catch(function(err) {
// show error in developer console for debugging
console.error(err);
});
}

/**
* Process payment data returned by the Google Pay API
*
* @param {object} paymentData response from Google Pay API after user approves payment
* @see {@link https://developers.google.com/pay/api/web/reference/response-objects#PaymentData|PaymentData object reference}
*/
function processPayment(paymentData) {
/**
* Google sends a JSON with some characters encoded (which should not be).
* Parsing the JSON and then stringifying it again fixes the issue.
*/
var paymentToken = JSON.stringify(JSON.parse(paymentData.paymentMethodData.tokenizationData.token));
setToken(paymentToken);
submitForm();
}

/**
* Set the token received from Google to the form
* @param googleToken
*/
function setToken(googleToken) {
document.querySelector('#googlePayToken').value = googleToken;
}

function submitForm() {
document.querySelector('#form').submit();
}

function showError() {
document.querySelector('.error').classList.remove('hide');
}

function deviceSupported() {
return location.protocol === 'https:';
}
Loading

0 comments on commit 7f34519

Please sign in to comment.