Skip to content

Commit

Permalink
OctopusDeploy release: 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
securesubmit-buildmaster committed Nov 16, 2021
1 parent 34dead5 commit 3e936b4
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

## Latest version

#### Enhancements:
- Add LPMs HPP on GP-ECOM
- Add PAYPAL on GP-ECOM

## v2.4.1 (11/12/2021)

#### Enhancements:
- Add reporting service to get transaction by id on GP-ECOM
- Add HPP_POST_DIMENSIONS and HPP_POST_RESPONSE to serialize on GP-ECOM

Expand Down
2 changes: 1 addition & 1 deletion metadata.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<xml>
<releaseNumber>2.4.1</releaseNumber>
<releaseNumber>2.4.2</releaseNumber>
</xml>
20 changes: 20 additions & 0 deletions src/Entities/HostedPaymentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace GlobalPayments\Api\Entities;

use GlobalPayments\Api\Entities\Enums\AlternativePaymentType;

/**
* Data collection to supplement a hosted payment page.
*/
Expand Down Expand Up @@ -87,6 +89,24 @@ class HostedPaymentData
*/
public $supplementaryData;

/** @var string */
public $customerCountry;

/** @var string */
public $customerFirstName;

/** @var string */
public $customerLastName;

/** @var string */
public $merchantResponseUrl;

/** @var string */
public $transactionStatusUrl;

/** @var array<AlternativePaymentType> */
public $presetPaymentMethods = [];

/**
* Instantiates a new `HostedPaymentData` object.
*
Expand Down
5 changes: 3 additions & 2 deletions src/Entities/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,11 @@ public function void($amount = null)
*
* @return ManagementBuilder
*/
public function confirm()
public function confirm($amount = null)
{
return (new ManagementBuilder(TransactionType::CONFIRM))
->withPaymentMethod($this->transactionReference);
->withPaymentMethod($this->transactionReference)
->withAmount($amount);
}

public function __get($name)
Expand Down
99 changes: 94 additions & 5 deletions src/Gateways/RealexConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GlobalPayments\Api\Builders\RecurringBuilder;
use GlobalPayments\Api\Builders\ReportBuilder;
use GlobalPayments\Api\Entities\Address;
use GlobalPayments\Api\Entities\Enums\AlternativePaymentType;
use GlobalPayments\Api\Entities\Enums\CvnPresenceIndicator;
use GlobalPayments\Api\Entities\Enums\PaymentMethodType;
use GlobalPayments\Api\Entities\Enums\ReportType;
Expand Down Expand Up @@ -562,6 +563,7 @@ public function serializeRequest(AuthorizationBuilder $builder)
$this->hostedPaymentConfig->directCurrencyConversionEnabled ? "1" : "0";
}
if (!empty($builder->hostedPaymentData)) {
$hostedPaymentData = $builder->hostedPaymentData;
$this->setSerializeData('CUST_NUM', $builder->hostedPaymentData->customerNumber);

if (!empty($this->hostedPaymentConfig->displaySavedCards) &&
Expand Down Expand Up @@ -590,6 +592,26 @@ public function serializeRequest(AuthorizationBuilder $builder)
if (isset($builder->hostedPaymentData->productId)) {
$this->setSerializeData('PROD_ID', $builder->hostedPaymentData->productId);
}
// APMs Fields
if (!empty($hostedPaymentData->customerCountry)) {
$this->setSerializeData('HPP_CUSTOMER_COUNTRY', $hostedPaymentData->customerCountry);
}
if (!empty($hostedPaymentData->customerFirstName)) {
$this->setSerializeData('HPP_CUSTOMER_FIRSTNAME', $hostedPaymentData->customerFirstName);
}
if (!empty($hostedPaymentData->customerLastName)) {
$this->setSerializeData('HPP_CUSTOMER_LASTNAME', $hostedPaymentData->customerLastName);
}
if (!empty($hostedPaymentData->merchantResponseUrl)) {
$this->setSerializeData('MERCHANT_RESPONSE_URL', $hostedPaymentData->merchantResponseUrl);
}
if (!empty($hostedPaymentData->transactionStatusUrl)) {
$this->setSerializeData('HPP_TX_STATUS_URL', $hostedPaymentData->transactionStatusUrl);
}
if (!empty($hostedPaymentData->presetPaymentMethods)) {
$this->setSerializeData('PM_METHODS', implode( '|', $hostedPaymentData->presetPaymentMethods));
}
// end APMs Fields
} elseif (isset($builder->customerId)) {
$this->setSerializeData('CUST_NUM', $builder->customerId);
}
Expand Down Expand Up @@ -705,9 +727,13 @@ public function serializeRequest(AuthorizationBuilder $builder)
null;
}

if (!empty($this->hostedPaymentConfig->fraudFilterMode) && $this->hostedPaymentConfig->fraudFilterMode !== FraudFilterMode::NONE) {
if (
!empty($this->hostedPaymentConfig->fraudFilterMode) &&
$this->hostedPaymentConfig->fraudFilterMode !== FraudFilterMode::NONE
) {
$toHash[] = $this->hostedPaymentConfig->fraudFilterMode;
}

if (!empty($builder->dynamicDescriptor)) {
$this->serializeData["CHARGE_DESCRIPTION"] = $builder->dynamicDescriptor;
}
Expand Down Expand Up @@ -768,6 +794,17 @@ public function manageTransaction(ManagementBuilder $builder)

if ($builder->alternativePaymentType !== null) {
$request->appendChild($xml->createElement("paymentmethod", $builder->alternativePaymentType));
if ($builder->transactionType == TransactionType::CONFIRM) {
$paymentMethodDetails = $xml->createElement("paymentmethoddetails");
$apmResponse = $builder->paymentMethod->alternativePaymentResponse;
if ($builder->alternativePaymentType == AlternativePaymentType::PAYPAL) {
$paymentMethodDetails->appendChild($xml->createElement('Token', $apmResponse->sessionToken));
$paymentMethodDetails->appendChild(
$xml->createElement('PayerID', $apmResponse->providerReference)
);
}
$request->appendChild($paymentMethodDetails);
}
}

if ($builder->transactionType === TransactionType::VERIFY_SIGNATURE) {
Expand Down Expand Up @@ -1123,6 +1160,39 @@ protected function mapResponse($rawResponse, array $acceptedCodes = null)
$root->paymentmethoddetails->redirecturl;
$result->alternativePaymentResponse->paymentPurpose = (string)
$root->paymentmethoddetails->paymentpurpose;
$result->alternativePaymentResponse->providerName = (string) $root->paymentmethod;
if (!empty($root->paymentmethoddetails->SetExpressCheckoutResponse)) {
$apmResponseDetails = $root->paymentmethoddetails->SetExpressCheckoutResponse;
} elseif (!empty($root->paymentmethoddetails->DoExpressCheckoutPaymentResponse)) {
$apmResponseDetails = $root->paymentmethoddetails->DoExpressCheckoutPaymentResponse;
}
if (!empty($apmResponseDetails)) {
$result->alternativePaymentResponse->sessionToken = !empty($apmResponseDetails->Token) ?
(string) $apmResponseDetails->Token : null;
$result->alternativePaymentResponse->ack = !empty($apmResponseDetails->Ack) ?
(string) $apmResponseDetails->Ack : null;
$result->alternativePaymentResponse->timeCreatedReference = !empty($apmResponseDetails->Timestamp) ?
(string) $apmResponseDetails->Timestamp : null;
$result->alternativePaymentResponse->correlationReference = !empty($apmResponseDetails->CorrelationID) ?
(string) $apmResponseDetails->CorrelationID : null;
$result->alternativePaymentResponse->versionReference = !empty($apmResponseDetails->Version) ?
(string) $apmResponseDetails->Version : null;
$result->alternativePaymentResponse->buildReference = !empty($apmResponseDetails->Build) ?
(string) $apmResponseDetails->Build : null;
if (!empty($apmResponseDetails->PaymentInfo)) {
$paymentInfo = $apmResponseDetails->PaymentInfo;
$result->alternativePaymentResponse->transactionReference = (string) $paymentInfo->TransactionID;
$result->alternativePaymentResponse->paymentType = (string) $paymentInfo->PaymentType;
$result->alternativePaymentResponse->paymentTimeReference = (string) $paymentInfo->PaymentDate;
$result->alternativePaymentResponse->grossAmount = (string) $paymentInfo->GrossAmount;
$result->alternativePaymentResponse->feeAmount = (string) $paymentInfo->TaxAmount;
$result->alternativePaymentResponse->paymentStatus = (string) $paymentInfo->PaymentStatus;
$result->alternativePaymentResponse->pendingReason = (string) $paymentInfo->PendingReason;
$result->alternativePaymentResponse->reasonCode = (string) $paymentInfo->ReasonCode;
$result->alternativePaymentResponse->authProtectionEligibilty = (string) $paymentInfo->ProtectionEligibility;
$result->alternativePaymentResponse->authProtectionEligibiltyType = (string) $paymentInfo->ProtectionEligibilityType;
}
}
}

return $result;
Expand Down Expand Up @@ -1275,6 +1345,8 @@ protected function mapManageRequestType(ManagementBuilder $builder)
return 'void';
case TransactionType::VERIFY_SIGNATURE:
return '3ds-verifysig';
case TransactionType::CONFIRM:
return 'payment-do';
default:
return 'unknown';
}
Expand Down Expand Up @@ -1460,13 +1532,20 @@ public function buildAlternativePaymentMethod($builder, $request, $xml)
));

$paymentMethodDetails = $xml->createElement("paymentmethoddetails");
list($returnUrl, $statusUpdateUrl, $cancelUrl) =
$this->mapAPMUrls($builder->paymentMethod->alternativePaymentMethodType);
$paymentMethodDetails->appendChild(
$xml->createElement("returnurl", $builder->paymentMethod->returnUrl)
$xml->createElement($returnUrl, $builder->paymentMethod->returnUrl)
);
$paymentMethodDetails->appendChild(
$xml->createElement("statusupdateurl", $builder->paymentMethod->statusUpdateUrl)
$xml->createElement($statusUpdateUrl, $builder->paymentMethod->statusUpdateUrl)
);

if (!empty($builder->paymentMethod->cancelUrl)) {
$paymentMethodDetails->appendChild(
$xml->createElement($cancelUrl, $builder->paymentMethod->cancelUrl)
);
}

if (!empty($builder->paymentMethod->descriptor)) {
$paymentMethodDetails->appendChild(
$xml->createElement("descriptor", $builder->paymentMethod->descriptor)
Expand All @@ -1491,11 +1570,21 @@ private function mapAcceptedCodes($paymentMethodType)
case "3ds-verifyenrolled":
return ["00", "110"];
case "payment-set":
return ["01"];
return ["01", "00"];
default:
return ["00"];
}
}

private function mapAPMUrls($paymentMethodType)
{
switch ($paymentMethodType) {
case AlternativePaymentType::PAYPAL:
return ['ReturnURL', 'StatusUpdateURL', 'CancelURL'];
default:
return ['returnurl', 'statusupdateurl', 'cancelurl'];
}
}

private function setSerializeData($key, $value = null)
{
Expand Down
75 changes: 55 additions & 20 deletions test/Integration/Gateways/RealexConnector/Hpp/RealexHppClient.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php
namespace GlobalPayments\Api\Tests\Integration\Gateways\RealexConnector\Hpp;

use GlobalPayments\Api\Entities\AlternativePaymentResponse;
use GlobalPayments\Api\Entities\Enums\AlternativePaymentType;
use GlobalPayments\Api\Entities\FraudRuleCollection;
use GlobalPayments\Api\PaymentMethods\AlternativePaymentMethod;
use GlobalPayments\Api\PaymentMethods\CreditCardData;
use GlobalPayments\Api\ServicesConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\Api\Entities\Address;
use GlobalPayments\Api\Entities\Customer;
use GlobalPayments\Api\Tests\Data\TestCards;
use GlobalPayments\Api\Utils\GenerationUtils;
use GlobalPayments\Api\Entities\Exceptions\ApiException;
use GlobalPayments\Api\Builders\AuthorizationBuilder;
use GlobalPayments\Api\Entities\Enums\AddressType;
use GlobalPayments\Api\Entities\DccRateData;
use GlobalPayments\Api\HostedPaymentConfig;
use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig;
use GlobalPayments\Api\Utils\Logging\Logger;
use GlobalPayments\Api\Utils\Logging\SampleRequestLogger;

class RealexHppClient
{
Expand Down Expand Up @@ -48,21 +50,14 @@ public function sendRequest($jsonData, $hppVersion = '')
$config->accountId = $account;
$config->sharedSecret = $this->sharedSecret;
$config->serviceUrl = 'https://api.sandbox.realexpayments.com/epage-remote.cgi';
//to be uncomment in case you need to log the raw request/response
// $config->requestLogger = new SampleRequestLogger(new Logger("logs"));
$config->hostedPaymentConfig = new HostedPaymentConfig();
$config->hostedPaymentConfig->language = "GB";
$config->hostedPaymentConfig->responseUrl = "http://requestb.in/10q2bjb1";
$config->hostedPaymentConfig->version = $hppVersion;

ServicesContainer::configureService($config);

// create the card object
$card = new CreditCardData();
$card->number = '4006097467207025';
$card->expMonth = 12;
$card->expYear = TestCards::validCardExpYear();
$card->cvn = '131';
$card->cardHolderName = 'James Mason';

// // check hash
$hashParam = [
$timestamp,
Expand All @@ -72,6 +67,29 @@ public function sendRequest($jsonData, $hppVersion = '')
$currency
];

// create the card/APM/LPM object
if (!empty($this->getValue('PM_METHODS'))) {
$apmTypes = explode("|", $this->getValue('PM_METHODS'));
$apmType = reset($apmTypes);
$card = new AlternativePaymentMethod($apmType);
$card->returnUrl = $this->getValue('MERCHANT_RESPONSE_URL');
$card->statusUpdateUrl = $this->getValue('HPP_TX_STATUS_URL');
if ($apmType == AlternativePaymentType::PAYPAL) {
//cancelUrl for Paypal example
$card->cancelUrl = 'https://www.example.com/failure/cancelURL';
}
$card->country = $this->getValue('HPP_CUSTOMER_COUNTRY');
$card->accountHolderName =
$this->getValue('HPP_CUSTOMER_FIRSTNAME') . ' '. $this->getValue('HPP_CUSTOMER_LASTNAME') ;
} else {
$card = new CreditCardData();
$card->number = '4006097467207025';
$card->expMonth = 12;
$card->expYear = TestCards::validCardExpYear();
$card->cvn = '131';
$card->cardHolderName = 'James Mason';
}

//for stored card
if (!empty($this->paymentData['OFFER_SAVE_CARD'])) {
$hashParam[] = (!empty($this->paymentData['PAYER_REF'])) ?
Expand All @@ -83,11 +101,11 @@ public function sendRequest($jsonData, $hppVersion = '')
if (!empty($this->paymentData['HPP_FRAUDFILTER_MODE'])) {
$hashParam[] = $this->paymentData['HPP_FRAUDFILTER_MODE'];
}

$newHash = GenerationUtils::generateHash(
$this->sharedSecret,
implode('.', $hashParam)
);

if ($newHash != $requestHash) {
throw new ApiException("Incorrect hash. Please check your code and the Developers Documentation.");
}
Expand Down Expand Up @@ -125,13 +143,14 @@ public function sendRequest($jsonData, $hppVersion = '')
$this->addFraudManagementInfo($gatewayRequest, $orderId);

$gatewayResponse = $gatewayRequest->execute();
if ($gatewayResponse->responseCode === '00') {

if (in_array($gatewayResponse->responseCode, ['00', '01'])) {
return $this->convertResponse($gatewayResponse);
}
} catch (ApiException $exc) {
throw $exc;
}

return null;
}

Expand Down Expand Up @@ -266,13 +285,29 @@ public function convertResponse($gatewayResponse)
'DCC_INFO_REQUST' => $this->getValue('DCC_INFO'),
'DCC_INFO_RESPONSE' => $gatewayResponse->dccResponseResult,
'HPP_FRAUDFILTER_MODE' => $this->getValue('HPP_FRAUDFILTER_MODE'),
'HPP_FRAUDFILTER_RESULT' => $gatewayResponse->fraudFilterResponse->fraudResponseResult
'HPP_FRAUDFILTER_RESULT' => !empty($gatewayResponse->fraudFilterResponse) ?
$gatewayResponse->fraudFilterResponse->fraudResponseResult : null
];
$hppFraudRules = [];
foreach ($gatewayResponse->fraudFilterResponse->fraudResponseRules as $fraudResponseRule) {
$hppFraudRules['HPP_FRAUDFILTER_RULE_' .$fraudResponseRule['id']] = $fraudResponseRule['action'];
if (!empty($gatewayResponse->transactionReference->alternativePaymentResponse)) {
/** @var AlternativePaymentResponse $alternativePaymentResponse */
$alternativePaymentResponse = $gatewayResponse->transactionReference->alternativePaymentResponse;
$apmResponse = [
'HPP_CUSTOMER_FIRSTNAME' => $this->getValue('HPP_CUSTOMER_FIRSTNAME'),
'HPP_CUSTOMER_LASTNAME' => $this->getValue('HPP_CUSTOMER_LASTNAME'),
'HPP_CUSTOMER_COUNTRY' => $this->getValue('HPP_CUSTOMER_COUNTRY'),
'PAYMENTMETHOD' => $alternativePaymentResponse->providerName,
'PAYMENTPURPOSE' => $alternativePaymentResponse->paymentPurpose,
'HPP_CUSTOMER_BANK_ACCOUNT' => $alternativePaymentResponse->bankAccount
];
$response = array_merge($response, $apmResponse);
}
if (!empty($gatewayResponse->fraudFilterResponse)) {
$hppFraudRules = [];
foreach ($gatewayResponse->fraudFilterResponse->fraudResponseRules as $fraudResponseRule) {
$hppFraudRules['HPP_FRAUDFILTER_RULE_' .$fraudResponseRule['id']] = $fraudResponseRule['action'];
}
$response = array_merge($response, $hppFraudRules);
}
$response = array_merge($response, $hppFraudRules);
$response['TSS_INFO'] = $this->getValue('TSS_INFO');

return json_encode($response);
Expand Down
Loading

0 comments on commit 3e936b4

Please sign in to comment.