# Making an EU Region API Call with unencrypted payload
source: https://developer.mastercard.com/cross-border-services/documentation/tutorials/psd2-unencrypted-api-call-tutorial/index.md

Create a Java file, called Main.java, at src/main/java/.

Base Path has to be set as per the region:  

**EU Region Base Path:** <https://sandbox.api.xbs.mastercard.eu>   

**UK Region Base Path:** <https://sandbox.api.xbs.mastercard.uk>

To make the API call, you need to make your OAuth credentials available to the program as shown below:
* Oauth

```Oauth
String consumerKey = "your consumer key";
String signingKeyFilePath = "/path/to/your/key.p12";
String signingKeyAlias = "your key alias";
String signingKeyPassword = "your password";
PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword);
```

Next, you instantiate a client that you can set up to sign requests that you send with your authentication credentials.
Note: Request Token generation is included as part of OkHttp2OAuth2RequestTokenInterceptor which will generate a request token based on the provided Consumer Key, P12 File, Signing Key Alias \& Signing Key Password.
* Client_Instantiation

```Client_Instantiation
ApiClient client = new ApiClient();
client.setBasePath("/path/to/your/domainURL");
client.setDebugging(true);
client.setReadTimeout(40000);

// For mTLS connection (For Sandbox EU/UK domain testing, do not keep below configurations)
KeyStore keystore = KeyStore.getInstance("PKCS12");
char[] password= "yourPFXPassword".toCharArray();

keystore.load((new FileInputStream("/path/to/your/.pfx")),password);

SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setKeyStore(keystore);
sslContextFactory.setKeyStorePassword("yourPFXPassword");
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
SSLSocketFactory sf = sslContext.getSocketFactory();
OkHttpClient httpClient = client.getHttpClient();
httpClient.setSslSocketFactory(sf);
client.addDefaultHeader("Content-Type", "application/json; charset=UTF-8");
client.setHttpClient(httpClient);
        
List<Interceptor> interceptors = client.getHttpClient().networkInterceptors();
interceptors.add(new OkHttp2OAuth2RequestTokenInterceptor(signingKeyFilePath, signingKeyAlias, signingKeyPassword, consumerKey));

PaymentApi paymentApi = new PaymentApi(client);   
```

With your environment set up, you can now start to build a request.
Any nested objects within the Request Body have been assigned a wrapper class each, and so in order to build the request, you will be instantiating multiple objects and ultimately wrapping those with the main request object.

You may store the response in a Response object.
Once you have the response stored, you have different options, but for this tutorial you can simply use toString to print the response body.  

To make it easy to understand, only the snippets needed to make the API call is shown above. The full content of Main.java is shown below.

## Content of Main.java {#content-of-mainjava}

* Main.Java

```Main.Java
package com.mastercard.test;

import com.mastercard.oauth2.requesttoken.interceptor.OkHttp2OAuth2RequestTokenInterceptor;
import com.mastercard.developer.utils.AuthenticationUtils;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import org.openapitools.client.ApiClient;
import org.openapitools.client.api.CardedRateApi;
import org.openapitools.client.api.PaymentApi;
import org.openapitools.client.api.RetrievePaymentApi;
import org.openapitools.client.model.*;
import interceptor.OkHttp2OAuth2Interceptor;
import java.io.IOException;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        ApiClient client = new ApiClient();

        String consumerKey = "your consumer key";
        String signingKeyFilePath = "/path/to/your/key.p12";
        String signingKeyAlias = "your key alias";
        String signingKeyPassword = "your password";
        PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword);

        client.setBasePath("/path/to/your/domainURL");
        client.setDebugging(true);
        client.setReadTimeout(40000);
        
        // for mTLS connection (For Sandbox EU/UK domain testing, do not keep below configurations)
        KeyStore keystore = KeyStore.getInstance("PKCS12");
        char[] password= "yourPFXPassword".toCharArray();
        
        keystore.load((new FileInputStream("/path/to/your/.pfx")),password);
        
        SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
        sslContextFactory.setKeyStore(keystore);
        sslContextFactory.setKeyStorePassword("yourPFXPassword");
        sslContextFactory.start();
        SSLContext sslContext = sslContextFactory.getSslContext();
        SSLSocketFactory sf = sslContext.getSocketFactory();
        OkHttpClient httpClient = client.getHttpClient();
        httpClient.setSslSocketFactory(sf);
        client.addDefaultHeader("Content-Type", "application/json; charset=UTF-8");
        client.setHttpClient(httpClient);
        
        List<Interceptor> interceptors = client.getHttpClient().networkInterceptors();
        interceptors.add(new OkHttp2OAuth2RequestTokenInterceptor(signingKeyFilePath, signingKeyAlias, signingKeyPassword, consumerKey));

        String partnerId = "your_partner_id";  // example: "BEL_MASEND5ged2"

        /*Payment API call*/
        PaymentApi paymentApi = new PaymentApi(client);
        System.out.println("Calling Make Payment");
        PaymentRequestWrapper paymentRequestWrapper = getPaymentRequest(); // Populate payment request
        PaymentWrapper remitResponse = paymentApi.payment(partnerId,paymentRequestWrapper);
        System.out.println("Make payment response : " + remitResponse);

        /*Retrieve Payment API call*/
        RetrievePaymentApi retrievePayment = new RetrievePaymentApi(client);
        System.out.println("Calling Retrieve Payment");
        String ref = "061574074811229"; //Can be obtained by remitResponse.getPayment().getTransactionReference();
        RetrievePaymentWrapper response = retrievePayment.transactionStatus(partnerId, ref);
        System.out.println("Retrieve Payment response: " +response);
    }

    private static PaymentRequestWrapper getPaymentRequest() {

        PaymentRequest paymentRequest = new PaymentRequest();
        paymentRequest.setTransactionReference(String.valueOf(System.currentTimeMillis()));
        paymentRequest.setSenderAccountUri("tel:+254108989");
        paymentRequest.setRecipientAccountUri("ewallet:paypal_user011");
        /* Amount information */
        PaymentAmount amount = new PaymentAmount();
        amount.setAmount("200");
        amount.setCurrency("INR");
        paymentRequest.setPaymentAmount(amount);
        paymentRequest.setPaymentOriginationCountry("ARE");

        FxType quoteType = new FxType();
        Reverse reverseFees = new Reverse();
        reverseFees.setSenderCurrency("USD");
        quoteType.setReverse(reverseFees);
        paymentRequest.setFxType(quoteType);
        paymentRequest.setBankCode("NP021");
        paymentRequest.setPaymentType("P2B");

        /*Sender Information */
        Sender senderData = new Sender();
        senderData.setFirstName("Pat");
        senderData.setLastName("Rose");
        senderData.setNationality("IND");
        Address senderAddress = new Address();
        senderAddress.setLine1("53 Main Street");
        senderAddress.setLine2("5A");
        senderAddress.setCity("Pune");
        senderAddress.setCountrySubdivision("MH");
        senderAddress.setCountry("IND");
        senderAddress.setPostalCode("411001");
        senderData.setAddress( senderAddress);

        GovernmentIds idData1 = new GovernmentIds();
        List<GovernmentIds> governmentIds = new ArrayList<>();
        idData1.setGovernmentIdUri("ppn:123456789;expiration-date=2019-05-27;issue-date=2011-07-12;country=USA");
        governmentIds.add(idData1);
        senderData.setGovernmentIds(governmentIds);
        senderData.setDateOfBirth("1985-06-24");
        paymentRequest.setSender(senderData);

        /*Recipient information */
        Recipient recipientData = new Recipient();
        recipientData.setEmail("test@gmail.com");
        recipientData.setNationality("USA");
        recipientData.setOrganizationName("WU");
        Address recipientAddress = new Address();
        recipientAddress.setLine1("123 MainStreet");
        recipientAddress.setLine2("5A");
        recipientAddress.setCity("Arlington");
        recipientAddress.setCountrySubdivision("VA");
        recipientAddress.setCountry("USA");
        recipientAddress.setPostalCode("22207");
        recipientData.setAddress(recipientAddress);
        paymentRequest.setRecipient(recipientData);

        /* Additional Data */
        List <DataField> fields = new ArrayList<>();
        DataField dataField1 = new DataField();
        dataField1.setName("501");dataField1.setValue("1234222222");
        DataField dataField2 = new DataField();
        dataField2.setName("503");dataField2.setValue("12362");
        AdditionalData additionalField = new AdditionalData();
        additionalField.setDataField(fields);
        paymentRequest.setAdditionalData(additionalField);

        paymentRequest.setSourceOfIncome("Bank");
        paymentRequest.setReceivingBankName("Royal Exchange");
        paymentRequest.setReceivingBankBranchName("Quad Cities");
        paymentRequest.setPaymentFileIdentifier("1233241223");
        PaymentRequestWrapper wrapper = new PaymentRequestWrapper();
        wrapper.setPaymentrequest(paymentRequest);
        return wrapper;
    }

    /**Add "Format=JSON" to the request for the service/gateway to return a JSON response.*/
    private static class ForceJsonResponseInterceptor implements Interceptor {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request originalRequest = chain.request();
            String withJsonFormatUrl = withJsonFormat(originalRequest.uri().toString());
            Request newRequest = originalRequest.newBuilder().url(withJsonFormatUrl).build();
            return chain.proceed(newRequest);
        }

        private String withJsonFormat(String uri) {
            StringBuilder newUri = new StringBuilder(uri);
            newUri.append(uri.contains("?") ? "&" : "?");
            newUri.append("Format=JSON");
            return newUri.toString();
        }
    }
}

```

[Go Back to API Tutorial](https://developer.mastercard.com/cross-border-services/documentation/tutorials/oauth2-api-sdk-tutorial-request-token/index.md)
