globalpayments / php-sdk

GNU General Public License v2.0
49 stars 66 forks source link

paymentMethod cannot be null for this transaction type, paymentMethod must be an instance of the GlobalPayments\Api\PaymentMethods\Interfaces\ISecure3d class. #96

Closed ssrgspdkt closed 9 months ago

ssrgspdkt commented 2 years ago

I'm using the following code to initiate 3dsecure 2. I got many errors. Please provide a solution to go ahead

$config = new GpEcomConfig(); $config->merchantId = "dev995440795660692259"; $config->accountId = "internet"; $config->sharedSecret = "mPFK3LldnO";

$config->methodNotificationUrl = 'https://example.com/globalpayment_new/method_url_endpoint.php'; $config->challengeNotificationUrl = 'https://example.com/globalpayment_new/challenge_notification_endpoint.php'; $config->merchantContactUrl = 'https://example.com/'; $config->secure3dVersion = Secure3dVersion::TWO; ServicesContainer::configureService($config);

// add cardholder data // Frictionless Example: 4263970000005262 // Challenge Example: 4012001038488884

// Add the cardholder data $card = new CreditCardData(); $card->number = "4012001038488884"; $card->expMonth = "05"; $card->expYear = "25"; $card->cvn = "123"; $card->cardHolderName = "James Mason";

// Add the customer's billing address $billingAddress = new Address(); $billingAddress->streetAddress1 = "Apartment 852"; $billingAddress->streetAddress2 = "Complex 741"; $billingAddress->streetAddress3 = "Unit 4"; $billingAddress->city = "Chicago"; $billingAddress->state = "IL"; $billingAddress->postalCode = "50001"; $billingAddress->countryCode = "840";

// Add the customer's shipping address $shippingAddress = new Address(); $shippingAddress->streetAddress1 = "Flat 456"; $shippingAddress->streetAddress2 = "House 789"; $shippingAddress->streetAddress3 = "Basement Flat"; $shippingAddress->city = "Halifax"; $shippingAddress->postalCode = "W5 9HR"; $shippingAddress->countryCode = "826";

// Add captured browser data from the client-side and server-side $browserData = new BrowserData(); $browserData->acceptHeader = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8"; $browserData->colorDepth = 24; $browserData->ipAddress = "123.123.123.123"; $browserData->javaEnabled = TRUE; $browserData->language = "en"; $browserData->screenHeight = "1080"; $browserData->screenWidth = "1920"; $browserData->challengWindowSize =600; $browserData->timeZone = "0"; $browserData->userAgent = $_SERVER['HTTP_USER_AGENT'];

$threeDSecureData = new ThreeDSecure(); $threeDSecureData->serverTransactionId = "9de5bccf-c438-4024-8961-ec4b3cff15ff"; $threeDSecureData->serverTransactionId = "af65c369-59b9-4f8d-b2f6-7d7d5f5c69d5";

try { $threeDSecureData = Secure3dService::initiateAuthentication($card, $threeDSecureData) ->withAmount(10.01) ->withCurrency("GBP") ->withOrderCreateDate(date("Y-m-d H:i:s")) ->withCustomerEmail("james.mason@example.com") ->withAddress($billingAddress, AddressType::BILLING) ->withAddress($shippingAddress, AddressType::SHIPPING) ->withBrowserData($browserData) ->withMethodUrlCompletion(MethodUrlCompletion::YES) ->withMobileNumber("44", "7123456789") ->execute('default',Secure3dVersion::TWO); } catch (ApiException $e) { print_r($e); echo 'Failure: ' . $e->getMessage()."\n"; exit; // TODO: add your error handling here } print_r($threeDSecureData);die; $status = $threeDSecureData->status;

Errors as follows:

[0] => GlobalPayments\Api\Builders\BaseBuilder\ValidationTarget Object --   | (   | [parent] => GlobalPayments\Api\Builders\BaseBuilder\Validations Object   | *RECURSION*   | [type] => 16777216   | [modifier] => 0   | [property] => paymentMethod   | [clause] => GlobalPayments\Api\Builders\BaseBuilder\ValidationClause Object   | (   | [parent] => GlobalPayments\Api\Builders\BaseBuilder\Validations Object   | *RECURSION*   | [target] => GlobalPayments\Api\Builders\BaseBuilder\ValidationTarget Object   | *RECURSION*   | [precondition] =>   | [callback] => Closure Object   | (   | [static] => Array   | (   | [subProperty] =>   | )   |     | [this] => GlobalPayments\Api\Builders\BaseBuilder\ValidationClause Object   | *RECURSION*   | [parameter] => Array   | (   | [$builder] =>   | )   |     | )   |     | [message] => paymentMethod cannot be null for this transaction type.   | )   |     | )   |     | [1] => GlobalPayments\Api\Builders\BaseBuilder\ValidationTarget Object   | (   | [parent] => GlobalPayments\Api\Builders\BaseBuilder\Validations Object   | *RECURSION*   | [type] => 16777216   | [modifier] => 0   | [property] =>   | [clause] =>   | )   |     | [2] => GlobalPayments\Api\Builders\BaseBuilder\ValidationTarget Object   | (   | [parent] => GlobalPayments\Api\Builders\BaseBuilder\Validations Object   | *RECURSION*   | [type] => 16777216   | [modifier] => 0   | [property] => paymentMethod   | [clause] => GlobalPayments\Api\Builders\BaseBuilder\ValidationClause Object   | (   | [parent] => GlobalPayments\Api\Builders\BaseBuilder\Validations Object   | *RECURSION*   | [target] => GlobalPayments\Api\Builders\BaseBuilder\ValidationTarget Object   | *RECURSION*   | [precondition] =>   | [callback] => Closure Object   | (   | [static] => Array   | (   | [clazz] => GlobalPayments\Api\PaymentMethods\Interfaces\ISecure3d   | )   |     | [this] => GlobalPayments\Api\Builders\BaseBuilder\ValidationClause Object   | *RECURSION*   | [parameter] => Array   | (   | [$builder] =>   | )   |     | )   |     | [message] => paymentMethod must be an instance of the GlobalPayments\Api\PaymentMethods\Interfaces\ISecure3d class.   | )   |     | )
cristina-nechita commented 2 years ago

In order to catch the error message please use "GatewayException". The value set on the challengWindowSize should be one from the enum class "ChallengeWindowSize": $browserData->challengWindowSize = ChallengeWindowSize::WINDOWED_600X400;

Also you need a valid "serverTransactionId" from the first step "checkEnrollment", if not you will get error message: "Status Code: 400"