Skip to content

Creating UPO Card #98

Description

@hantsy

I tried to create a UPO by Card using executor.execute(AddUPOCreditCardRequest), but returned an error with reason similar to The specified user token is not found or doesn't belong to the user.

So I tried to create a new user in Nuvei side firstly, then create a UPO.

  1. Check the user existence by executor.execute(GetUserDetailsRequest)
  2. a. If user found/status = SUCCESS, update the user by executor.execute(UpdateUserRequest)
    b. If user not found/status = ERROR, create a new user by executor.execute(CreateUserRequest) (<- this step always returns an ERROR status in my testing codes, but could be sucessful, it did not prevent me to step3)
  3. Then create UPO Card by executor.execute(AddUPOCreditCardRequest)

Here I share some code snippets of the step 1 and 2.

private suspend fun createUserIfNotExists(
        userTokenId: String? = null,
        firstName: String? = null,
        lastName: String? = null,
        email: String? = null,
        phoneNumber: String? = null,
        address: String? = null,
        city: String? = null,
        state: String? = null,
        country: String? = null,
        zipcode: String? = null
    ) {
        val getUserDetailsBuilder = GetUserDetailsRequest.builder()
            .userTokenId(userTokenId)
            .addMerchantInfo(merchantInfo)

        val userDetailsResponse = try {
            withContext(Dispatchers.IO) {
                requestExecutor.execute(getUserDetailsBuilder.build()) as GetUserDetailsResponse
            }
        } catch (e: Exception) {
            throw NuveiPaymentServiceException("Get user details failed: ${e.message}")
        }
        log.debug("Get user details response: $userDetailsResponse")
        if (userDetailsResponse.status == Constants.APIResponseStatus.SUCCESS) {
            val updateUserRequestBuilder = UpdateUserRequest.builder()
                .addMerchantInfo(merchantInfo)
                .userTokenId(userTokenId)
                .firstName(firstName)
                .lastName(lastName)
                .phone(phoneNumber)
                .email(email)
                .city(city)
                .country(country)
                .state(state)
                .address(address)
                .zip(zipcode)
            try {
                withContext(Dispatchers.IO) {
                    requestExecutor.execute(updateUserRequestBuilder.build()) as UserResponse
                }
            } catch (e: Exception) {
                throw NuveiPaymentServiceException("Update user details failed: ${e.message}")
            }
            log.debug("Update user details response: $userDetailsResponse")
        } else {
            val createUserDetailsBuilder = CreateUserRequest.builder()
                .addMerchantInfo(merchantInfo)
                .userTokenId(userTokenId)
                .firstName(firstName)
                .lastName(lastName)
                .phone(phoneNumber)
                .email(email)
                .city(city)
                .country(country)
                .state(state)
                .address(address)
                .zip(zipcode)
            try {
                withContext(Dispatchers.IO) {
                    requestExecutor.execute(createUserDetailsBuilder.build()) as UserResponse
                }
            } catch (e: Exception) {
                throw NuveiPaymentServiceException("Create user details failed: ${e.message}")
            }
            log.debug("Create user details response: $userDetailsResponse")
        }
    }

When I run my testing codes to perform a creating UPO Card with the following data.

userTokenId = UUID.randomUUID().toString(),
cardHolderName = "Hantsy Bai",
cardNumber = "4761201381475297",
cardExpirationYear = "2030",
cardExpirationMonth = "01",
firstName = "Hantsy",
lastName = "Bai",
address = "test",
phoneNumber = "",
zipcode = "",
city = "",
country = "",
state = "",
email = "hantsy@etip.io"

It will print logs of the steps in console like this:

2025-04-14T18:03:07.544+08:00 DEBUG 14236 --- [s.test runner#2] i.e.b.i.nuvei.NuveiProperties            : Get user details response:
 internalRequestId=19750311111, status=ERROR, errCode=1010, reason='User with the specified token is not found!', merchantId='6839445827700704346', merchantSiteId='262438', version='1.0', clientRequestId='null', sessionToken='null', clientUniqueId='null', errorType=null, apiType=null, hint=null
2025-04-14T18:03:08.079+08:00 DEBUG 14236 --- [s.test runner#2] i.e.b.i.nuvei.NuveiProperties            : Create user details response: 
internalRequestId=19750311111, status=ERROR, errCode=1010, reason='User with the specified token is not found!', merchantId='6839445827700704346', merchantSiteId='262438', version='1.0', clientRequestId='null', sessionToken='null', clientUniqueId='null', errorType=null, apiType=null, hint=null
2025-04-14T18:03:09.375+08:00 DEBUG 14236 --- [s.test runner#2] i.e.b.i.nuvei.NuveiProperties            : Add card UPO response: 
AddUPOCreditCardResponse{userPaymentOptionId=1050275111, ccToken='OABRAG8AUABuAFAARgBuAG4ARgBuAG4ASQBlADUAVABnAG4AVAB3AD4AWgBFAGIANwAsAFkAYgAsAGMAYgAlAEkAbQA/AE4AXwA1AHQAWwB7AGIAXABtAHQALAA5ADIAJAA1AEoAMwA=', brand='visa', uniqueCC='7cDCtV2wA5C6tm8y9MC+AIFlcU4=', bin='476120', last4Digits='5297', cardType='Credit', externalTokenProvider='null', billingAddress='UserDetails{firstName='Hantsy', lastName='Bai', address='test', phone='', zip='', city='', country='null', state='', email='hantsy@etip.io', locale='null', county='null', identification='null', identificationType='null'}, Birthdate='null'}', internalRequestId=19750314111, status=SUCCESS, errCode=0, reason='', merchantId='6839445827700704346', merchantSiteId='262438', version='1.0', clientRequestId='null', sessionToken='null', clientUniqueId='null', errorType=null, apiType=null, hint=null}
2025-04-14T18:03:09.376+08:00 DEBUG 14236 --- [s.test runner#2] i.e.b.e.NuveiPaymentServiceTest          : create card upo result: 1050275111

I have run the testing codes several times, the creating user step always failed(with an ERROR status), but the further creating UPO Card got successful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions