Skip to content

Commit

Permalink
OctopusDeploy release: 6.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
securesubmit-buildmaster committed Dec 13, 2022
1 parent 5a8f97a commit 6cfaeba
Show file tree
Hide file tree
Showing 29 changed files with 1,267 additions and 65 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

## Latest version
#### Enhancements:
- GP-API: Add BNPL feature
- GP-API: Click-to-Pay

## v6.0.3 (12/06/2022)
#### Enhancements:
- PAX: Adding tip after the Sale
- Portico: APPLE PAY / GOOGLE PAY fix for token format

Expand All @@ -19,7 +24,7 @@
- GP-API/GP-ECOM: Fix end-to-end examples
- Portico: APPLE PAY / GOOGLE PAY fix

## v6.0.0 (11/03/2022)
## v6.0.1 (11/03/2022)
#### Enhancements:
- Security vulnerabilities fixes

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>6.0.3</releaseNumber>
<releaseNumber>6.0.4</releaseNumber>
</xml>
21 changes: 21 additions & 0 deletions src/Builders/AuthorizationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
use GlobalPayments\Api\Entities\Address;
use GlobalPayments\Api\Entities\AutoSubstantiation;
use GlobalPayments\Api\Entities\EcommerceInfo;
use GlobalPayments\Api\Entities\Enums\BNPLShippingMethod;
use GlobalPayments\Api\Entities\Enums\EmvFallbackCondition;
use GlobalPayments\Api\Entities\Enums\EmvLastChipRead;
use GlobalPayments\Api\Entities\Enums\FraudFilterMode;
use GlobalPayments\Api\Entities\Enums\PaymentMethodUsageMode;
use GlobalPayments\Api\Entities\Enums\PhoneNumberType;
use GlobalPayments\Api\Entities\Enums\RemittanceReferenceType;
use GlobalPayments\Api\Entities\Exceptions\ArgumentException;
use GlobalPayments\Api\Entities\FraudRuleCollection;
use GlobalPayments\Api\Entities\HostedPaymentData;
use GlobalPayments\Api\Entities\Enums\AddressType;
Expand All @@ -23,6 +25,7 @@
use GlobalPayments\Api\Entities\PhoneNumber;
use GlobalPayments\Api\Entities\StoredCredential;
use GlobalPayments\Api\Entities\Transaction;
use GlobalPayments\Api\PaymentMethods\BNPL;
use GlobalPayments\Api\PaymentMethods\EBTCardData;
use GlobalPayments\Api\PaymentMethods\GiftCard;
use GlobalPayments\Api\PaymentMethods\Interfaces\IPaymentMethod;
Expand Down Expand Up @@ -505,6 +508,9 @@ class AuthorizationBuilder extends TransactionBuilder
/** @var string */
public $remittanceReferenceValue;

/** @var BNPLShippingMethod */
public $bnplShippingMethod;

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -1415,4 +1421,19 @@ public function withRemittanceReference($remittanceReferenceType, $remittanceRef

return $this;
}

/**
* @param BNPLShippingMethod $bnpShippingMethod
*
* @return $this
* @throws ArgumentException
*/
public function withBNPLShippingMethod($bnpShippingMethod)
{
if (!$this->paymentMethod instanceof BNPL) {
throw new ArgumentException("The selected payment method doesn't support this property!");
}
$this->bnplShippingMethod = $bnpShippingMethod;
return $this;
}
}
185 changes: 141 additions & 44 deletions src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GlobalPayments\Api\Builders\AuthorizationBuilder;
use GlobalPayments\Api\Builders\BaseBuilder;
use GlobalPayments\Api\Entities\CustomerDocument;
use GlobalPayments\Api\Entities\EncryptionData;
use GlobalPayments\Api\Entities\Enums\CardType;
use GlobalPayments\Api\Entities\Enums\Channel;
Expand All @@ -25,7 +26,9 @@
use GlobalPayments\Api\Entities\IRequestBuilder;
use GlobalPayments\Api\Entities\PayLinkData;
use GlobalPayments\Api\Entities\PhoneNumber;
use GlobalPayments\Api\Entities\Product;
use GlobalPayments\Api\Mapping\EnumMapping;
use GlobalPayments\Api\PaymentMethods\BNPL;
use GlobalPayments\Api\PaymentMethods\CreditCardData;
use GlobalPayments\Api\PaymentMethods\CreditTrackData;
use GlobalPayments\Api\PaymentMethods\DebitTrackData;
Expand Down Expand Up @@ -205,11 +208,12 @@ private function createFromAuthorizationBuilder($builder, GpApiConfig $config)

if (
$builder->paymentMethod instanceof ECheck ||
$builder->paymentMethod instanceof AlternativePaymentMethod
$builder->paymentMethod instanceof AlternativePaymentMethod ||
$builder->paymentMethod instanceof BNPL
) {
$requestBody['payer'] = $this->setPayerInformation($builder);
}
if ($builder->paymentMethod instanceof AlternativePaymentMethod) {
if ($builder->paymentMethod instanceof AlternativePaymentMethod || $builder->paymentMethod instanceof BNPL) {
$this->setOrderInformation($builder, $requestBody);

$requestBody['notifications'] = [
Expand Down Expand Up @@ -280,6 +284,44 @@ private function setPayerInformation($builder)
list($phoneNumber, $phoneCountryCode) = $this->getPhoneNumber($builder, PhoneNumberType::MOBILE);
$payer['mobile_phone'] = $phoneCountryCode . $phoneNumber;
break;
case BNPL::class:
if (empty($builder->customerData)) {
break;
}
$payer['email'] = $builder->customerData->email;
$payer['date_of_birth'] = $builder->customerData->dateOfBirth;
if (!empty($builder->billingAddress)) {
$payer['billing_address'] = [
'line_1' => $builder->billingAddress->streetAddress1,
'line_2' => $builder->billingAddress->streetAddress2,
'city' => $builder->billingAddress->city,
'postal_code' => $builder->billingAddress->postalCode,
'state' => $builder->billingAddress->state,
'country' => $builder->billingAddress->countryCode,
'first_name' => $builder->customerData->firstName ?? '',
'last_name' => $builder->customerData->lastName ?? ''
];
}
if (isset($builder->customerData->phone)) {
$payer['contact_phone'] = [
'country_code' => !empty($builder->customerData->phone->countryCode) ?
StringUtils::validateToNumber($builder->customerData->phone->countryCode): null,
'subscriber_number' => !empty($builder->customerData->phone->number) ?
StringUtils::validateToNumber($builder->customerData->phone->number): null,
];
}
if (!empty($builder->customerData->documents)) {
/** @var CustomerDocument $document */
foreach ($builder->customerData->documents as $document) {
$documents[] = [
'type' => $document->type,
'reference' => $document->reference,
'issuer' => $document->issuer
];
}
$payer['documents'] = $documents ?? null;
}
break;
default:
break;
}
Expand Down Expand Up @@ -323,7 +365,7 @@ private function getPhoneNumber($builder, $type)
*/
private function createPaymentMethodParam($builder, $config)
{
/** @var CreditCardData|CreditTrackData|DebitTrackData|ECheck|AlternativePaymentMethod $paymentMethodContainer */
/** @var CreditCardData|CreditTrackData|DebitTrackData|ECheck|AlternativePaymentMethod|BNPL $paymentMethodContainer */
$paymentMethodContainer = $builder->paymentMethod;
$paymentMethod = new PaymentMethod();
$paymentMethod->entry_mode = $this->getEntryMode($builder, $config->channel);
Expand Down Expand Up @@ -397,6 +439,15 @@ private function createPaymentMethodParam($builder, $config)
$paymentMethodContainer->addressOverrideMode : null
];

return $paymentMethod;
case BNPL::class:
if (!empty($builder->customerData->firstName) && !empty($builder->customerData->lastName)) {
$name = $builder->customerData->firstName . ' ' . $builder->customerData->lastName;
}
$paymentMethod->name = $name ?? null;
$paymentMethod->bnpl = [
'provider' => $paymentMethodContainer->bnplType
];
return $paymentMethod;
default:
break;
Expand Down Expand Up @@ -562,9 +613,9 @@ private function setOrderInformation($builder, &$requestBody)
$builder->orderDetails->description : null;
if (!empty($builder->shippingAddress)) {
$order['shipping_address'] = [
'line1' => $builder->shippingAddress->streetAddress1,
'line2' => $builder->shippingAddress->streetAddress2,
'line3' => $builder->shippingAddress->streetAddress3,
'line_1' => $builder->shippingAddress->streetAddress1,
'line_2' => $builder->shippingAddress->streetAddress2,
'line_3' => $builder->shippingAddress->streetAddress3,
'city' => $builder->shippingAddress->city,
'postal_code' => $builder->shippingAddress->postalCode,
'state' => $builder->shippingAddress->state,
Expand All @@ -577,47 +628,19 @@ private function setOrderInformation($builder, &$requestBody)
'subscriber_number' => $phoneNumber
];

if (!empty($builder->productData)) {
$taxTotalAmount = $itemsAmount = 0;
foreach ($builder->productData as $product) {
$qta = !empty($product['quantity']) ? $product['quantity'] : 0;
$taxAmount = !empty($product['tax_amount']) ? StringUtils::toNumeric($product['tax_amount']) : 0;
$unitAmount = !empty($product['unit_amount']) ? StringUtils::toNumeric($product['unit_amount']) : 0;
$items[] = [
'reference' => !empty($product['reference']) ? $product['reference'] : null,
'label' => !empty($product['label']) ? $product['label'] : null,
'description' => !empty($product['description']) ? $product['description'] : null,
'quantity' => $qta,
'unit_amount' => $unitAmount,
'unit_currency' => !empty($product['unit_currency']) ? $product['unit_currency'] : null,
'tax_amount' => $taxAmount,
'amount' => $qta * $unitAmount
];
if (!empty($product['tax_amount'])) {
$taxTotalAmount += $taxAmount;
switch (get_class($builder->paymentMethod)) {
case AlternativePaymentMethod::class:
if (!empty($builder->productData)) {
$this->setItemDetailsListForApm($builder, $order);
}
if (!empty($product['unit_amount'])) {
$itemsAmount += $unitAmount;
break;
case BNPL::class:
$order['shipping_method'] = $builder->bnplShippingMethod;
if (!empty($builder->productData)) {
$this->setItemDetailsListForBNPL($builder, $order);
}
}

$order['tax_amount'] = $taxTotalAmount;
$order['item_amount'] = $itemsAmount;
$order['shipping_amount'] = !empty($builder->shippingAmount) ?
StringUtils::toNumeric($builder->shippingAmount) : 0;
$order['insurance_offered'] = !empty($builder->orderDetails) && !is_null($builder->orderDetails->hasInsurance) ?
($builder->orderDetails->hasInsurance === true ? 'YES' : 'NO') : null;
$order['shipping_discount'] = !empty($builder->shippingDiscount) ?
StringUtils::toNumeric($builder->shippingDiscount) : 0;
$order['insurance_amount'] = !empty($builder->orderDetails->insuranceAmount) ?
StringUtils::toNumeric($builder->orderDetails->insuranceAmount) : 0;
$order['handling_amount'] = !empty($builder->orderDetails->handlingAmount) ?
StringUtils::toNumeric($builder->orderDetails->handlingAmount) : 0;
$orderAmount = $itemsAmount + $taxTotalAmount + $order['handling_amount'] + $order['insurance_amount'] + $order['shipping_amount'];
$order['amount'] = $orderAmount;
$order['currency'] = $builder->currency;
break;
}
$order['items'] = !empty($items) ? $items : null;

if (!empty($orderAmount)) {
$requestBody['amount'] = $orderAmount;
Expand All @@ -630,6 +653,80 @@ private function setOrderInformation($builder, &$requestBody)
return $requestBody;
}

private function setItemDetailsListForBNPL($builder, &$order)
{
/** @var Product $product */
foreach ($builder->productData as $product) {
$qta = !empty($product->quantity) ? (int) $product->quantity : 0;
$unitAmount = !empty($product->unitPrice) ? StringUtils::toNumeric($product->unitPrice) : 0;
$taxAmount = !empty($product->taxAmount) ? StringUtils::toNumeric($product->taxAmount) : 0;
$netUnitAmount = !empty($product->netUnitPrice) ? StringUtils::toNumeric($product->netUnitPrice) : 0;
$discountAmount = !empty($product->discountAmount) ? StringUtils::toNumeric($product->discountAmount) : 0;
$items[] = [
'reference' => !empty($product->productId) ? $product->productId : null,
'label' => !empty($product->productName) ? $product->productName : null,
'description' => !empty($product->description) ? $product->description : null,
'quantity' => (string) $qta,
'unit_amount' => (string) $unitAmount,
'total_amount' => (string) ($qta * $unitAmount),
'tax_amount' => (string)$taxAmount,
'discount_amount' => (string)$discountAmount,
'tax_percentage' => !empty($product->taxPercentage) ? StringUtils::toNumeric($product->taxPercentage) : "0",
'net_unit_amount' => (string) $netUnitAmount,
'url' => !empty($product->url) ? $product->url : null,
'image_url' => !empty($product->imageUrl) ? $product->imageUrl : null,
];
}
if (isset($builder->customerData)) {
$order['shipping_address']['first_name'] = $builder->customerData->firstName;
$order['shipping_address']['last_name'] = $builder->customerData->lastName;
}
$order['items'] = $items ?? null;
}

private function setItemDetailsListForApm($builder, &$order)
{
$taxTotalAmount = $itemsAmount = 0;
foreach ($builder->productData as $product) {
$qta = !empty($product['quantity']) ? $product['quantity'] : 0;
$taxAmount = !empty($product['tax_amount']) ? StringUtils::toNumeric($product['tax_amount']) : 0;
$unitAmount = !empty($product['unit_amount']) ? StringUtils::toNumeric($product['unit_amount']) : 0;
$items[] = [
'reference' => !empty($product['reference']) ? $product['reference'] : null,
'label' => !empty($product['label']) ? $product['label'] : null,
'description' => !empty($product['description']) ? $product['description'] : null,
'quantity' => $qta,
'unit_amount' => $unitAmount,
'unit_currency' => !empty($product['unit_currency']) ? $product['unit_currency'] : null,
'tax_amount' => $taxAmount,
'amount' => $qta * $unitAmount
];
if (!empty($product['tax_amount'])) {
$taxTotalAmount += $taxAmount;
}
if (!empty($product['unit_amount'])) {
$itemsAmount += $unitAmount;
}
}

$order['tax_amount'] = $taxTotalAmount;
$order['item_amount'] = $itemsAmount;
$order['shipping_amount'] = !empty($builder->shippingAmount) ?
StringUtils::toNumeric($builder->shippingAmount) : 0;
$order['insurance_offered'] = !empty($builder->orderDetails) && !is_null($builder->orderDetails->hasInsurance) ?
($builder->orderDetails->hasInsurance === true ? 'YES' : 'NO') : null;
$order['shipping_discount'] = !empty($builder->shippingDiscount) ?
StringUtils::toNumeric($builder->shippingDiscount) : 0;
$order['insurance_amount'] = !empty($builder->orderDetails->insuranceAmount) ?
StringUtils::toNumeric($builder->orderDetails->insuranceAmount) : 0;
$order['handling_amount'] = !empty($builder->orderDetails->handlingAmount) ?
StringUtils::toNumeric($builder->orderDetails->handlingAmount) : 0;
$orderAmount = $itemsAmount + $taxTotalAmount + $order['handling_amount'] + $order['insurance_amount'] + $order['shipping_amount'];
$order['amount'] = $orderAmount;
$order['currency'] = $builder->currency;
$order['items'] = $items ?? null;
}

public function mapFraudManagement()
{
if (!empty($this->builder->fraudRules)) {
Expand Down
19 changes: 19 additions & 0 deletions src/Entities/BNPLResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace GlobalPayments\Api\Entities;

/**
* BNPL response entity
*/
class BNPLResponse
{
/** @var string */
public $providerName;

/**
* URL to redirect the customer, sent so merchant can redirect consumer to complete the payment.
*
* @var string
*/
public $redirectUrl;
}
6 changes: 6 additions & 0 deletions src/Entities/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ class Customer extends RecurringEntity
*/
public $status;

/** @var PhoneNumber */
public $phone;

/** @var array<CustomerDocument> */
public $documents = [];

/**
* Adds a payment method to the customer
*
Expand Down
24 changes: 24 additions & 0 deletions src/Entities/CustomerDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace GlobalPayments\Api\Entities;

use GlobalPayments\Api\Entities\Enums\CustomerDocumentType;

class CustomerDocument
{
/** @var string */
public $reference;

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

/** @var CustomerDocumentType */
public $type;

public function __construct($reference, $issuer, $type)
{
$this->reference = $reference;
$this->issuer = $issuer;
$this->type = $type;
}
}
Loading

0 comments on commit 6cfaeba

Please sign in to comment.