diff --git a/CHANGELOG.md b/CHANGELOG.md index 08037a49..f01ea005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ ## Latest version #### Enhancements: +- GP-API: add risk assessment feature +- Refacto the Secure3DBuilder + +## v6.0.6 (02/26/2023) +#### Enhancements: - GPI Transactions : added support for credit, ach & reporting transactions - GP-API: add to generateXGPSignature to GenerationUtils - Portico Gateway: Fix incorrect date handling in schedule response diff --git a/metadata.xml b/metadata.xml index d5b0e1f9..fff7c43f 100644 --- a/metadata.xml +++ b/metadata.xml @@ -1,3 +1,3 @@ - 6.0.6 + 6.1.0 \ No newline at end of file diff --git a/src/Builders/FraudBuilder.php b/src/Builders/FraudBuilder.php new file mode 100644 index 00000000..47c8b3bf --- /dev/null +++ b/src/Builders/FraudBuilder.php @@ -0,0 +1,38 @@ +authenticationSource = AuthenticationSource::BROWSER; + $this->transactionType = $transactionType; + } + + public function withPaymentMethod(IPaymentMethod $value) + { + $this->paymentMethod = $value; + return $this; + } + + public function execute($configName = 'default') + { + $client = ServicesContainer::instance()->getFraudCheckClient($configName); + return $client->processFraud($this); + } + + /** @return void */ + public function setupValidations() + { + $this->validations->of(TransactionType::RISK_ASSESS) + ->check('paymentMethod')->isNotNull(); + } +} \ No newline at end of file diff --git a/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php b/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php index 751a52d3..0facf8d3 100644 --- a/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php +++ b/src/Builders/RequestBuilder/GpApi/GpApiAuthorizationRequestBuilder.php @@ -30,6 +30,7 @@ use GlobalPayments\Api\Entities\Product; use GlobalPayments\Api\Mapping\EnumMapping; use GlobalPayments\Api\PaymentMethods\BNPL; +use GlobalPayments\Api\PaymentMethods\Credit; use GlobalPayments\Api\PaymentMethods\CreditCardData; use GlobalPayments\Api\PaymentMethods\CreditTrackData; use GlobalPayments\Api\PaymentMethods\DebitTrackData; @@ -192,7 +193,10 @@ private function createFromAuthorizationBuilder($builder, GpApiConfig $config) $requestBody['currency'] = $builder->currency; $requestBody['reference'] = !empty($builder->clientTransactionId) ? $builder->clientTransactionId : GenerationUtils::getGuid(); - if ($builder->paymentMethod->mobileType == EncyptedMobileType::CLICK_TO_PAY) { + if ( + $builder->paymentMethod instanceof Credit && + $builder->paymentMethod->mobileType == EncyptedMobileType::CLICK_TO_PAY + ) { $requestBody['masked'] = $builder->maskedDataResponse === true ? 'YES' : 'NO'; } $requestBody['description'] = $builder->description; diff --git a/src/Builders/RequestBuilder/GpApi/GpApiSecure3DRequestBuilder.php b/src/Builders/RequestBuilder/GpApi/GpApiSecure3DRequestBuilder.php deleted file mode 100644 index 00262d45..00000000 --- a/src/Builders/RequestBuilder/GpApi/GpApiSecure3DRequestBuilder.php +++ /dev/null @@ -1,301 +0,0 @@ -builder = $builder; - $requestData = null; - - switch ($builder->transactionType) - { - case TransactionType::VERIFY_ENROLLED: - $verb = 'POST'; - $endpoint = GpApiRequest::AUTHENTICATIONS_ENDPOINT; - $requestData = $this->verifyEnrolled($builder, $config); - break; - case TransactionType::INITIATE_AUTHENTICATION: - $verb = 'POST'; - $endpoint = GpApiRequest::AUTHENTICATIONS_ENDPOINT . "/{$builder->getServerTransactionId()}/initiate"; - $requestData = $this->initiateAuthenticationData($builder, $config); - break; - case TransactionType::VERIFY_SIGNATURE: - $verb = 'POST'; - $endpoint = GpApiRequest::AUTHENTICATIONS_ENDPOINT . "/{$builder->getServerTransactionId()}/result"; - if (!empty($builder->getPayerAuthenticationResponse())) { - $requestData['three_ds'] = [ - 'challenge_result_value' => $builder->getPayerAuthenticationResponse() - ]; - } - break; - default: - return null; - } - - return new GpApiRequest( - $endpoint, - $verb, - $requestData - ); - } - - private function verifyEnrolled(Secure3dBuilder $builder, GpApiConfig $config) - { - $threeDS = []; - $threeDS['account_name'] = $config->accessTokenInfo->transactionProcessingAccountName; - $threeDS['channel'] = $config->channel; - $threeDS['country'] = $config->country; - $threeDS['reference'] = !empty($builder->referenceNumber) ? $builder->referenceNumber : GenerationUtils::getGuid(); - $threeDS['amount'] = StringUtils::toNumeric($builder->amount); - $threeDS['currency'] = $builder->currency; - $threeDS['preference'] = $builder->challengeRequestIndicator; - $threeDS['source'] = (string) $builder->authenticationSource; - $threeDS['payment_method'] = $this->setPaymentMethodParam($builder->paymentMethod); - $threeDS['notifications'] = [ - 'challenge_return_url' => $config->challengeNotificationUrl, - 'three_ds_method_return_url' => $config->methodNotificationUrl, - 'decoupled_notification_url' => $builder->decoupledNotificationUrl ?? null - ]; - if (!empty($builder->storedCredential)) { - $this->setStoreCredentialParam($builder->storedCredential, $threeDS); - } - - return $threeDS; - } - - private function initiateAuthenticationData(Secure3dBuilder $builder, GpApiConfig $config) - { - $threeDS['three_ds'] = [ - 'source' => (string) $builder->authenticationSource, - 'preference' => $builder->challengeRequestIndicator, - 'message_version' => $builder->threeDSecure->messageVersion, - 'message_category' => EnumMapping::mapMessageCategory(GatewayProvider::GP_API, $builder->messageCategory) - ]; - - if (!empty($builder->storedCredential)) { - $this->setStoreCredentialParam($builder->storedCredential, $threeDS); - } - $threeDS['method_url_completion_status'] = (string) $builder->methodUrlCompletion; - $threeDS['merchant_contact_url'] = $config->merchantContactUrl; - $threeDS['order'] = $this->setOrderParam(); - $threeDS['payment_method'] = $this->setPaymentMethodParam($builder->paymentMethod); - $threeDS['payer'] = [ - 'reference' => $builder->customerAccountId, - 'account_age' => (string) $builder->accountAgeIndicator, - 'account_creation_date' => !empty($builder->accountCreateDate) ? - (new \DateTime($builder->accountCreateDate))->format('Y-m-d') : null, - 'account_change_date' => !empty($builder->accountChangeDate) ? - (new \DateTime($builder->accountChangeDate))->format('Y-m-d') : null, - 'account_change_indicator' => (string) $builder->accountChangeIndicator, - 'account_password_change_date' => !empty($builder->passwordChangeDate) ? - (new \DateTime($builder->passwordChangeDate))->format('Y-m-d') : null, - 'account_password_change_indicator' => (string) $builder->passwordChangeIndicator, - 'home_phone' => [ - 'country_code' => $builder->homeCountryCode, - 'subscriber_number' => $builder->homeNumber - ], - 'work_phone' => [ - 'country_code' => $builder->workCountryCode, - 'subscriber_number' => $builder->workNumber - ], - 'mobile_phone' => [ - 'country_code' => $builder->mobileCountryCode, - 'subscriber_number' => $builder->mobileNumber - ], - 'payment_account_creation_date' => !empty($builder->paymentAccountCreateDate) ? - (new \DateTime($builder->paymentAccountCreateDate))->format('Y-m-d') : null, - 'payment_account_age_indicator' => (string) $builder->paymentAgeIndicator, - 'suspicious_account_activity' => $builder->previousSuspiciousActivity, - 'purchases_last_6months_count' => $builder->numberOfPurchasesInLastSixMonths, - 'transactions_last_24hours_count' => $builder->numberOfTransactionsInLast24Hours, - 'transaction_last_year_count' => $builder->numberOfTransactionsInLastYear, - 'provision_attempt_last_24hours_count' => $builder->numberOfAddCardAttemptsInLast24Hours, - 'shipping_address_time_created_reference' => !empty($builder->shippingAddressCreateDate) ? - (new \DateTime($builder->shippingAddressCreateDate))->format('Y-m-d') : null, - 'shipping_address_creation_indicator' => (string) $builder->shippingAddressUsageIndicator - ]; - if (!empty($builder->billingAddress)) { - $threeDS['payer']['billing_address'] = [ - 'line1' => $builder->billingAddress->streetAddress1, - 'line2' => $builder->billingAddress->streetAddress2, - 'line3' => $builder->billingAddress->streetAddress3, - 'city' => $builder->billingAddress->city, - 'postal_code' => $builder->billingAddress->postalCode, - 'state' => $builder->billingAddress->state, - 'country' => CountryUtils::getNumericCodeByCountry($builder->billingAddress->countryCode) - ]; - } - - $threeDS['payer_prior_three_ds_authentication_data'] = [ - 'authentication_method' => (string) $builder->priorAuthenticationMethod, - 'acs_transaction_reference' => $builder->priorAuthenticationTransactionId, - 'authentication_timestamp' => !empty($builder->priorAuthenticationTimestamp) ? - (new \DateTime($builder->priorAuthenticationTimestamp))->format('Y-m-d\TH:i:s.u\Z') : null, - 'authentication_data' => $builder->priorAuthenticationData - ]; - - $threeDS['recurring_authorization_data'] = [ - 'max_number_of_instalments' => $builder->maxNumberOfInstallments, - 'frequency' => $builder->recurringAuthorizationFrequency, - 'expiry_date' => $builder->recurringAuthorizationExpiryDate - ]; - - $threeDS['payer_login_data'] = [ - 'authentication_data' => $builder->customerAuthenticationData, - 'authentication_timestamp' => !empty($builder->customerAuthenticationTimestamp) ? - (new \DateTime($builder->customerAuthenticationTimestamp))->format('Y-m-d\TH:i:s.u\Z') : null, - 'authentication_type' => (string) $builder->customerAuthenticationMethod - ]; - - if (!empty($builder->browserData) && $builder->authenticationSource != AuthenticationSource::MOBILE_SDK) { - $threeDS['browser_data'] = [ - 'accept_header' => $builder->browserData->acceptHeader, - 'color_depth' => (string) $builder->browserData->colorDepth, - 'ip' => $builder->browserData->ipAddress, - 'java_enabled' => $builder->browserData->javaEnabled, - 'javascript_enabled' => $builder->browserData->javaScriptEnabled, - 'language' => $builder->browserData->language, - 'screen_height' => $builder->browserData->screenHeight, - 'screen_width' => $builder->browserData->screenWidth, - 'challenge_window_size' => (string) $builder->browserData->challengWindowSize, - 'timezone' => (string) $builder->browserData->timeZone, - 'user_agent' => $builder->browserData->userAgent - ]; - } - if (!empty($builder->mobileData) && $builder->authenticationSource == AuthenticationSource::MOBILE_SDK) { - $threeDS['mobile_data'] = [ - 'encoded_data' => $builder->mobileData->encodedData, - 'application_reference' => $builder->mobileData->applicationReference, - 'sdk_interface' => $builder->mobileData->sdkInterface, - 'sdk_ui_type' => EnumMapping::mapSdkUiType(GatewayProvider::GP_API, $builder->mobileData->sdkUiTypes), - 'ephemeral_public_key' => json_decode($builder->mobileData->ephemeralPublicKey), - 'maximum_timeout' => $builder->mobileData->maximumTimeout, - 'reference_number' => $builder->mobileData->referenceNumber, - 'sdk_trans_reference' => $builder->mobileData->sdkTransReference - ]; - } - $threeDS['notifications'] = [ - 'decoupled_notification_url' => $builder->decoupledNotificationUrl ?? null - ]; - if (isset($builder->decoupledFlowRequest)) { - $threeDS['decoupled_flow_request'] = $builder->decoupledFlowRequest === true ? DecoupledFlowRequest::DECOUPLED_PREFERRED : - DecoupledFlowRequest::DO_NOT_USE_DECOUPLED; - } - $threeDS['decoupled_flow_timeout'] = $builder->decoupledFlowTimeout ?? null; - - return $threeDS; - } - - private function setPaymentMethodParam($cardData) - { - $paymentMethod = new PaymentMethod(); - if ($cardData instanceof ITokenizable && !empty($cardData->token)) { - $paymentMethod->id = $cardData->token; - - } - if ($cardData instanceof ICardData) { - $paymentMethod->card = (object) [ - 'number' => $cardData->number, - 'expiry_month' => !empty($cardData->expMonth) ? $cardData->expMonth : '', - 'expiry_year' => !empty($cardData->expYear) ? - substr(str_pad($cardData->expYear, 4, '0', STR_PAD_LEFT), 2, 2) : '' - ];; - } - $paymentMethod->name = !empty($cardData->cardHolderName) ? $cardData->cardHolderName : null; - - return $paymentMethod; - } - - /** - * Set the order parameter in the request - * - * @return array - */ - private function setOrderParam() - { - $order = [ - 'time_created_reference' => !empty($this->builder->orderCreateDate) ? - (new \DateTime($this->builder->orderCreateDate))->format('Y-m-d\TH:i:s.u\Z') : null, - 'amount' => StringUtils::toNumeric($this->builder->amount), - 'currency' => $this->builder->currency, - 'reference' => $this->builder->referenceNumber, - 'address_match_indicator' => $this->builder->isAddressMatchIndicator(), - 'gift_card_count' => $this->builder->giftCardCount, - 'gift_card_currency'=> $this->builder->giftCardCurrency, - 'gift_card_amount' => $this->builder->giftCardAmount, - 'delivery_email' => $this->builder->deliveryEmail, - 'delivery_timeframe' => $this->builder->deliveryTimeframe, - 'shipping_method' => (string) $this->builder->shippingMethod, - 'shipping_name_matches_cardholder_name' => $this->builder->getShippingNameMatchesCardHolderName(), - 'preorder_indicator' => (string) $this->builder->preOrderIndicator, - 'preorder_availability_date' => !empty($this->builder->preOrderAvailabilityDate) ? - (new \DateTime($this->builder->preOrderAvailabilityDate))->format('Y-m-d') : null, - 'reorder_indicator' => (string) $this->builder->reorderIndicator, - 'transaction_type' => $this->builder->orderTransactionType - ]; - - if (!empty($this->builder->shippingAddress)) { - $order['shipping_address'] = [ - 'line1' => $this->builder->shippingAddress->streetAddress1, - 'line2' => $this->builder->shippingAddress->streetAddress2, - 'line3' => $this->builder->shippingAddress->streetAddress3, - 'city' => $this->builder->shippingAddress->city, - 'postal_code' => $this->builder->shippingAddress->postalCode, - 'state' => $this->builder->shippingAddress->state, - 'country' => CountryUtils::getNumericCodeByCountry($this->builder->shippingAddress->countryCode) - ]; - } - - return $order; - } - - - /** - * Set the stored credential details in the request - * - * @param StoredCredential $storedCredential - * @param array $threeDS - */ - private function setStoreCredentialParam($storedCredential, &$threeDS) - { - $initiator = EnumMapping::mapStoredCredentialInitiator(GatewayProvider::GP_API, $storedCredential->initiator); - $threeDS['initiator'] = !empty($initiator) ? $initiator : null; - $threeDS['stored_credential'] = [ - 'model' => strtoupper($storedCredential->type), - 'reason' => strtoupper($storedCredential->reason), - 'sequence' => strtoupper($storedCredential->sequence) - ]; - } -} \ No newline at end of file diff --git a/src/Builders/RequestBuilder/GpApi/GpApiSecureRequestBuilder.php b/src/Builders/RequestBuilder/GpApi/GpApiSecureRequestBuilder.php new file mode 100644 index 00000000..bda423d1 --- /dev/null +++ b/src/Builders/RequestBuilder/GpApi/GpApiSecureRequestBuilder.php @@ -0,0 +1,361 @@ +builder = $builder; + $requestData = null; + switch ($builder->transactionType) + { + case TransactionType::VERIFY_ENROLLED: + $verb = 'POST'; + $endpoint = GpApiRequest::AUTHENTICATIONS_ENDPOINT; + $requestData = $this->verifyEnrolled($builder, $config); + break; + case TransactionType::INITIATE_AUTHENTICATION: + $verb = 'POST'; + $endpoint = GpApiRequest::AUTHENTICATIONS_ENDPOINT . "/{$builder->getServerTransactionId()}/initiate"; + $requestData = $this->initiateAuthenticationData($builder, $config); + break; + case TransactionType::VERIFY_SIGNATURE: + $verb = 'POST'; + $endpoint = GpApiRequest::AUTHENTICATIONS_ENDPOINT . "/{$builder->getServerTransactionId()}/result"; + if (!empty($builder->getPayerAuthenticationResponse())) { + $requestData['three_ds'] = [ + 'challenge_result_value' => $builder->getPayerAuthenticationResponse() + ]; + } + break; + case TransactionType::RISK_ASSESS: + $verb = 'POST'; + $endpoint = GpApiRequest::RISK_ASSESSMENTS; + $requestData['account_name'] = $config->accessTokenInfo->riskAssessmentAccountName; + $requestData['reference'] = !empty($builder->getReferenceNumber()) ? + $builder->getReferenceNumber() : GenerationUtils::getGuid(); + $requestData['source'] = $builder->getAuthenticationSource(); + $requestData['merchant_contact_url'] = $config->merchantContactUrl; + $requestData['order'] = $this->setOrderParam(); + if (!empty($this->builder->getShippingAddress())) { + $requestData['order']['shipping_address']['country'] = + CountryUtils::getCountryCodeByCountry($this->builder->getShippingAddress()->countryCode); + } + $requestData['payment_method'] = $this->setPaymentMethodParam($builder->paymentMethod); + $requestData['payer'] = $this->setPayerParam(); + $requestData['payer_prior_three_ds_authentication_data'] = $this->setPayerPrior3DSAuthenticationDataParam(); + $requestData['recurring_authorization_data'] = $this->setRecurringAuthorizationDataParam(); + $requestData['payer_login_data'] = $this->setPayerLoginDataParam(); + $requestData['browser_data'] = $this->setBrowserDataParam($builder->getBrowserData()); + break; + default: + throw new UnsupportedTransactionException( + sprintf("Your current gateway does not %s transaction type.", $builder->transactionType) + ); + } + + return new GpApiRequest( + $endpoint, + $verb, + $requestData + ); + } + + private function verifyEnrolled(Secure3dBuilder $builder, GpApiConfig $config) + { + $threeDS = []; + $threeDS['account_name'] = $config->accessTokenInfo->transactionProcessingAccountName; + $threeDS['channel'] = $config->channel; + $threeDS['country'] = $config->country; + $threeDS['reference'] = !empty($builder->getReferenceNumber()) ? + $builder->getReferenceNumber() : GenerationUtils::getGuid(); + $threeDS['amount'] = StringUtils::toNumeric($builder->getAmount()); + $threeDS['currency'] = $builder->getCurrency(); + $threeDS['preference'] = $builder->challengeRequestIndicator; + $threeDS['source'] = (string) $builder->getAuthenticationSource(); + $threeDS['payment_method'] = $this->setPaymentMethodParam($builder->paymentMethod); + $threeDS['notifications'] = [ + 'challenge_return_url' => $config->challengeNotificationUrl, + 'three_ds_method_return_url' => $config->methodNotificationUrl, + 'decoupled_notification_url' => $builder->decoupledNotificationUrl ?? null + ]; + if (!empty($builder->storedCredential)) { + $this->setStoreCredentialParam($builder->storedCredential, $threeDS); + } + + return $threeDS; + } + + private function initiateAuthenticationData(Secure3dBuilder $builder, GpApiConfig $config) + { + $threeDS['three_ds'] = [ + 'source' => (string) $builder->getAuthenticationSource(), + 'preference' => $builder->challengeRequestIndicator, + 'message_version' => $builder->threeDSecure->messageVersion, + 'message_category' => EnumMapping::mapMessageCategory(GatewayProvider::GP_API, $builder->messageCategory) + ]; + + if (!empty($builder->storedCredential)) { + $this->setStoreCredentialParam($builder->storedCredential, $threeDS); + } + $threeDS['method_url_completion_status'] = (string) $builder->methodUrlCompletion; + $threeDS['merchant_contact_url'] = $config->merchantContactUrl; + $threeDS['order'] = $this->setOrderParam(); + $threeDS['payment_method'] = $this->setPaymentMethodParam($builder->paymentMethod); + $threeDS['payer'] = $this->setPayerParam(); + if (!empty($builder->billingAddress)) { + $threeDS['payer']['billing_address'] = [ + 'line1' => $builder->billingAddress->streetAddress1, + 'line2' => $builder->billingAddress->streetAddress2, + 'line3' => $builder->billingAddress->streetAddress3, + 'city' => $builder->billingAddress->city, + 'postal_code' => $builder->billingAddress->postalCode, + 'state' => $builder->billingAddress->state, + 'country' => CountryUtils::getNumericCodeByCountry($builder->billingAddress->countryCode) + ]; + } + + $threeDS['payer_prior_three_ds_authentication_data'] = $this->setPayerPrior3DSAuthenticationDataParam(); + $threeDS['recurring_authorization_data'] = $this->setRecurringAuthorizationDataParam(); + $threeDS['payer_login_data'] = $this->setPayerLoginDataParam(); + + if (!empty($builder->getBrowserData()) && $builder->getAuthenticationSource() != AuthenticationSource::MOBILE_SDK) { + $threeDS['browser_data'] = $this->setBrowserDataParam($builder->getBrowserData()); + } + if (!empty($builder->mobileData) && $builder->getAuthenticationSource() == AuthenticationSource::MOBILE_SDK) { + $threeDS['mobile_data'] = [ + 'encoded_data' => $builder->mobileData->encodedData, + 'application_reference' => $builder->mobileData->applicationReference, + 'sdk_interface' => $builder->mobileData->sdkInterface, + 'sdk_ui_type' => EnumMapping::mapSdkUiType(GatewayProvider::GP_API, $builder->mobileData->sdkUiTypes), + 'ephemeral_public_key' => json_decode($builder->mobileData->ephemeralPublicKey), + 'maximum_timeout' => $builder->mobileData->maximumTimeout, + 'reference_number' => $builder->mobileData->referenceNumber, + 'sdk_trans_reference' => $builder->mobileData->sdkTransReference + ]; + } + $threeDS['notifications'] = [ + 'decoupled_notification_url' => $builder->decoupledNotificationUrl ?? null + ]; + if (isset($builder->decoupledFlowRequest)) { + $threeDS['decoupled_flow_request'] = $builder->decoupledFlowRequest === true ? DecoupledFlowRequest::DECOUPLED_PREFERRED : + DecoupledFlowRequest::DO_NOT_USE_DECOUPLED; + } + $threeDS['decoupled_flow_timeout'] = $builder->decoupledFlowTimeout ?? null; + + return $threeDS; + } + + private function setPaymentMethodParam($cardData) + { + $paymentMethod = new PaymentMethod(); + if ($cardData instanceof ITokenizable && !empty($cardData->token)) { + $paymentMethod->id = $cardData->token; + + } + if ($cardData instanceof ICardData) { + $paymentMethod->card = (object) [ + 'brand' => strtoupper($cardData->getCardType()), + 'number' => $cardData->number, + 'expiry_month' => !empty($cardData->expMonth) ? $cardData->expMonth : '', + 'expiry_year' => !empty($cardData->expYear) ? + substr(str_pad($cardData->expYear, 4, '0', STR_PAD_LEFT), 2, 2) : '' + ];; + $paymentMethod->name = !empty($cardData->cardHolderName) ? $cardData->cardHolderName : null; + } + + + return $paymentMethod; + } + + /** + * Set the order parameter in the request + * + * @return array + */ + private function setOrderParam() + { + $order = [ + 'time_created_reference' => !empty($this->builder->getOrderCreateDate()) ? + (new \DateTime($this->builder->getOrderCreateDate()))->format('Y-m-d\TH:i:s.u\Z') : null, + 'amount' => StringUtils::toNumeric($this->builder->getAmount()), + 'currency' => $this->builder->getCurrency(), + 'reference' => $this->builder->getOrderId() ?? GenerationUtils::getGuid(), + 'address_match_indicator' => StringUtils::boolToString($this->builder->isAddressMatchIndicator()), + 'gift_card_count' => $this->builder->getGiftCardCount(), + 'gift_card_currency'=> $this->builder->getGiftCardCurrency(), + 'gift_card_amount' => $this->builder->getGiftCardAmount(), + 'delivery_email' => $this->builder->getDeliveryEmail(), + 'delivery_timeframe' => $this->builder->getDeliveryTimeframe(), + 'shipping_method' => (string) $this->builder->getShippingMethod(), + 'shipping_name_matches_cardholder_name' => StringUtils::boolToString( + $this->builder->getShippingNameMatchesCardHolderName() + ), + 'preorder_indicator' => (string) $this->builder->getPreOrderIndicator(), + 'preorder_availability_date' => !empty($this->builder->getPreOrderAvailabilityDate()) ? + (new \DateTime($this->builder->getPreOrderAvailabilityDate()))->format('Y-m-d') : null, +// 'reorder_indicator' => (string) $this->builder->getReorderIndicator(), + 'category' => $this->builder->getOrderTransactionType() + ]; + + if (!empty($this->builder->getShippingAddress())) { + $shippingAddress = $this->builder->getShippingAddress(); + $order['shipping_address'] = [ + 'line1' => $shippingAddress->streetAddress1, + 'line2' => $shippingAddress->streetAddress2, + 'line3' => $shippingAddress->streetAddress3, + 'city' => $shippingAddress->city, + 'postal_code' => $shippingAddress->postalCode, + 'state' => $shippingAddress->state, + 'country' => CountryUtils::getNumericCodeByCountry($shippingAddress->countryCode) + ]; + } + + return $order; + } + + + /** + * Set the stored credential details in the request + * + * @param StoredCredential $storedCredential + * @param array $threeDS + */ + private function setStoreCredentialParam($storedCredential, &$threeDS) + { + $initiator = EnumMapping::mapStoredCredentialInitiator(GatewayProvider::GP_API, $storedCredential->initiator); + $threeDS['initiator'] = !empty($initiator) ? $initiator : null; + $threeDS['stored_credential'] = [ + 'model' => strtoupper($storedCredential->type), + 'reason' => strtoupper($storedCredential->reason), + 'sequence' => strtoupper($storedCredential->sequence) + ]; + } + + private function setPayerParam() + { + return[ + 'reference' => $this->builder->getCustomerAccountId(), + 'account_age' => (string) $this->builder->getAccountAgeIndicator(), + 'account_creation_date' => !empty($this->builder->getAccountCreateDate()) ? + (new \DateTime($this->builder->getAccountCreateDate()))->format('Y-m-d') : null, + 'account_change_date' => !empty($this->builder->getAccountChangeDate()) ? + (new \DateTime($this->builder->getAccountChangeDate()))->format('Y-m-d') : null, + 'account_change_indicator' => (string) $this->builder->getAccountChangeIndicator(), + 'account_password_change_date' => !empty($this->builder->getPasswordChangeDate()) ? + (new \DateTime($this->builder->getPasswordChangeDate()))->format('Y-m-d') : null, + 'account_password_change_indicator' => (string) $this->builder->getPasswordChangeIndicator(), + 'home_phone' => [ + 'country_code' => $this->builder->getHomeCountryCode(), + 'subscriber_number' => $this->builder->getHomeNumber() + ], + 'work_phone' => [ + 'country_code' => $this->builder->getWorkCountryCode(), + 'subscriber_number' => $this->builder->getWorkNumber() + ], + 'mobile_phone' => [ + 'country_code' => $this->builder->getMobileCountryCode(), + 'subscriber_number' => $this->builder->getMobileNumber() + ], + 'payment_account_creation_date' => !empty($this->builder->getPaymentAccountCreateDate()) ? + (new \DateTime($this->builder->getPaymentAccountCreateDate()))->format('Y-m-d') : null, + 'payment_account_age_indicator' => (string) $this->builder->getPaymentAgeIndicator(), + 'suspicious_account_activity' => StringUtils::boolToString($this->builder->getPreviousSuspiciousActivity()), + 'purchases_last_6months_count' => str_pad($this->builder->getNumberOfPurchasesInLastSixMonths(), 2, '0', STR_PAD_LEFT), + 'transactions_last_24hours_count' => str_pad($this->builder->getNumberOfTransactionsInLast24Hours(), 2, '0', STR_PAD_LEFT), + 'transaction_last_year_count' => str_pad($this->builder->getNumberOfTransactionsInLastYear(), 2, '0', STR_PAD_LEFT), + 'provision_attempt_last_24hours_count' => str_pad($this->builder->getNumberOfAddCardAttemptsInLast24Hours(), 2, '0', STR_PAD_LEFT), + 'shipping_address_time_created_reference' => !empty($this->builder->getShippingAddressCreateDate()) ? + (new \DateTime($this->builder->getShippingAddressCreateDate()))->format('Y-m-d\TH:i:s') : null, + 'shipping_address_creation_indicator' => (string) $this->builder->getShippingAddressUsageIndicator() + ]; + } + + private function setBrowserDataParam($browserData) + { + if (empty($browserData)) { + return; + } + + return [ + 'accept_header' => $browserData->acceptHeader, + 'color_depth' => (string) $browserData->colorDepth, + 'ip' => $browserData->ipAddress, + 'java_enabled' => StringUtils::boolToString($browserData->javaEnabled), + 'javascript_enabled' => StringUtils::boolToString($browserData->javaScriptEnabled), + 'language' => $browserData->language, + 'screen_height' => $browserData->screenHeight, + 'screen_width' => $browserData->screenWidth, + 'challenge_window_size' => (string) $browserData->challengWindowSize, + 'timezone' => (string) $browserData->timeZone, + 'user_agent' => $browserData->userAgent + ]; + } + + private function setPayerPrior3DSAuthenticationDataParam() + { + return [ + 'authentication_method' => (string) $this->builder->getPriorAuthenticationMethod(), + 'acs_transaction_reference' => $this->builder->getPriorAuthenticationTransactionId(), + 'authentication_timestamp' => !empty($this->builder->getPriorAuthenticationTimestamp()) ? + (new \DateTime($this->builder->getPriorAuthenticationTimestamp()))->format('Y-m-d\TH:i:s.u\Z') : null, + 'authentication_data' => $this->builder->getPriorAuthenticationData() + ]; + } + + private function setRecurringAuthorizationDataParam() + { + return [ + 'max_number_of_instalments' => str_pad($this->builder->getMaxNumberOfInstallments(), 2, '0', STR_PAD_LEFT), + 'frequency' => $this->builder->getRecurringAuthorizationFrequency(), + 'expiry_date' => $this->builder->getRecurringAuthorizationExpiryDate() + ]; + } + + private function setPayerLoginDataParam() + { + return [ + 'authentication_data' => $this->builder->getCustomerAuthenticationData(), + 'authentication_timestamp' => !empty($this->builder->getCustomerAuthenticationTimestamp()) ? + (new \DateTime($this->builder->getCustomerAuthenticationTimestamp()))->format('Y-m-d\TH:i:s.u\Z') : null, + 'authentication_type' => (string) $this->builder->getCustomerAuthenticationMethod() + ]; + } +} \ No newline at end of file diff --git a/src/Builders/RequestBuilder/RequestBuilderFactory.php b/src/Builders/RequestBuilder/RequestBuilderFactory.php index d132cf86..08a057d6 100644 --- a/src/Builders/RequestBuilder/RequestBuilderFactory.php +++ b/src/Builders/RequestBuilder/RequestBuilderFactory.php @@ -8,7 +8,8 @@ GpApiManagementRequestBuilder, GpApiPayFacRequestBuilder, GpApiReportRequestBuilder, - GpApiSecure3DRequestBuilder}; + GpApiSecureRequestBuilder +}; use GlobalPayments\Api\Builders\RequestBuilder\GpEcom\{ GpEcomAuthorizationRequestBuilder, GpEcomManagementRequestBuilder, @@ -20,6 +21,7 @@ TransactionApiManagementRequestBuilder, TransactionApiAuthorizationRequestBuilder }; + use GlobalPayments\Api\Entities\Enums\GatewayProvider; class RequestBuilderFactory @@ -35,7 +37,7 @@ class RequestBuilderFactory GpApiAuthorizationRequestBuilder::class, GpApiManagementRequestBuilder::class, GpApiReportRequestBuilder::class, - GpApiSecure3DRequestBuilder::class, + GpApiSecureRequestBuilder::class, GpApiPayFacRequestBuilder::class ], GatewayProvider::TRANSACTION_API => [ diff --git a/src/Builders/Secure3dBuilder.php b/src/Builders/Secure3dBuilder.php index 25f4fed1..b1083ef7 100644 --- a/src/Builders/Secure3dBuilder.php +++ b/src/Builders/Secure3dBuilder.php @@ -3,7 +3,6 @@ namespace GlobalPayments\Api\Builders; use GlobalPayments\Api\Entities\Enums\DecoupledFlowRequest; -use GlobalPayments\Api\Entities\Enums\WhiteListStatus; use GlobalPayments\Api\Entities\MobileData; use GlobalPayments\Api\Entities\StoredCredential; use GlobalPayments\Api\Gateways\GpApiConnector; @@ -15,10 +14,8 @@ use GlobalPayments\Api\PaymentMethods\Interfaces\IPaymentMethod; use GlobalPayments\Api\PaymentMethods\Interfaces\ISecure3d; use GlobalPayments\Api\Entities\Address; -use GlobalPayments\Api\Entities\BrowserData; use GlobalPayments\Api\Entities\MerchantDataCollection; use GlobalPayments\Api\Entities\ThreeDSecure; -use GlobalPayments\Api\Entities\Enums\AddressType; use GlobalPayments\Api\Entities\Enums\AgeIndicator; use GlobalPayments\Api\Entities\Enums\AuthenticationRequestType; use GlobalPayments\Api\Entities\Enums\AuthenticationSource; @@ -28,43 +25,15 @@ use GlobalPayments\Api\Entities\Enums\TransactionType; use GlobalPayments\Api\Entities\Exceptions\BuilderException; -class Secure3dBuilder extends BaseBuilder +class Secure3dBuilder extends SecureBuilder { - /** @var AgeIndicator */ - public $accountAgeIndicator; - /** @var DateTime */ - public $accountChangeDate; - /** @var DateTime */ - public $accountCreateDate; - /** @var AgeIndicator */ - public $accountChangeIndicator; - /** @var bool */ - public $addressMatchIndicator; - /** @var string|float */ - public $amount; /** @var string */ public $applicationId; - /** @var AuthenticationSource */ - public $authenticationSource; /** @var AuthenticationRequestType */ public $authenticationRequestType; - /** @var Address */ - public $billingAddress; - /** @var BrowserData */ - public $browserData; /** @var ChallengeRequestIndicator */ public $challengeRequestIndicator; /** @var string */ - public $currency; - /** @var string */ - public $customerAccountId; - /** @var string */ - public $customerAuthenticationData; - /** @var CustomerAuthenticationMethod */ - public $customerAuthenticationMethod; - /** @var DateTime */ - public $customerAuthenticationTimestamp; - /** @var string */ public $customerEmail; /** @var DecoupledFlowRequest */ public $decoupledFlowRequest; @@ -73,26 +42,10 @@ class Secure3dBuilder extends BaseBuilder /** @var string */ public $decoupledNotificationUrl; /** @var string */ - public $deliveryEmail; - /** @var DeliveryTimeFrame */ - public $deliveryTimeframe; - /** @var string */ public $encodedData; /** @var string */ public $ephemeralPublicKey; /** @var int */ - public $giftCardCount; - /** @var string */ - public $giftCardCurrency; - /** @var decimal */ - public $giftCardAmount; - /** @var string */ - public $homeCountryCode; - /** @var string */ - public $homeNumber; - /** @var int */ - public $maxNumberOfInstallments; - /** @var int */ public $maximumTimeout; /** @var MerchantDataCollection */ public $merchantData; @@ -105,92 +58,22 @@ class Secure3dBuilder extends BaseBuilder /** @var MethodUrlCompletion */ public $methodUrlCompletion; /** @var string */ - public $mobileCountryCode; - /** @var string */ - public $mobileNumber; - /** @var int */ - public $numberOfAddCardAttemptsInLast24Hours; - /** @var int */ - public $numberOfPurchasesInLastSixMonths; - /** @var int */ - public $numberOfTransactionsInLast24Hours; - /** @var int */ - public $numberOfTransactionsInLastYear; - /** @var DateTime */ - public $orderCreateDate; - /** @var string */ - public $orderId; - /** @var OrderTransactionType */ - public $orderTransactionType; - /** @var DateTime */ - public $passwordChangeDate; - /** @var AgeIndicator */ - public $passwordChangeIndicator; - /** @var DateTime */ - public $paymentAccountCreateDate; - /** @var AgeIndicator */ - public $paymentAgeIndicator; - /** @var string */ public $payerAuthenticationResponse; - /** @var IPaymentMethod */ - public $paymentMethod; - /** @var DateTime */ - public $preOrderAvailabilityDate; - /** @var PreOrderIndicator */ - public $preOrderIndicator; - /** @var bool */ - public $previousSuspiciousActivity; - /** @var string */ - public $priorAuthenticationData; - /** @var PriorAuthenticationMethod */ - public $priorAuthenticationMethod; - /** @var string */ - public $priorAuthenticationTransactionId; - /** @var DateTime */ - public $priorAuthenticationTimestamp; - /** @var DateTime */ - public $recurringAuthorizationExpiryDate; - /** @var int */ - public $recurringAuthorizationFrequency; - /** @var string */ - public $referenceNumber; - /** @var ReorderIndicator */ - public $reorderIndicator; /** @var SdkInterface */ public $sdkInterface; /** @var string */ public $sdkTransactionId; /** @var array */ public $sdkUiTypes; - /** @var Address */ - public $shippingAddress; - /** @var DateTime */ - public $shippingAddressCreateDate; - /** @var AgeIndicator */ - public $shippingAddressUsageIndicator; - /** @var ShippingMethod */ - public $shippingMethod; - /** @var bool */ - public $shippingNameMatchesCardHolderName; /** @var ThreeDSecure */ public $threeDSecure; - /** @var TransactionType */ - public $transactionType; + /** @var TransactionModifier */ public $transactionModifier = TransactionModifier::NONE; // /** @var Secure3dVersion */ // public $version; /** @var string */ public $whitelistStatus; - /** @var string */ - public $workCountryCode; - /** @var string */ - public $workNumber; - - /** - * @var string - */ - public $idempotencyKey; /** * @var bool */ @@ -213,54 +96,12 @@ public function __construct($transactionType) $this->transactionType = $transactionType; } - /** @return AgeIndicator */ - public function getAccountAgeIndicator() - { - return $this->accountAgeIndicator; - } - - /** @return DateTime */ - public function getAccountChangeDate() - { - return $this->accountChangeDate; - } - - /** @return DateTime */ - public function getAccountCreateDate() - { - return $this->accountCreateDate; - } - - /** @return AgeIndicator */ - public function getAccountChangeIndicator() - { - return $this->accountChangeIndicator; - } - - /** @return bool */ - public function isAddressMatchIndicator() - { - return $this->addressMatchIndicator; - } - - /** @return string|float */ - public function getAmount() - { - return $this->amount; - } - /** @return string */ public function getApplicationId() { return $this->applicationId; } - /** @return AuthenticationSource */ - public function getAuthenticationSource() - { - return $this->authenticationSource; - } - /** @return AuthenticationRequestType */ public function getAuthenticationRequestType() { @@ -273,66 +114,18 @@ public function getBillingAddress() return $this->billingAddress; } - /** @return BrowserData */ - public function getBrowserData() - { - return $this->browserData; - } - /** @return string */ public function getChallengeRequestIndicator() { return $this->challengeRequestIndicator; } - /** @return string */ - public function getCurrency() - { - return $this->currency; - } - - /** @return string */ - public function getCustomerAccountId() - { - return $this->customerAccountId; - } - - /** @return string */ - public function getCustomerAuthenticationData() - { - return $this->customerAuthenticationData; - } - - /** @return CustomerAuthenticationMethod */ - public function getCustomerAuthenticationMethod() - { - return $this->customerAuthenticationMethod; - } - - /** @return DateTime */ - public function getCustomerAuthenticationTimestamp() - { - return $this->customerAuthenticationTimestamp; - } - /** @return string */ public function getCustomerEmail() { return $this->customerEmail; } - /** @return string */ - public function getDeliveryEmail() - { - return $this->deliveryEmail; - } - - /** @return DeliveryTimeFrame */ - public function getDeliveryTimeframe() - { - return $this->deliveryTimeframe; - } - /** @return string */ public function getEncodedData() { @@ -345,42 +138,6 @@ public function getEphemeralPublicKey() return $this->ephemeralPublicKey; } - /** @return int */ - public function getGiftCardCount() - { - return $this->giftCardCount; - } - - /** @return string */ - public function getGiftCardCurrency() - { - return $this->giftCardCurrency; - } - - /** @return decimal */ - public function getGiftCardAmount() - { - return $this->giftCardAmount; - } - - /** @return string */ - public function getHomeCountryCode() - { - return $this->homeCountryCode; - } - - /** @return string */ - public function getHomeNumber() - { - return $this->homeNumber; - } - - /** @return int */ - public function getMaxNumberOfInstallments() - { - return $this->maxNumberOfInstallments; - } - /** @return int */ public function getMaximumTimeout() { @@ -417,162 +174,12 @@ public function getMethodUrlCompletion() return $this->methodUrlCompletion; } - /** @return string */ - public function getMobileCountryCode() - { - return $this->mobileCountryCode; - } - - /** @return string */ - public function getMobileNumber() - { - return $this->mobileNumber; - } - - /** @return int */ - public function getNumberOfAddCardAttemptsInLast24Hours() - { - return $this->numberOfAddCardAttemptsInLast24Hours; - } - - /** @return int */ - public function getNumberOfPurchasesInLastSixMonths() - { - return $this->numberOfPurchasesInLastSixMonths; - } - - /** @return int */ - public function getNumberOfTransactionsInLast24Hours() - { - return $this->numberOfTransactionsInLast24Hours; - } - - /** @return int */ - public function getNumberOfTransactionsInLastYear() - { - return $this->numberOfTransactionsInLastYear; - } - - /** @return DateTime */ - public function getOrderCreateDate() - { - return $this->orderCreateDate; - } - - /** @return string */ - public function getOrderId() - { - return $this->orderId; - } - - /** @return OrderTransactionType */ - public function getOrderTransactionType() - { - return $this->orderTransactionType; - } - - /** @return DateTime */ - public function getPasswordChangeDate() - { - return $this->passwordChangeDate; - } - - /** @return AgeIndicator */ - public function getPasswordChangeIndicator() - { - return $this->passwordChangeIndicator; - } - - /** @return DateTime */ - public function getPaymentAccountCreateDate() - { - return $this->paymentAccountCreateDate; - } - - /** @return AgeIndicator */ - public function getPaymentAgeIndicator() - { - return $this->paymentAgeIndicator; - } - /** @return string */ public function getPayerAuthenticationResponse() { return $this->payerAuthenticationResponse; } - /** @return IPaymentMethod */ - public function getPaymentMethod() - { - return $this->paymentMethod; - } - - /** @return DateTime */ - public function getPreOrderAvailabilityDate() - { - return $this->preOrderAvailabilityDate; - } - - /** @return PreOrderIndicator */ - public function getPreOrderIndicator() - { - return $this->preOrderIndicator; - } - - /** @return bool */ - public function getPreviousSuspiciousActivity() - { - return $this->previousSuspiciousActivity; - } - - /** @return string */ - public function getPriorAuthenticationData() - { - return $this->priorAuthenticationData; - } - - /** @return PriorAuthenticationMethod */ - public function getPriorAuthenticationMethod() - { - return $this->priorAuthenticationMethod; - } - - /** @return string */ - public function getPriorAuthenticationTransactionId() - { - return $this->priorAuthenticationTransactionId; - } - - /** @return DateTime */ - public function getPriorAuthenticationTimestamp() - { - return $this->priorAuthenticationTimestamp; - } - - /** @return DateTime */ - public function getRecurringAuthorizationExpiryDate() - { - return $this->recurringAuthorizationExpiryDate; - } - - /** @return int */ - public function getRecurringAuthorizationFrequency() - { - return $this->recurringAuthorizationFrequency; - } - - /** @return string */ - public function getReferenceNumber() - { - return $this->referenceNumber; - } - - /** @return ReorderIndicator */ - public function getReorderIndicator() - { - return $this->reorderIndicator; - } - /** @return SdkInterface */ public function getSdkInterface() { @@ -591,7 +198,9 @@ public function getSdkUiTypes() return $this->sdkUiTypes; } - /** @return string */ + /** + * @return string|null + */ public function getServerTransactionId() { if (!empty($this->threeDSecure)) { @@ -600,36 +209,6 @@ public function getServerTransactionId() return null; } - /** @return Address */ - public function getShippingAddress() - { - return $this->shippingAddress; - } - - /** @return DateTime */ - public function getShippingAddressCreateDate() - { - return $this->shippingAddressCreateDate; - } - - /** @return AgeIndicator */ - public function getShippingAddressUsageIndicator() - { - return $this->shippingAddressUsageIndicator; - } - - /** @return ShippingMethod */ - public function getShippingMethod() - { - return $this->shippingMethod; - } - - /** @return bool */ - public function getShippingNameMatchesCardHolderName() - { - return $this->shippingNameMatchesCardHolderName; - } - /** @return ThreeDSecure */ public function getThreeDSecure() { @@ -683,20 +262,6 @@ public function getWhitelistStatus() return $this->whitelistStatus; } - - - /** @return string */ - public function getWorkCountryCode() - { - return $this->workCountryCode; - } - - /** @return string */ - public function getWorkNumber() - { - return $this->workNumber; - } - // HELPER METHOD FOR THE CONNECTOR /** @return bool */ @@ -706,7 +271,7 @@ public function hasMobileFields() !empty($this->applicationId) || $this->ephemeralPublicKey != null || $this->maximumTimeout != null || - $this->referenceNumber != null || + $this->getReferenceNumber() != null || !empty($this->sdkTransactionId) || !empty($this->encodedData) || $this->sdkInterface != null || @@ -718,10 +283,10 @@ public function hasMobileFields() public function hasPriorAuthenticationData() { return ( - $this->priorAuthenticationMethod != null || - !empty($this->priorAuthenticationTransactionId) || - $this->priorAuthenticationTimestamp != null || - !empty($this->priorAuthenticationData) + $this->getPriorAuthenticationMethod() != null || + !empty($this->getPriorAuthenticationTransactionId()) || + $this->getPriorAuthenticationTimestamp() != null || + !empty($this->getPriorAuthenticationData()) ); } @@ -729,9 +294,9 @@ public function hasPriorAuthenticationData() public function hasRecurringAuthData() { return ( - $this->maxNumberOfInstallments != null || - $this->recurringAuthorizationFrequency != null || - $this->recurringAuthorizationExpiryDate != null + $this->getMaxNumberOfInstallments() != null || + $this->getRecurringAuthorizationFrequency() != null || + $this->getRecurringAuthorizationExpiryDate() != null ); } @@ -739,68 +304,12 @@ public function hasRecurringAuthData() public function hasPayerLoginData() { return ( - !empty($this->customerAuthenticationData) || - $this->customerAuthenticationTimestamp != null || - $this->customerAuthenticationMethod != null + !empty($this->getCustomerAuthenticationData()) || + $this->getCustomerAuthenticationTimestamp() != null || + $this->getCustomerAuthenticationMethod() != null ); } - /** @return Secure3dBuilder */ - public function withAddress(Address $address, $type = AddressType::BILLING) - { - if ($type === AddressType::BILLING) { - $this->billingAddress = $address; - } else { - $this->shippingAddress = $address; - } - return $this; - } - - /** @return Secure3dBuilder */ - public function withAccountAgeIndicator($ageIndicator) - { - $this->accountAgeIndicator = $ageIndicator; - return $this; - } - - /** @return Secure3dBuilder */ - public function withAccountChangeDate($accountChangeDate) - { - $this->accountChangeDate = $accountChangeDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withAccountCreateDate($accountCreateDate) - { - $this->accountCreateDate = $accountCreateDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withAccountChangeIndicator($accountChangeIndicator) - { - $this->accountChangeIndicator = $accountChangeIndicator; - return $this; - } - - /** - * @param bool $value - * @return Secure3dBuilder - */ - public function withAddressMatchIndicator($value) - { - $this->addressMatchIndicator = $value; - return $this; - } - - /** @return Secure3dBuilder */ - public function withAmount($value) - { - $this->amount = $value; - return $this; - } - /** @return Secure3dBuilder */ public function withApplicationId($applicationId) { @@ -808,12 +317,6 @@ public function withApplicationId($applicationId) return $this; } - /** @return Secure3dBuilder */ - public function withAuthenticationSource($value) - { - $this->authenticationSource = $value; - return $this; - } /** @return Secure3dBuilder */ public function withAuthenticationRequestType($value) @@ -822,13 +325,6 @@ public function withAuthenticationRequestType($value) return $this; } - /** @return Secure3dBuilder */ - public function withBrowserData($value) - { - $this->browserData = $value; - return $this; - } - /** @return Secure3dBuilder */ public function withChallengeRequestIndicator($challengeRequestIndicator) { @@ -836,41 +332,6 @@ public function withChallengeRequestIndicator($challengeRequestIndicator) return $this; } - /** @return Secure3dBuilder */ - public function withCustomerAccountId($customerAccountId) - { - $this->customerAccountId = $customerAccountId; - return $this; - } - - /** @return Secure3dBuilder */ - public function withCustomerAuthenticationData($customerAuthenticationData) - { - $this->customerAuthenticationData = $customerAuthenticationData; - return $this; - } - - /** @return Secure3dBuilder */ - public function withCustomerAuthenticationMethod($customerAuthenticationMethod) - { - $this->customerAuthenticationMethod = $customerAuthenticationMethod; - return $this; - } - - /** @return Secure3dBuilder */ - public function withCustomerAuthenticationTimestamp($customerAuthenticationTimestamp) - { - $this->customerAuthenticationTimestamp = $customerAuthenticationTimestamp; - return $this; - } - - /** @return Secure3dBuilder */ - public function withCurrency($value) - { - $this->currency = $value; - return $this; - } - /** @return Secure3dBuilder */ public function withCustomerEmail($value) { @@ -908,20 +369,6 @@ public function withDecoupledNotificationUrl($decoupledNotificationUrl) return $this; } - /** @return Secure3dBuilder */ - public function withDeliveryEmail($deliveryEmail) - { - $this->deliveryEmail = $deliveryEmail; - return $this; - } - - /** @return Secure3dBuilder */ - public function withDeliveryTimeFrame($deliveryTimeframe) - { - $this->deliveryTimeframe = $deliveryTimeframe; - return $this; - } - /** @return Secure3dBuilder */ public function withEncodedData($encodedData) { @@ -936,42 +383,6 @@ public function withEphemeralPublicKey($ephemeralPublicKey) return $this; } - /** @return Secure3dBuilder */ - public function withGiftCardCount($giftCardCount) - { - $this->giftCardCount = $giftCardCount; - return $this; - } - - /** @return Secure3dBuilder */ - public function withGiftCardCurrency($giftCardCurrency) - { - $this->giftCardCurrency = $giftCardCurrency; - return $this; - } - - /** @return Secure3dBuilder */ - public function withGiftCardAmount($giftCardAmount) - { - $this->giftCardAmount = $giftCardAmount; - return $this; - } - - /** @return Secure3dBuilder */ - public function withHomeNumber($countryCode, $number) - { - $this->homeCountryCode = $countryCode; - $this->homeNumber = $number; - return $this; - } - - /** @return Secure3dBuilder */ - public function withMaxNumberOfInstallments($maxNumberOfInstallments) - { - $this->maxNumberOfInstallments = $maxNumberOfInstallments; - return $this; - } - /** @return Secure3dBuilder */ public function withMaximumTimeout($maximumTimeout) { @@ -1020,91 +431,6 @@ public function withMethodUrlCompletion($value) return $this; } - /** @return Secure3dBuilder */ - public function withMobileNumber($countryCode, $number) - { - $this->mobileCountryCode = $countryCode; - $this->mobileNumber = $number; - return $this; - } - - /** @return Secure3dBuilder */ - public function withNumberOfAddCardAttemptsInLast24Hours($numberOfAddCardAttemptsInLast24Hours) - { - $this->numberOfAddCardAttemptsInLast24Hours = $numberOfAddCardAttemptsInLast24Hours; - return $this; - } - - /** @return Secure3dBuilder */ - public function withNumberOfPurchasesInLastSixMonths($numberOfPurchasesInLastSixMonths) - { - $this->numberOfPurchasesInLastSixMonths = $numberOfPurchasesInLastSixMonths; - return $this; - } - - /** @return Secure3dBuilder */ - public function withNumberOfTransactionsInLast24Hours($numberOfTransactionsInLast24Hours) - { - $this->numberOfTransactionsInLast24Hours = $numberOfTransactionsInLast24Hours; - return $this; - } - - /** @return Secure3dBuilder */ - public function withNumberOfTransactionsInLastYear($numberOfTransactionsInLastYear) - { - $this->numberOfTransactionsInLastYear = $numberOfTransactionsInLastYear; - return $this; - } - - /** @return Secure3dBuilder */ - public function withOrderCreateDate($value) - { - $this->orderCreateDate = $value; - return $this; - } - - /** @return Secure3dBuilder */ - public function withOrderId($value) - { - $this->orderId = $value; - return $this; - } - - /** @return Secure3dBuilder */ - public function withOrderTransactionType($orderTransactionType) - { - $this->orderTransactionType = $orderTransactionType; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPasswordChangeDate($passwordChangeDate) - { - $this->passwordChangeDate = $passwordChangeDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPasswordChangeIndicator($passwordChangeIndicator) - { - $this->passwordChangeIndicator = $passwordChangeIndicator; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPaymentAccountCreateDate($paymentAccountCreateDate) - { - $this->paymentAccountCreateDate = $paymentAccountCreateDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPaymentAccountAgeIndicator($paymentAgeIndicator) - { - $this->paymentAgeIndicator = $paymentAgeIndicator; - return $this; - } - /** @return Secure3dBuilder */ public function withPayerAuthenticationResponse($value) { @@ -1113,7 +439,7 @@ public function withPayerAuthenticationResponse($value) } /** @return Secure3dBuilder */ - public function withPaymentMethod($value) + public function withPaymentMethod(?IPaymentMethod $value) { $this->paymentMethod = $value; if ($this->paymentMethod instanceof ISecure3d) { @@ -1125,86 +451,6 @@ public function withPaymentMethod($value) return $this; } - /** @return Secure3dBuilder */ - public function withPreOrderAvailabilityDate($preOrderAvailabilityDate) - { - $this->preOrderAvailabilityDate = $preOrderAvailabilityDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPreOrderIndicator($preOrderIndicator) - { - $this->preOrderIndicator = $preOrderIndicator; - return $this; - } - - /** - * @param bool $previousSuspiciousActivity - * @return Secure3dBuilder - */ - public function withPreviousSuspiciousActivity($previousSuspiciousActivity) - { - $this->previousSuspiciousActivity = $previousSuspiciousActivity; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPriorAuthenticationData($priorAuthenticationData) - { - $this->priorAuthenticationData = $priorAuthenticationData; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPriorAuthenticationMethod($priorAuthenticationMethod) - { - $this->priorAuthenticationMethod = $priorAuthenticationMethod; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPriorAuthenticationTransactionId($priorAuthencitationTransactionId) - { - $this->priorAuthenticationTransactionId = $priorAuthencitationTransactionId; - return $this; - } - - /** @return Secure3dBuilder */ - public function withPriorAuthenticationTimestamp($priorAuthenticationTimestamp) - { - $this->priorAuthenticationTimestamp = $priorAuthenticationTimestamp; - return $this; - } - - /** @return Secure3dBuilder */ - public function withRecurringAuthorizationExpiryDate($recurringAuthorizationExpiryDate) - { - $this->recurringAuthorizationExpiryDate = $recurringAuthorizationExpiryDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withRecurringAuthorizationFrequency($recurringAuthorizationFrequency) - { - $this->recurringAuthorizationFrequency = $recurringAuthorizationFrequency; - return $this; - } - - /** @return Secure3dBuilder */ - public function withReferenceNumber($referenceNumber) - { - $this->referenceNumber = $referenceNumber; - return $this; - } - - /** @return Secure3dBuilder */ - public function withReorderIndicator($reorderIndicator) - { - $this->reorderIndicator = $reorderIndicator; - return $this; - } - /** @return Secure3dBuilder */ public function withSdkInterface($sdkInterface) { @@ -1236,34 +482,6 @@ public function withServerTransactionId($value) return $this; } - /** @return Secure3dBuilder */ - public function withShippingAddressCreateDate($shippingAddressCreateDate) - { - $this->shippingAddressCreateDate = $shippingAddressCreateDate; - return $this; - } - - /** @return Secure3dBuilder */ - public function withShippingAddressUsageIndicator($shippingAddressUsageIndicator) - { - $this->shippingAddressUsageIndicator = $shippingAddressUsageIndicator; - return $this; - } - - /** @return Secure3dBuilder */ - public function withShippingMethod($shippingMethod) - { - $this->shippingMethod = $shippingMethod; - return $this; - } - - /** @return Secure3dBuilder */ - public function withShippingNameMatchesCardHolderName($shippingNameMatchesCardHolderName) - { - $this->shippingNameMatchesCardHolderName = $shippingNameMatchesCardHolderName; - return $this; - } - /** @return Secure3dBuilder */ public function withThreeDSecure(ThreeDSecure $threeDSecure) { @@ -1271,13 +489,6 @@ public function withThreeDSecure(ThreeDSecure $threeDSecure) return $this; } - /** @return Secure3dBuilder */ - public function withTransactionType($transactionType) - { - $this->transactionType = $transactionType; - return $this; - } - /** * @param bool * @return Secure3dBuilder @@ -1292,26 +503,6 @@ public function withWhitelistStatus($whitelistStatus) return $this; } - /** @return Secure3dBuilder */ - public function withWorkNumber($countryCode, $number) - { - $this->workCountryCode = $countryCode; - $this->workNumber = $number; - return $this; - } - - /** - * @param string $value - * - * @return Secure3dBuilder - */ - public function withIdempotencyKey($value) - { - $this->idempotencyKey = $value; - - return $this; - } - /** * @return Secure3dBuilder */ @@ -1418,8 +609,8 @@ public function execute($configName = 'default', $version = Secure3dVersion::ANY if (!empty($response->threeDSecure)) { $rvalue = $response->threeDSecure; if (in_array($rvalue->enrolled, ['True', 'Y', true], true)) { - $rvalue->setAmount($this->amount); - $rvalue->setCurrency($this->currency); + $rvalue->setAmount($this->getAmount()); + $rvalue->setCurrency($this->getCurrency()); $rvalue->setOrderId($response->orderId); $rvalue->setVersion($provider->getVersion()); } elseif ((bool)$canDowngrade) { @@ -1470,7 +661,7 @@ public function setupValidations() $this->validations->of(TransactionType::INITIATE_AUTHENTICATION) ->when('merchantInitiatedRequestType')->isNotNull() ->check('merchantInitiatedRequestType')->isNotEqualTo(AuthenticationRequestType::PAYMENT_TRANSACTION); - + $this->validations->of(TransactionType::INITIATE_AUTHENTICATION) ->when('accountAgeIndicator')->isNotNull() ->check('accountAgeIndicator')->isNotEqualTo(AgeIndicator::NO_CHANGE); diff --git a/src/Builders/SecureBuilder.php b/src/Builders/SecureBuilder.php new file mode 100644 index 00000000..c14dfcfb --- /dev/null +++ b/src/Builders/SecureBuilder.php @@ -0,0 +1,1096 @@ +amount; + } + + /** @return string */ + public function getCurrency() + { + return $this->currency; + } + + /** @return AuthenticationSource */ + public function getAuthenticationSource() + { + return $this->authenticationSource; + } + + /** @return DateTime */ + public function getOrderCreateDate() + { + return $this->orderCreateDate; + } + + /** @return string */ + public function getOrderId() + { + return $this->orderId; + } + + /** @return OrderTransactionType */ + public function getOrderTransactionType() + { + return $this->orderTransactionType; + } + + /** @return string */ + public function getReferenceNumber() + { + return $this->referenceNumber; + } + + + /** @return bool */ + public function isAddressMatchIndicator() + { + return $this->addressMatchIndicator; + } + + /** @return Address */ + public function getShippingAddress() + { + return $this->shippingAddress; + } + + /** @return ShippingMethod */ + public function getShippingMethod() + { + return $this->shippingMethod; + } + + /** @return bool */ + public function getShippingNameMatchesCardHolderName() + { + return $this->shippingNameMatchesCardHolderName; + } + + + /** @return DateTime */ + public function getShippingAddressCreateDate() + { + return $this->shippingAddressCreateDate; + } + + + /** @return AgeIndicator */ + public function getShippingAddressUsageIndicator() + { + return $this->shippingAddressUsageIndicator; + } + + /** @return int */ + public function getGiftCardCount() + { + return $this->giftCardCount; + } + + /** @return string */ + public function getGiftCardCurrency() + { + return $this->giftCardCurrency; + } + + /** @return float */ + public function getGiftCardAmount() + { + return $this->giftCardAmount; + } + + /** @return string */ + public function getDeliveryEmail() + { + return $this->deliveryEmail; + } + + /** @return DeliveryTimeFrame */ + public function getDeliveryTimeframe() + { + return $this->deliveryTimeframe; + } + + /** @return DateTime */ + public function getPreOrderAvailabilityDate() + { + return $this->preOrderAvailabilityDate; + } + + /** @return PreOrderIndicator */ + public function getPreOrderIndicator() + { + return $this->preOrderIndicator; + } + + /** @return ReorderIndicator */ + public function getReorderIndicator() + { + return $this->reorderIndicator; + } + + /** @return string */ + public function getCustomerAccountId() + { + return $this->customerAccountId; + } + + /** @return AgeIndicator */ + public function getAccountAgeIndicator() + { + return $this->accountAgeIndicator; + } + + /** @return DateTime */ + public function getAccountChangeDate() + { + return $this->accountChangeDate; + } + + /** @return DateTime */ + public function getAccountCreateDate() + { + return $this->accountCreateDate; + } + + /** @return AgeIndicator */ + public function getAccountChangeIndicator() + { + return $this->accountChangeIndicator; + } + + + /** @return DateTime */ + public function getPasswordChangeDate() + { + return $this->passwordChangeDate; + } + + /** @return AgeIndicator */ + public function getPasswordChangeIndicator() + { + return $this->passwordChangeIndicator; + } + + + /** @return string */ + public function getHomeCountryCode() + { + return $this->homeCountryCode; + } + + /** @return string */ + public function getHomeNumber() + { + return $this->homeNumber; + } + + /** @return string */ + public function getWorkCountryCode() + { + return $this->workCountryCode; + } + + /** @return string */ + public function getWorkNumber() + { + return $this->workNumber; + } + + + /** @return string */ + public function getMobileCountryCode() + { + return $this->mobileCountryCode; + } + + /** @return string */ + public function getMobileNumber() + { + return $this->mobileNumber; + } + + + /** @return DateTime */ + public function getPaymentAccountCreateDate() + { + return $this->paymentAccountCreateDate; + } + + /** @return AgeIndicator */ + public function getPaymentAgeIndicator() + { + return $this->paymentAgeIndicator; + } + + + /** @return bool */ + public function getPreviousSuspiciousActivity() + { + return $this->previousSuspiciousActivity; + } + + + /** @return int */ + public function getNumberOfPurchasesInLastSixMonths() + { + return $this->numberOfPurchasesInLastSixMonths; + } + + + /** @return int */ + public function getNumberOfTransactionsInLast24Hours() + { + return $this->numberOfTransactionsInLast24Hours; + } + + /** @return int */ + public function getNumberOfAddCardAttemptsInLast24Hours() + { + return $this->numberOfAddCardAttemptsInLast24Hours; + } + + /** @return int */ + public function getNumberOfTransactionsInLastYear() + { + return $this->numberOfTransactionsInLastYear; + } + + + /** @return BrowserData */ + public function getBrowserData() + { + return $this->browserData; + } + + + /** @return string */ + public function getPriorAuthenticationData() + { + return $this->priorAuthenticationData; + } + + /** @return PriorAuthenticationMethod */ + public function getPriorAuthenticationMethod() + { + return $this->priorAuthenticationMethod; + } + + /** @return string */ + public function getPriorAuthenticationTransactionId() + { + return $this->priorAuthenticationTransactionId; + } + + /** @return \DateTime */ + public function getPriorAuthenticationTimestamp() + { + return $this->priorAuthenticationTimestamp; + } + + /** @return int */ + public function getMaxNumberOfInstallments() + { + return $this->maxNumberOfInstallments; + } + + + /** @return \DateTime */ + public function getRecurringAuthorizationExpiryDate() + { + return $this->recurringAuthorizationExpiryDate; + } + + /** @return int */ + public function getRecurringAuthorizationFrequency() + { + return $this->recurringAuthorizationFrequency; + } + + + /** @return string */ + public function getCustomerAuthenticationData() + { + return $this->customerAuthenticationData; + } + + /** @return CustomerAuthenticationMethod */ + public function getCustomerAuthenticationMethod() + { + return $this->customerAuthenticationMethod; + } + + /** @return \DateTime */ + public function getCustomerAuthenticationTimestamp() + { + return $this->customerAuthenticationTimestamp; + } + + /************************************************SETTERS****************************/ + /** + * @param IPaymentMethod $value + * @return $this + */ + abstract public function withPaymentMethod(IPaymentMethod $value); + + + /** + * @param $transactionType + * @return $this + */ + public function withTransactionType($transactionType) + { + $this->transactionType = $transactionType; + return $this; + } + + /** + * @param float|string $value + * @return $this + */ + public function withAmount($value) + { + $this->amount = $value; + return $this; + } + + /** + * @param string $value + * @return $this + */ + public function withCurrency(string $value) + { + $this->currency = $value; + return $this; + } + + /** + * @param AuthenticationSource $value + * @return $this + */ + public function withAuthenticationSource($value) + { + $this->authenticationSource = $value; + return $this; + } + + /** + * @param DateTime $value + * @return $this + */ + public function withOrderCreateDate($value) + { + $this->orderCreateDate = $value; + return $this; + } + + /** + * @param string $referenceNumber + * @return $this + */ + public function withReferenceNumber($referenceNumber) + { + $this->referenceNumber = $referenceNumber; + return $this; + } + + /** + * @param bool $value + * @return $this + */ + public function withAddressMatchIndicator($value) + { + $this->addressMatchIndicator = $value; + return $this; + } + + /** + * @param Address $address + * @param string $type + * @return $this + */ + public function withAddress(Address $address, $type = AddressType::BILLING) + { + if ($type === AddressType::BILLING) { + $this->billingAddress = $address; + } else { + $this->shippingAddress = $address; + } + return $this; + } + + /** + * @param float $giftCardAmount + * @return $this + */ + public function withGiftCardAmount($giftCardAmount) + { + $this->giftCardAmount = $giftCardAmount; + + return $this; + } + + /** + * @param int $giftCardCount + * @return $this + */ + public function withGiftCardCount($giftCardCount) + { + $this->giftCardCount = $giftCardCount; + return $this; + } + + /** + * @param string $giftCardCurrency + * @return $this + */ + public function withGiftCardCurrency($giftCardCurrency) + { + $this->giftCardCurrency = $giftCardCurrency; + return $this; + } + + /** + * @param string $deliveryEmail + * @return $this + */ + public function withDeliveryEmail($deliveryEmail) + { + $this->deliveryEmail = $deliveryEmail; + return $this; + } + + /** + * @param DeliveryTimeFrame $deliveryTimeframe + * @return $this + */ + public function withDeliveryTimeFrame($deliveryTimeframe) + { + $this->deliveryTimeframe = $deliveryTimeframe; + return $this; + } + + /** + * @param ShippingMethod $shippingMethod + * @return $this + */ + public function withShippingMethod($shippingMethod) + { + $this->shippingMethod = $shippingMethod; + return $this; + } + + /** + * @param bool $shippingNameMatchesCardHolderName + * @return $this + */ + public function withShippingNameMatchesCardHolderName($shippingNameMatchesCardHolderName) + { + $this->shippingNameMatchesCardHolderName = $shippingNameMatchesCardHolderName; + return $this; + } + + /** + * @param \DateTime $shippingAddressCreateDate + * @return $this + */ + public function withShippingAddressCreateDate($shippingAddressCreateDate) + { + $this->shippingAddressCreateDate = $shippingAddressCreateDate; + return $this; + } + + /** + * @param $shippingAddressUsageIndicator + * @return $this + */ + public function withShippingAddressUsageIndicator($shippingAddressUsageIndicator) + { + $this->shippingAddressUsageIndicator = $shippingAddressUsageIndicator; + return $this; + } + + /** + * @param $preOrderAvailabilityDate + * @return $this + */ + public function withPreOrderAvailabilityDate($preOrderAvailabilityDate) + { + $this->preOrderAvailabilityDate = $preOrderAvailabilityDate; + return $this; + } + + /** + * @param $preOrderIndicator + * @return $this + */ + public function withPreOrderIndicator($preOrderIndicator) + { + $this->preOrderIndicator = $preOrderIndicator; + return $this; + } + + + /** + * @param ReorderIndicator $reorderIndicator + * @return $this + */ + public function withReorderIndicator($reorderIndicator) + { + $this->reorderIndicator = $reorderIndicator; + return $this; + } + + /** + * @param OrderTransactionType $orderTransactionType + * @return $this + */ + public function withOrderTransactionType($orderTransactionType) + { + $this->orderTransactionType = $orderTransactionType; + return $this; + } + + /** + * @param string $value + * @return $this + */ + public function withOrderId($value) + { + $this->orderId = $value; + return $this; + } + + /** + * @param string $customerAccountId + * @return $this + */ + public function withCustomerAccountId($customerAccountId) + { + $this->customerAccountId = $customerAccountId; + return $this; + } + + /** + * @param AgeIndicator $ageIndicator + * @return $this + */ + public function withAccountAgeIndicator($ageIndicator) + { + $this->accountAgeIndicator = $ageIndicator; + return $this; + } + + /** + * @param DateTime $accountChangeDate + * @return $this + */ + public function withAccountChangeDate($accountChangeDate) + { + $this->accountChangeDate = $accountChangeDate; + return $this; + } + + /** + * @param DateTime $accountCreateDate + * @return $this + */ + public function withAccountCreateDate($accountCreateDate) + { + $this->accountCreateDate = $accountCreateDate; + return $this; + } + + + /** + * @param AgeIndicator $accountChangeIndicator + * @return $this + */ + public function withAccountChangeIndicator($accountChangeIndicator) + { + $this->accountChangeIndicator = $accountChangeIndicator; + return $this; + } + + + /** + * @param DateTime $passwordChangeDate + * @return $this + */ + public function withPasswordChangeDate($passwordChangeDate) + { + $this->passwordChangeDate = $passwordChangeDate; + + return $this; + } + + /** + * @param AgeIndicator $passwordChangeIndicator + * @return $this + */ + public function withPasswordChangeIndicator($passwordChangeIndicator) + { + $this->passwordChangeIndicator = $passwordChangeIndicator; + return $this; + } + + /** + * @param string $phoneCountryCode + * @param string $number + * @param PhoneNumberType $type + * + * @return $this + */ + public function withPhoneNumber($phoneCountryCode, $number, $type) + { + $phoneNumber = new PhoneNumber($phoneCountryCode, $number, $type); + $this->phoneList[$type] = $phoneNumber; + switch ($phoneNumber->type) { + case PhoneNumberType::HOME: + $this->homeNumber = $number; + $this->homeCountryCode = $phoneCountryCode; + break; + case PhoneNumberType::WORK: + $this->workNumber = $number; + $this->workCountryCode = $phoneCountryCode; + break; + case PhoneNumberType::MOBILE: + $this->mobileNumber = $number; + $this->mobileCountryCode = $phoneCountryCode; + break; + default: + break; + } + + return $this; + } + + /** + * @deprecated Will be replaced with method withPhoneNumber($phoneCountryCode, $number, $type) + * @param string $countryCode + * @param string $number + * + * @return $this + */ + public function withHomeNumber($countryCode, $number) + { + $this->homeCountryCode = $countryCode; + $this->homeNumber = $number; + + return $this; + } + + /** + * @deprecated Will be replaced with method withPhoneNumber($phoneCountryCode, $number, $type) + * + * @param string $countryCode + * @param string $number + * @return $this + */ + public function withWorkNumber($countryCode, $number) + { + $this->workCountryCode = $countryCode; + $this->workNumber = $number; + return $this; + } + + /** + * @deprecated Will be replaced with method withPhoneNumber($phoneCountryCode, $number, $type) + * + * @param string $countryCode + * @param string $number + * @return $this + */ + public function withMobileNumber($countryCode, $number) + { + $this->mobileCountryCode = $countryCode; + $this->mobileNumber = $number; + return $this; + } + + /** + * @param $paymentAccountCreateDate + * @return $this + */ + public function withPaymentAccountCreateDate($paymentAccountCreateDate) + { + $this->paymentAccountCreateDate = $paymentAccountCreateDate; + return $this; + } + + /** + * @param AgeIndicator $paymentAgeIndicator + * @return $this + */ + public function withPaymentAccountAgeIndicator($paymentAgeIndicator) + { + $this->paymentAgeIndicator = $paymentAgeIndicator; + return $this; + } + + /** + * @param $previousSuspiciousActivity + * @return $this + */ + public function withPreviousSuspiciousActivity($previousSuspiciousActivity) + { + $this->previousSuspiciousActivity = $previousSuspiciousActivity; + return $this; + } + + /** + * @param string $numberOfPurchasesInLastSixMonths + * @return $this + */ + public function withNumberOfPurchasesInLastSixMonths($numberOfPurchasesInLastSixMonths) + { + $this->numberOfPurchasesInLastSixMonths = $numberOfPurchasesInLastSixMonths; + return $this; + } + + /** + * @param int $numberOfTransactionsInLast24Hours + * @return $this + */ + public function withNumberOfTransactionsInLast24Hours($numberOfTransactionsInLast24Hours) + { + $this->numberOfTransactionsInLast24Hours = $numberOfTransactionsInLast24Hours; + return $this; + } + + /** + * @param int $numberOfAddCardAttemptsInLast24Hours + * @return $this + */ + public function withNumberOfAddCardAttemptsInLast24Hours($numberOfAddCardAttemptsInLast24Hours) + { + $this->numberOfAddCardAttemptsInLast24Hours = $numberOfAddCardAttemptsInLast24Hours; + return $this; + } + + /** + * @param int $numberOfTransactionsInLastYear + * @return $this + */ + public function withNumberOfTransactionsInLastYear($numberOfTransactionsInLastYear) + { + $this->numberOfTransactionsInLastYear = $numberOfTransactionsInLastYear; + return $this; + } + + /** + * @param BrowserData $value + * @return $this + */ + public function withBrowserData($value) + { + $this->browserData = $value; + return $this; + } + + /** + * @param string $priorAuthenticationData + * @return $this + */ + public function withPriorAuthenticationData($priorAuthenticationData) + { + $this->priorAuthenticationData = $priorAuthenticationData; + return $this; + } + + /** + * @param PriorAuthenticationMethod $priorAuthenticationMethod + * @return $this + */ + public function withPriorAuthenticationMethod($priorAuthenticationMethod) + { + $this->priorAuthenticationMethod = $priorAuthenticationMethod; + return $this; + } + + /** + * @param string $priorAuthencitationTransactionId + * @return $this + */ + public function withPriorAuthenticationTransactionId($priorAuthencitationTransactionId) + { + $this->priorAuthenticationTransactionId = $priorAuthencitationTransactionId; + return $this; + } + + /** + * @param \DateTime $priorAuthenticationTimestamp + * @return $this + */ + public function withPriorAuthenticationTimestamp($priorAuthenticationTimestamp) + { + $this->priorAuthenticationTimestamp = $priorAuthenticationTimestamp; + return $this; + } + + /** + * @param int $maxNumberOfInstallments + * @return $this + */ + public function withMaxNumberOfInstallments($maxNumberOfInstallments) + { + $this->maxNumberOfInstallments = $maxNumberOfInstallments; + return $this; + } + + /** + * @param \DateTime $recurringAuthorizationExpiryDate + * @return $this + */ + public function withRecurringAuthorizationExpiryDate($recurringAuthorizationExpiryDate) + { + $this->recurringAuthorizationExpiryDate = $recurringAuthorizationExpiryDate; + return $this; + } + + /** + * @param int $recurringAuthorizationFrequency + * @return $this + */ + public function withRecurringAuthorizationFrequency($recurringAuthorizationFrequency) + { + $this->recurringAuthorizationFrequency = $recurringAuthorizationFrequency; + return $this; + } + + /** + * @param string $customerAuthenticationData + * @return $this + */ + public function withCustomerAuthenticationData($customerAuthenticationData) + { + $this->customerAuthenticationData = $customerAuthenticationData; + return $this; + } + + /** + * @param CustomerAuthenticationMethod $customerAuthenticationMethod + * @return $this + */ + public function withCustomerAuthenticationMethod($customerAuthenticationMethod) + { + $this->customerAuthenticationMethod = $customerAuthenticationMethod; + return $this; + } + + /** + * @param \DateTime $customerAuthenticationTimestamp + * @return $this + */ + public function withCustomerAuthenticationTimestamp($customerAuthenticationTimestamp) + { + $this->customerAuthenticationTimestamp = $customerAuthenticationTimestamp; + return $this; + } + + /** + * @param string $value + * @return SecureBuilder + */ + public function withIdempotencyKey(string $value) + { + $this->idempotencyKey = $value; + + return $this; + } +} \ No newline at end of file diff --git a/src/Builders/TransactionBuilder.php b/src/Builders/TransactionBuilder.php index 6c2bea18..dba23907 100644 --- a/src/Builders/TransactionBuilder.php +++ b/src/Builders/TransactionBuilder.php @@ -2,12 +2,10 @@ namespace GlobalPayments\Api\Builders; -use GlobalPayments\Api\Builders\BaseBuilder\Validations; use GlobalPayments\Api\Entities\Enums\TransactionModifier; -use GlobalPayments\Api\Entities\Exceptions\ArgumentException; +use GlobalPayments\Api\Entities\Enums\TransactionType; use GlobalPayments\Api\Entities\PayLinkData; -use GlobalPayments\Api\Entities\PayLinkResponse; -use GlobalPayments\Api\Entities\Transaction; +use GlobalPayments\Api\PaymentMethods\Interfaces\IPaymentMethod; abstract class TransactionBuilder extends BaseBuilder { @@ -121,7 +119,7 @@ public function __construct($type, $paymentMethod = null) * @internal * @param TransactionType $transactionType Request transaction type * - * @return AuthorizationBuilder + * @return TransactionBuilder */ public function withTransactionType($transactionType) { @@ -135,7 +133,7 @@ public function withTransactionType($transactionType) * @internal * @param TransactionModifier $modifier Request transaction modifier * - * @return AuthorizationBuilder + * @return TransactionBuilder */ public function withModifier($modifier) { @@ -148,7 +146,7 @@ public function withModifier($modifier) * * @param bool $allowDuplicates Request to allow duplicates * - * @return AuthorizationBuilder + * @return TransactionBuilder */ public function withAllowDuplicates($allowDuplicates) { diff --git a/src/ConfiguredServices.php b/src/ConfiguredServices.php index e939f56a..b20e9ace 100644 --- a/src/ConfiguredServices.php +++ b/src/ConfiguredServices.php @@ -7,6 +7,7 @@ use GlobalPayments\Api\Gateways\ISecure3dProvider; use GlobalPayments\Api\Entities\Enums\Secure3dVersion; use GlobalPayments\Api\Gateways\OpenBankingProvider; +use GlobalPayments\Api\Services\FraudService; class ConfiguredServices { @@ -42,6 +43,9 @@ class ConfiguredServices /** @var PayrollConnector */ public $payrollConnector; + /** @var FraudService */ + public $fraudService; + public function __construct() { $this->secure3dProviders = array(); diff --git a/src/Entities/Card.php b/src/Entities/Card.php new file mode 100644 index 00000000..53ee9fe1 --- /dev/null +++ b/src/Entities/Card.php @@ -0,0 +1,48 @@ +getAccountName(self::TRANSACTION_PROCESSING_ACCOUNT_NAME_PREFIX); } + public function getRiskAssessmentAccountName() + { + return $this->getAccountName(self::RIKS_ASSESSMENT_ACCOUNT_NAME_PREFIX); + } + public function getToken() { return $this->token; diff --git a/src/Entities/RiskAssessment.php b/src/Entities/RiskAssessment.php new file mode 100644 index 00000000..cac61da9 --- /dev/null +++ b/src/Entities/RiskAssessment.php @@ -0,0 +1,96 @@ +sessionDataFieldName = $this->mergeValue($this->sessionDataFieldName, $secureEcom->sessionDataFieldName); $this->challengeReturnUrl = $this->mergeValue($this->challengeReturnUrl, $secureEcom->challengeReturnUrl); $this->exemptStatus = $this->mergeValue($this->exemptStatus, $secureEcom->exemptStatus); - $this->exemptReason = $this->mergeValue($this->exemptStatus, $secureEcom->exemptReason); + $this->exemptReason = $this->mergeValue($this->exemptReason, $secureEcom->exemptReason); $this->liabilityShift = $this->mergeValue($this->liabilityShift, $secureEcom->liabilityShift); $this->acsReferenceNumber = $this->mergeValue($this->acsReferenceNumber, $secureEcom->acsReferenceNumber); $this->providerServerTransRef = $this->mergeValue($this->providerServerTransRef, $secureEcom->providerServerTransRef); diff --git a/src/Gateways/Gp3DSProvider.php b/src/Gateways/Gp3DSProvider.php index 9f7ea16a..df21fde9 100644 --- a/src/Gateways/Gp3DSProvider.php +++ b/src/Gateways/Gp3DSProvider.php @@ -82,13 +82,16 @@ protected function maybeSetKey(array $arr, $key, $value = null) } /** + * @param Secure3dBuilder $builder + * @return Transaction * @throws ApiException - * @return Transaction */ + * @throws GatewayException + */ public function processSecure3d(Secure3dBuilder $builder) { $transType = $builder->getTransactionType(); $timestamp = date("Y-m-d\TH:i:s.u"); - $paymentMethod = $builder->getPaymentMethod(); + $paymentMethod = $builder->paymentMethod; $secure3d = $paymentMethod; $request = []; diff --git a/src/Gateways/GpApiConnector.php b/src/Gateways/GpApiConnector.php index 18ed3178..7433927c 100644 --- a/src/Gateways/GpApiConnector.php +++ b/src/Gateways/GpApiConnector.php @@ -3,6 +3,7 @@ namespace GlobalPayments\Api\Gateways; use GlobalPayments\Api\Builders\AuthorizationBuilder; +use GlobalPayments\Api\Builders\FraudBuilder; use GlobalPayments\Api\Builders\ManagementBuilder; use GlobalPayments\Api\Builders\PayFacBuilder; use GlobalPayments\Api\Builders\ReportBuilder; @@ -22,6 +23,8 @@ use GlobalPayments\Api\Entities\IRequestBuilder; use GlobalPayments\Api\Entities\Reporting\DepositSummary; use GlobalPayments\Api\Entities\Reporting\DisputeSummary; +use GlobalPayments\Api\Entities\RiskAssessment; +use GlobalPayments\Api\Entities\ThreeDSecure; use GlobalPayments\Api\Entities\Transaction; use GlobalPayments\Api\Entities\Reporting\TransactionSummary; use GlobalPayments\Api\Entities\User; @@ -30,7 +33,7 @@ use GlobalPayments\Api\Mapping\GpApiMapping; use GlobalPayments\Api\PaymentMethods\AlternativePaymentMethod; -class GpApiConnector extends RestGateway implements IPaymentGateway, ISecure3dProvider, IPayFacProvider +class GpApiConnector extends RestGateway implements IPaymentGateway, ISecure3dProvider, IPayFacProvider, IFraudCheckService { const GP_API_VERSION = '2021-03-22'; const IDEMPOTENCY_HEADER = 'x-gp-idempotency'; @@ -163,6 +166,15 @@ public function processPayFac(PayFacBuilder $builder) throw new UnsupportedTransactionException(sprintf('Method %s not supported by %s', __METHOD__, $this->gpApiConfig->gatewayProvider)); } + public function processFraud(FraudBuilder $builder) : RiskAssessment + { + if (empty($this->accessToken)) { + $this->signIn(); + } + $response = $this->executeProcess($builder); + + return GpApiMapping::mapRiskAssessmentResponse($response); + } private function executeProcess($builder) { @@ -295,6 +307,9 @@ public function signIn() if (empty($accessTokenInfo->disputeManagementAccountName)) { $accessTokenInfo->disputeManagementAccountName = $response->getDisputeManagementAccountName(); } + if (empty($accessTokenInfo->riskAssessmentAccountName)) { + $accessTokenInfo->riskAssessmentAccountName = $response->getRiskAssessmentAccountName(); + } $this->gpApiConfig->accessTokenInfo = $accessTokenInfo; } diff --git a/src/Gateways/GpEcomConnector.php b/src/Gateways/GpEcomConnector.php index 5454ec92..8df78c16 100644 --- a/src/Gateways/GpEcomConnector.php +++ b/src/Gateways/GpEcomConnector.php @@ -2,61 +2,43 @@ namespace GlobalPayments\Api\Gateways; -use GlobalPayments\Api\Builders\AuthorizationBuilder; -use GlobalPayments\Api\Builders\ManagementBuilder; -use GlobalPayments\Api\Builders\RecurringBuilder; -use GlobalPayments\Api\Builders\ReportBuilder; +use GlobalPayments\Api\Builders\{ + AuthorizationBuilder, + ManagementBuilder, + RecurringBuilder, + ReportBuilder, + Secure3dBuilder +}; use GlobalPayments\Api\Builders\RequestBuilder\RequestBuilderFactory; -use GlobalPayments\Api\Entities\Address; -use GlobalPayments\Api\Entities\Customer; -use GlobalPayments\Api\Entities\Enums\GatewayProvider; -use GlobalPayments\Api\Entities\Enums\TransactionType; -use GlobalPayments\Api\Entities\Exceptions\BuilderException; -use GlobalPayments\Api\Entities\Exceptions\GatewayException; -use GlobalPayments\Api\Entities\Exceptions\UnsupportedTransactionException; -use GlobalPayments\Api\Entities\IRequestBuilder; -use GlobalPayments\Api\Entities\Request; -use GlobalPayments\Api\Entities\Schedule; -use GlobalPayments\Api\Entities\Transaction; +use GlobalPayments\Api\Entities\{Address, Customer, IRequestBuilder, Request, Schedule, Transaction}; +use GlobalPayments\Api\Entities\Enums\{GatewayProvider, TransactionType, FraudFilterMode, Secure3dVersion}; +use GlobalPayments\Api\Entities\Exceptions\{ + BuilderException, + GatewayException, + UnsupportedTransactionException, + ApiException +}; use GlobalPayments\Api\HostedPaymentConfig; use GlobalPayments\Api\Mapping\GpEcomMapping; -use GlobalPayments\Api\PaymentMethods\BankPayment; -use GlobalPayments\Api\PaymentMethods\TransactionReference; use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig; -use GlobalPayments\Api\Utils\CountryUtils; -use GlobalPayments\Api\Utils\GenerationUtils; -use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; -use GlobalPayments\Api\Entities\Enums\FraudFilterMode; -use GlobalPayments\Api\Entities\Enums\Secure3dVersion; -use GlobalPayments\Api\Builders\Secure3dBuilder; -use GlobalPayments\Api\Entities\Exceptions\ApiException; -use GlobalPayments\Api\Utils\StringUtils; +use GlobalPayments\Api\PaymentMethods\{RecurringPaymentMethod, BankPayment}; +use GlobalPayments\Api\Utils\{StringUtils, CountryUtils, GenerationUtils}; class GpEcomConnector extends XmlGateway implements IPaymentGateway, IRecurringService, ISecure3dProvider { - /** - * @var boolean - */ + /** @var bool */ public $supportsHostedPayments = true; - /** - * @var boolean - */ + /** @var bool */ public $supportsRetrieval = true; - /** - * @var boolean - */ + /** @var bool */ public $supportsUpdatePaymentDetails = true; - /** - * @var HostedPaymentConfig - */ + /** @var HostedPaymentConfig */ public $hostedPaymentConfig; - - /** - * @var array - */ + + /** @var array */ private $serializeData = []; /** @var GpEcomConfig */ diff --git a/src/Gateways/IFraudCheckService.php b/src/Gateways/IFraudCheckService.php new file mode 100644 index 00000000..866eb0ff --- /dev/null +++ b/src/Gateways/IFraudCheckService.php @@ -0,0 +1,13 @@ +id = $response->id; + $riskAssessment->timeCreated = $response->time_created; + $riskAssessment->status = $response->status ?? null; + $riskAssessment->amount = isset($response->amount) ? StringUtils::toAmount($response->amount) : null; + $riskAssessment->currency = $response->currency ?? null; + $riskAssessment->merchantId = $response->merchant_id ?? null; + $riskAssessment->merchantName = $response->merchant_name ?? null; + $riskAssessment->accountId = $response->account_id ?? null; + $riskAssessment->accountName = $response->account_name ?? null; + $riskAssessment->reference = $response->reference ?? null; + $riskAssessment->responseCode = $response->action->result_code ?? null; + $riskAssessment->responseMessage = $response->result ?? null; + if (isset($response->payment_method->card)) { + $paymentMethod = $response->payment_method->card; + $card = new Card(); + $card->maskedNumberLast4 = $paymentMethod->masked_number_last4 ?? null; + $card->brand = $paymentMethod->brand ?? null; + $card->brandReference = $paymentMethod->brand_reference ?? null; + $card->bin = $paymentMethod->bin ?? null; + $card->binCountry = $paymentMethod->bin_country ?? null; + $card->accountType = $paymentMethod->account_type ?? null; + $card->issuer = $paymentMethod->issuer ?? null; + + $riskAssessment->cardDetails = $card; + } + if (isset($response->raw_response)) { + $rawResponse = $response->raw_response; + $thirdPartyResponse = new ThirdPartyResponse(); + $thirdPartyResponse->platform = $rawResponse->platform; + $thirdPartyResponse->data = $rawResponse->data; + $riskAssessment->thirdPartyResponse = $thirdPartyResponse; + } + $riskAssessment->actionId = $response->action->id ?? null; + + return $riskAssessment; + } + /** * @param Object $response */ diff --git a/src/PaymentMethods/CreditCardData.php b/src/PaymentMethods/CreditCardData.php index aa4b1518..78110a41 100644 --- a/src/PaymentMethods/CreditCardData.php +++ b/src/PaymentMethods/CreditCardData.php @@ -105,6 +105,9 @@ public function getShortExpiry() */ public function getCardType() { + if (empty($this->number)) { + return; + } return CardUtils::getCardType($this->number); } diff --git a/src/PaymentMethods/Interfaces/ISecureCheck.php b/src/PaymentMethods/Interfaces/ISecureCheck.php new file mode 100644 index 00000000..ee23f0b6 --- /dev/null +++ b/src/PaymentMethods/Interfaces/ISecureCheck.php @@ -0,0 +1,7 @@ +gatewayConnector = $gateway; $services->reportingService = $gateway; + $services->fraudService = $gateway; $services->setPayFacProvider($gateway); $services->setSecure3dProvider(Secure3dVersion::ONE, $gateway); $services->setSecure3dProvider(Secure3dVersion::TWO, $gateway); + } public function validate() diff --git a/src/Services/FraudService.php b/src/Services/FraudService.php new file mode 100644 index 00000000..880b4373 --- /dev/null +++ b/src/Services/FraudService.php @@ -0,0 +1,21 @@ +withPaymentMethod($paymentMethod); + } +} \ No newline at end of file diff --git a/src/Services/GpApiService.php b/src/Services/GpApiService.php index d1c03c44..fad4d6a2 100644 --- a/src/Services/GpApiService.php +++ b/src/Services/GpApiService.php @@ -30,6 +30,7 @@ public static function generateTransactionKey(GpApiConfig $config) $accessTokenInfo->disputeManagementAccountName = $data->getDisputeManagementAccountName(); $accessTokenInfo->transactionProcessingAccountName = $data->getTransactionProcessingAccountName(); $accessTokenInfo->tokenizationAccountName = $data->getTokenizationAccountName(); + $accessTokenInfo->riskAssessmentAccountName = $data->getRiskAssessmentAccountName(); return $accessTokenInfo; } diff --git a/src/ServicesContainer.php b/src/ServicesContainer.php index b5a55ce7..7b63a88b 100644 --- a/src/ServicesContainer.php +++ b/src/ServicesContainer.php @@ -204,6 +204,15 @@ public function getOpenBanking($configName) throw new ApiException("The specified configuration has not been added for open banking."); } + public function getFraudCheckClient($configName) + { + if (array_key_exists($configName, static::$configurations)) { + return static::$configurations[$configName]->fraudService; + } + + throw new ApiException("The specified configuration has not been configured for fraud check."); + } + public static function removeConfiguration($configName = 'default') { if (array_key_exists($configName, static::$configurations)) { diff --git a/src/Utils/StringUtils.php b/src/Utils/StringUtils.php index 66db921e..d0d6dcfe 100644 --- a/src/Utils/StringUtils.php +++ b/src/Utils/StringUtils.php @@ -100,4 +100,13 @@ public static function isJson($string) json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } + + public static function boolToString($value) + { + if (!is_bool($value)) { + return; + } + + return json_encode($value); + } } diff --git a/test/Integration/Gateways/GpApiConnector/GpApiRiskAssessmentTest.php b/test/Integration/Gateways/GpApiConnector/GpApiRiskAssessmentTest.php new file mode 100644 index 00000000..5213bbc3 --- /dev/null +++ b/test/Integration/Gateways/GpApiConnector/GpApiRiskAssessmentTest.php @@ -0,0 +1,423 @@ +setUpConfig(); + ServicesContainer::configureService($config); + + $this->currency = 'GBP'; + $this->amount = '10.01'; + + $this->card = new CreditCardData(); + $this->card->number = '4012001038488884'; + $this->card->expMonth = '12'; + $this->card->expYear = date('Y', strtotime('+1 year')); + $this->card->cardHolderName = "James Mason"; + + $this->shippingAddress = new Address(); + $this->shippingAddress->streetAddress1 = "Apartment 852"; + $this->shippingAddress->streetAddress2 = "Complex 741"; + $this->shippingAddress->streetAddress3 = "no"; + $this->shippingAddress->city = "Chicago"; + $this->shippingAddress->postalCode = "5001"; + $this->shippingAddress->state = "IL"; + $this->shippingAddress->countryCode = "840"; + + //IF WE SET THE screenHeight/screenWidth the API will return a strange error + $this->browserData = new BrowserData(); + $this->browserData->acceptHeader = "text/html,application/xhtml+xml,application/xml;q=9,image/webp,img/apng,*/*;q=0.8"; + $this->browserData->colorDepth = ColorDepth::TWENTY_FOUR_BITS; + $this->browserData->ipAddress = "123.123.123.123"; + $this->browserData->javaEnabled = true; + $this->browserData->javaScriptEnabled = true; + $this->browserData->language = "en-US"; + $this->browserData->challengWindowSize = ChallengeWindowSize::FULL_SCREEN; + $this->browserData->timeZone = "0"; + $this->browserData->userAgent = "Mozilla/5.0 (Windows NT 6.1; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"; + } + + public static function tearDownAfterClass() + { + BaseGpApiTestConfig::resetGpApiConfig(); + } + + public function setUpConfig() + { + return BaseGpApiTestConfig::gpApiSetupConfig(Channel::CardNotPresent); + } + + public function testTransactionRiskAnalysisBasicOption() + { + $idempotencyKey = GenerationUtils::getGuid(); + + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withIdempotencyKey($idempotencyKey) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + } + + public function testTransactionRiskAnalysis_WithIdempotency() + { + $idempotencyKey = GenerationUtils::getGuid(); + + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withIdempotencyKey($idempotencyKey) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + + $errorFound = false; + try { + FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withIdempotencyKey($idempotencyKey) + ->withBrowserData($this->browserData) + ->execute(); + } catch (GatewayException $e) { + $errorFound = true; + $this->assertStringContainsString("Status Code: DUPLICATE_ACTION - Idempotency Key seen before", $e->getMessage()); + $this->assertEquals('40039', $e->responseCode); + } finally { + $this->assertTrue($errorFound); + } + } + + public function testRiskAssessmentFullOption() + { + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withOrderCreateDate(date('Y-m-d H:i:s')) + ->withReferenceNumber('my_EOS_risk_assessment') + ->withAddressMatchIndicator(false) + ->withAddress($this->shippingAddress, AddressType::SHIPPING) + ->withGiftCardAmount(2) + ->withGiftCardCount(1) + ->withGiftCardCurrency($this->currency) + ->withDeliveryEmail('james.mason@example.com') + ->withDeliveryTimeFrame(DeliveryTimeFrame::SAME_DAY) + ->withShippingMethod(ShippingMethod::VERIFIED_ADDRESS) + ->withShippingNameMatchesCardHolderName(false) + ->withPreOrderIndicator(PreOrderIndicator::FUTURE_AVAILABILITY) + ->withPreOrderAvailabilityDate(date('Y-m-d H:i:s')) + ->withReorderIndicator(ReorderIndicator::REORDER) + ->withOrderTransactionType(OrderTransactionType::GOODS_SERVICE_PURCHASE) + ->withCustomerAccountId(\GlobalPayments\Api\Utils\GenerationUtils::getGuid()) + ->withAccountAgeIndicator(AgeIndicator::LESS_THAN_THIRTY_DAYS) + ->withAccountCreateDate(date('Y-m-d')) + ->withAccountChangeDate(date('Y-m-d')) + ->withAccountChangeIndicator(AgeIndicator::THIS_TRANSACTION) + ->withPasswordChangeDate(date('Y-m-d')) + ->withPasswordChangeIndicator(AgeIndicator::LESS_THAN_THIRTY_DAYS) + ->withPhoneNumber('44', '123456789', PhoneNumberType::HOME) + ->withPhoneNumber('44', '1801555888', PhoneNumberType::WORK) + ->withPaymentAccountCreateDate(date('Y-m-d')) + ->withPaymentAccountAgeIndicator(AgeIndicator::LESS_THAN_THIRTY_DAYS) + ->withPreviousSuspiciousActivity(false) + ->withNumberOfPurchasesInLastSixMonths(3) + ->withNumberOfTransactionsInLast24Hours(1) + ->withNumberOfTransactionsInLastYear(5) + ->withNumberOfAddCardAttemptsInLast24Hours(1) + ->withShippingAddressCreateDate(date('Y-m-d H:i:s')) + ->withShippingAddressUsageIndicator(AgeIndicator::THIS_TRANSACTION) + ->withPriorAuthenticationMethod(PriorAuthenticationMethod::FRICTIONLESS_AUTHENTICATION) + ->withPriorAuthenticationTransactionId(GenerationUtils::getGuid()) + ->withPriorAuthenticationTimestamp(date('2022-10-10T16:41:33')) + ->withPriorAuthenticationData('secret123') + ->withMaxNumberOfInstallments(5) + ->withRecurringAuthorizationFrequency(25) + ->withRecurringAuthorizationExpiryDate(date('Y-m-d')) + ->withCustomerAuthenticationData('secret123') + ->withCustomerAuthenticationTimestamp(date('2022-10-10T16:41:33')) + ->withCustomerAuthenticationMethod(CustomerAuthenticationMethod::MERCHANT_SYSTEM) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + } + + public function testTransactionRiskAnalysisBasicOption_WithIdempotency() + { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + } + + public function testTransactionRiskAnalysis_AllSources() + { + $source = array(AuthenticationSource::BROWSER, AuthenticationSource::MERCHANT_INITIATED, AuthenticationSource::MOBILE_SDK); + foreach ($source as $value) { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource($value) + ->withBrowserData($this->browserData) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + } + } + + public function testTransactionRiskAnalysis_AllDeliveryTimeFrames() + { + $deliveryTimeFrame = new DeliveryTimeFrame(); + $reflectionClass = new ReflectionClass($deliveryTimeFrame); + foreach ($reflectionClass->getConstants() as $value) { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->withDeliveryTimeFrame($value) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + } + } + + public function testTransactionRiskAnalysis_AllShippingMethods() + { + $shippingMethod = new ShippingMethod(); + $reflectionClass = new ReflectionClass($shippingMethod); + foreach ($reflectionClass->getConstants() as $value) { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->withShippingMethod($value) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + } + } + + public function testTransactionRiskAnalysis_AllOrderTransactionTypes() + { + $shippingMethod = new OrderTransactionType(); + $reflectionClass = new ReflectionClass($shippingMethod); + foreach ($reflectionClass->getConstants() as $value) { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->withOrderTransactionType($value) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + } + } + + public function testTransactionRiskAnalysis_AllPriorAuthenticationMethods() + { + $shippingMethod = new PriorAuthenticationMethod(); + $reflectionClass = new ReflectionClass($shippingMethod); + foreach ($reflectionClass->getConstants() as $value) { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->withPriorAuthenticationMethod($value) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertStringStartsWith("RAS_", $response->id); + } + } + + public function testTransactionRiskAnalysis_AllCustomerAuthenticationMethods() + { + $shippingMethod = new CustomerAuthenticationMethod(); + $reflectionClass = new ReflectionClass($shippingMethod); + foreach ($reflectionClass->getConstants() as $value) { + /** @var \GlobalPayments\Api\Entities\RiskAssessment $response */ + $response = FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->withCustomerAuthenticationMethod($value) + ->execute(); + + $this->assertEquals("SUCCESS", $response->responseCode); + $this->assertEquals(RiskAssessmentStatus::ACCEPTED, $response->status); + $this->assertEquals("Apply Exemption", $response->responseMessage); + $this->assertStringStartsWith("RAS_", $response->id); + } + } + + public function testTransactionRiskAnalysis_MissingAmount() + { + $errorFound = false; + try { + FraudService::riskAssess($this->card) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->execute(); + } catch (GatewayException $e) { + $errorFound = true; + $this->assertEquals("Status Code: MANDATORY_DATA_MISSING - Request expects the following field order.amount", $e->getMessage()); + $this->assertEquals('40005', $e->responseCode); + } finally { + $this->assertTrue($errorFound); + } + } + + public function testTransactionRiskAnalysis_MissingCurrency() + { + $errorFound = false; + try { + FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->execute(); + } catch (GatewayException $e) { + $errorFound = true; + $this->assertEquals("Status Code: MANDATORY_DATA_MISSING - Request expects the following field order.currency", $e->getMessage()); + $this->assertEquals('40005', $e->responseCode); + } finally { + $this->assertTrue($errorFound); + } + } + + public function testTransactionRiskAnalysis_MissingSource() + { + $errorFound = false; + try { + FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withBrowserData($this->browserData) + ->execute(); + } catch (GatewayException $e) { + $errorFound = true; + $this->assertEquals("Status Code: MANDATORY_DATA_MISSING - Request expects the following field order.amount", $e->getMessage()); + $this->assertEquals('40005', $e->responseCode); + } finally { + $this->assertTrue($errorFound); + } + } + + public function testTransactionRiskAnalysis_MissingBrowserData() + { + $errorFound = false; + try { + FraudService::riskAssess($this->card) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->execute(); + } catch (GatewayException $e) { + $errorFound = true; + $this->assertEquals("Status Code: MANDATORY_DATA_MISSING - Request expects the following field browser_data.accept_header", $e->getMessage()); + $this->assertEquals('40005', $e->responseCode); + } finally { + $this->assertTrue($errorFound); + } + } + + public function testTransactionRiskAnalysis_MissingCard() + { + $errorFound = false; + try { + FraudService::riskAssess(new CreditCardData()) + ->withAmount($this->amount) + ->withCurrency($this->currency) + ->withAuthenticationSource(AuthenticationSource::BROWSER) + ->withBrowserData($this->browserData) + ->execute(); + } catch (GatewayException $e) { + $errorFound = true; + $this->assertEquals("Status Code: MANDATORY_DATA_MISSING - Request expects the following field payment_method.card.number", $e->getMessage()); + $this->assertEquals('40005', $e->responseCode); + } finally { + $this->assertTrue($errorFound); + } + } +} \ No newline at end of file