Menu

Java SDK for Connected Checkout

1. Set Client Id

Use the consumer key generated in the Merchant Portal to set the client id.

MasterCardApiConfig.setClientId("cLb0tKkEJhGTITp_6ltDIibO5Wgbx4rIldeXM_jRd4b0476c!414f4859446c4a366c726a327474695545332b353049303d"); 

2. Set private key

Prior to completing this step, the developer must have uploaded or generated a PEM encoded Certificate Request File as part of the onboarding process.

MasterCardApiConfig.setPrivateKey(getPrivateKey());

...
 
private static PrivateKey getPrivateKey() {
     String fileName = "example-file.p12"; // path to your p12 file
    String password = "password";         // your keystore password
    PrivateKey privateKey = null;
    try {
        KeyStore ks = KeyStore.getInstance("PKCS12");
        ks.load(AbstractTest.class.getResourceAsStream(fileName), password.toCharArray());
        Enumeration<String> enumeration = ks.aliases();
        String keyAlias = enumeration.nextElement();
        privateKey = (PrivateKey) ks.getKey(keyAlias, password.toCharArray());
    } catch (Exception e) {
     throw new MCApiRuntimeException(e);
    }

    return privateKey;
}

3. Set MasterPass environment

MasterCardApiConfig.SANDBOX = true;

Connected Checkout Integration

Pairing During Checkout

1. Call Request Token Service (2 times)

Call the Request Token Service twice. The first call generates a pairing request token, which will be used to gain the long access token needed to pair the consumer's wallet and merchant account.

The second call generates a checkout request token that will be used to invoke the MasterPass Lightbox. Pass a callback_url that the browser will redirect to when the Lightbox closes.

The Request Token Service calls must be made before the consumer clicks the Buy with MasterPass button.

String callback_url = "https://www.somemerchant.com/checkoutconfirm.htm";

RequestTokenResponse pairingResponse = RequestTokenService.create(Auth.auth(callback_url));
String pairing_request_token = pairingResponse.getOauthToken();

RequestTokenResponse checkoutResponse = RequestTokenService.create(Auth.auth(callback_url));
String checkout_request_token = checkoutResponse.getOauthToken();

2. Call Shopping Cart Service

The Shopping Cart Service enables shopping cart data to be displayed to users as they proceed through the MasterPass login and checkout. This service requires the checkout request token from Step 1.

Each ShoppingCartItem must have a description, quantity, and value. Value is represented as an integer (for example, USD 100.00 is 10000), and is calculated as the cost of a single item multiplied by the quantity of that item. A ShoppingCartItem may also have an optional imageURL.

The Shopping Cart Service must be called before the consumer clicks the Buy with MasterPass button.

//Create an instance of ShoppingCartRequest
ShoppingCartRequest shoppingCartRequest = new ShoppingCartRequest()
        .shoppingCart(new ShoppingCart()
            .subtotal(11900)
            .currencyCode("USD")
            .shoppingCartItem(new ShoppingCartItem()
                .value(1900)
                .description("This is one item")
                .quantity(1))

            .shoppingCartItem(new ShoppingCartItem()
                .imageURL("https://somemerchant.com/someimage")
                .value(10000)
                .description("Five items")
                .quantity(5)))
        .oAuthToken(checkout_request_token);

//Call the ShoppingCartService with required params
ShoppingCartResponse shoppingCartResponse = ShoppingCartService.create(shoppingCartRequest);

3. Call Merchant Initialization Service

The Merchant Initialization Service is used to secure Lightbox connections between the merchant and MasterPass. The originUrl identifies the origin of the page that will initialize the Lightbox. This service requires the checkout request token from Step 1.

The Merchant Initialization Service must be called before the consumer clicks the Buy with MasterPass button.

//Create an instance of MerchantInitializationRequest
MerchantInitializationRequest merchantInitializationRequest = new MerchantInitializationRequest()
        .originUrl("https://somemerchant.com")
        .oAuthToken(checkout_request_token);

//Call the MerchantInitializationApi with required params
MerchantInitializationResponse merchantInitializationResponse = MerchantInitializationService.create(merchantInitializationRequest);

4. Invoke MasterPass UI (Lightbox) for checkout

On the Checkout Page of the merchant's website, add the Buy with MasterPass button to your HTML (see MasterPass Branding to customize size and locale).

<img src="https://www.mastercard.com/mc_us/wallet/img/en/US/mcpp_wllt_btn_chk_147x034px.png"/>

Import jQuery, and add the MasterPass Integration Script for either the sandbox or the production environment.

<!-- url to jquery 1.10.2 -->
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/
jquery/1.10.2/jquery.min.js"></script>

<!-- url to sandbox MasterPass Lightbox -->
  <script type="text/javascript" src=" https://sandbox.masterpass.com/
lightbox/Switch/integration/MasterPass.client.js "></script>

<!-- url to production MasterPass Lightbox -->
  <!-- <script type="text/javascript" src=" https://masterpass.com/lightbox/
Switch/integration/MasterPass.client.js "></script> -->

Invoke the MasterPass lightbox when the user clicks the Buy with MasterPass button.

<script type="text/javascript" language="Javascript"> 
    MasterPass.client.checkout({ 
       "requestPairing":true,                                                      //required
       "requestToken":"insert_checkout_request_token_here",                        //required
       "pairingRequestToken":"insert_pairing_request_token_here",                  //required
       "callbackUrl":"http://www.somemerchant.com/checkoutcomplete.htm",           //required
       "merchantCheckoutId":"insert_checkout_id_here",                             //required
       "requestedDataTypes":["REWARD_PROGRAM", "ADDRESS", "PROFILE", "CARD"],      //required
       "allowedCardTypes":["master","amex","diners","discover","maestro","visa"],  //optional
       "version":"v6",                                                             //optional
       "successCallback": function(mpLightboxResponse){ ... },                     //optional
       "failureCallback": function(mpLightboxResponse){ ... },                     //optional
       "cancelCallback": function(mpLightboxResponse){ ... }                       //optional
    });
</script>
  • requestPairing: To enable pairing, value must be true.
  • requestToken: The checkout request token generated in Step 1.
  • pairingRequestToken: The pairing request token generated in Step 1.
  • callbackUrl: The merchant URL to which the browser will redirect when the Lightbox closes.
  • merchantCheckoutId: The unique checkout identifier obtained during the merchant onboarding process.
  • requestedDataTypes: The data types the merchant requests for pairing. PROFILE and CARD are required.
  • allowedCardTypes: Card types accepted by the merchant (default is all card types).
  • version: MasterPass API version (default is v6).
  • successCallback: The function that will be called if the MasterPass Lightbox flow ends successfully.
  • failureCallback: The function that will be called if the MasterPass Lightbox flow ends in failure.
  • cancelCallback: The function that will be called if the user cancels the MasterPass Lightbox flow.

5. Redirect to callback URL or call callback function

After the consumer completes checkout, MasterPass returns data to the merchant. By default, MasterPass redirects the browser to the callback URL, returning the data via URL parameters. Optionally, if callback functions were provided in Step 4, MasterPass returns control to the page that initiated the Lightbox, and the data is passed to the callback function.

Under certain conditions, the MasterPass UI may be forced to run in Full Screen display instead of launching the Lightbox. When this occurs, the browser will redirect to the callback URL when the MasterPass flow is complete, even if callback functions were supplied.

On success

On success, MasterPass returns the following parameters:

  • mpstatus: String that indicates whether the MasterPass flow resulted in success, failure, or cancel.
  • checkout_resource_url: The API URL that will be used to retrieve checkout information in Step 7.
  • oauth_verifier: The checkout verifier token that is used to retrieve the access token in Step 6.
  • oauth_token: The checkout request token that is used to retrieve the access token in Step 6. This token has the same value as the checkout request token that is generated in Step 1.
  • pairing_verifier: The pairing verifier token that is used to retrieve the long access token in Step 6.
  • pairing_token: The pairing request token used to retrieve the long access token in Step 6.

Example Callback URL (Success)

http://www.somemerchant.com/checkoutcomplete.htm
?mpstatus=success
&checkout_resource_url=https%3A%2F%2Fstage.api.mastercard.com%2Fmasterpass%2Fv6%2Fcheckout%2F
10706241%3Fwallet%3Dphw
&oauth_verifier=fbe45bcad30299c93765b1fb4b45bab208f84458
&oauth_token=d9382e34e0721a68a9952110cecdf89517e45498
&pairing_verifier=6c50838e31b7441e6eafa2229385452889255b13
&pairing_token=35b2a0cf87f8160fcb5d24996a12edb7cce4c530

Example Callback URL (Cancel)

http://www.somemerchant.com/checkoutcomplete.htm
?mpstatus=cancel

Example Callback URL (Failure)

http://www.somemerchant.com/checkoutcomplete.htm
?mpstatus=failure

6. Call Access Token Service (2 times)

If the checkout was completed successfully, the next step is to make two Access Token Service calls. The first call uses the checkout request token and the checkout verifier token from Step 5 to retrieve a checkout access token. This checkout access token will be used in the next step to retrieve checkout data from the current transaction.

The second call uses the pairing request token and the pairing verifier token from Step 5 to retrieve a long access token. The long access token will be used to retrieve pre-checkout data for this consumer in future transactions.

public void accessTokenService_returnsToken() throws Exception {
    AccessTokenResponse checkoutAccessTokenResponse = AccessTokenService.create(Auth.auth(oauth_checkout_request_token),Auth.auth(oauth_checkout_verifier_token));
    String checkout_accessToken = checkoutAccessTokenResponse.getOauthToken();
    
    AccessTokenResponse longAccessTokenResponse = AccessTokenService.create(Auth.auth(oauth_pairing_request_token),Auth.auth(oauth_pairing_verifier_token));
    String long_accessToken = longAccessTokenResponse.getOauthToken();
}

7. Retrieve payment, shipping data, rewards and 3DS details

Use the checkout resource URL received in Step 5 and the checkout access token from Step 6 to retrieve the consumer’s payment, shipping, reward and 3-D Secure information from MasterPass.

//TEMPORARY This is going to change to use checkout resource url
 Checkout checkout = CheckoutApi.show(checkoutid, Auth.auth(accessToken));
 
 Card card = checkout.getCard();
 Address billingAddress = card.getBillingAddress();
 Contact contact = checkout.getContact();
 AuthenticationOptions authOptions = checkout.getAuthenticationOptions(); //result of 3DS verification
 String preCheckoutTransactionId = checkout.getPreCheckoutTransactionId(); 
 RewardProgram rewardProgram = checkout.getRewardProgram(); 
 ShippingAddress shippingAddress = checkout.getShippingAddress();
 String transactionId = checkout.getTransactionId();
 String walletId = checkout.getWalletID();

8. Process payment through a payment gateway

Using the data retrieved in Step 7, process the payment through the merchant's payment gateway.

9. Log transactions with MasterPass

After the payment has been processed in Step 8, make a service call to communicate the result of the transaction to MasterPass.

//Create an instance of MerchantTransactions
MerchantTransactions request = new MerchantTransactions()
        .merchantTransactions(new MerchantTransactions()
            .transactionId(4549794)                       //from Step 7
            .purchaseDate("2014-08-01T14:52:57.539-05:00")
            .expressCheckoutIndicator(false)
            .approvalCode("888888")                       // authorization code returned by payment gateway
            .transactionStatus("Success")
            .orderAmount(1229)
            .preCheckoutTransactionId("a4a6x55-rgb1c5-hyaqkemj-1-hybxhplo-947") //from Step 7
            .currency("USD")
            .consumerKey("0zMKpm0nFtUv8lLXT97jDRo2bp4vNF8MFYyt3R5R87e3f3f4!414b48675861677159682b563745776b593652377939673d")); //generated during onboarding process

//Call the PostbackService with required params
MerchantTransactions response = PostbackService.create(request);

Pairing without Checkout

1. Call Request Token Service

Call the Request Token Service to generate the pairing request token that will be used to invoke the MasterPass Lightbox. Pass a callback_url that the browser will redirect to when the Lightbox closes.

The Request Token Service must be called before the consumer clicks the Connect with MasterPass button.

String callback_url = "https://www.somemerchant.com/pairingcomplete.htm"
RequestTokenResponse requestTokenResponse = RequestTokenService.create(Auth.auth(callback_url));
String pairing_request_token = requestTokenResponse.getOauthToken();

2. Call Merchant Initialization Service

The Merchant Initialization Service is used to secure Lightbox connections between the merchant site and MasterPass. The originUrl identifies the origin of the page that will initialize the Lightbox. This service requires the pairing request token from Step 1.

//Create an instance of MerchantInitializationRequest
MerchantInitializationRequest merchantInitializationRequest = new MerchantInitializationRequest()
        .originUrl("https://somemerchant.com")
        .oAuthToken(pairing_request_token);

//Call the MerchantInitializationApi with required params
MerchantInitializationResponse merchantInitializationResponse = MerchantInitializationService.create(merchantInitializationRequest);

3. Invoke MasterPass UI (Lightbox) for pairing

Add the Connect with MasterPass button to the merchant site (for example, on the user account page) (see MasterPass Branding to customize size and locale).

<img src="https://www.mastercard.com/mc_us/wallet/img/en/US/mp_connect_with_button_126px.png"/>

Import jQuery, and add the MasterPass Integration Script for either the sandbox or the production environment.

<!-- url to jquery 1.10.2 -->
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/
jquery/1.10.2/jquery.min.js"></script>

<!-- url to sandbox MasterPass Lightbox -->
 <script type="text/javascript" src=" https://sandbox.masterpass.com/
lightbox/Switch/integration/MasterPass.client.js "></script>

<!-- url to production MasterPass Lightbox -->
 <!-- <script type="text/javascript" src=" https://masterpass.com/lightbox/
Switch/integration/MasterPass.client.js "></script> -->

Invoke the MasterPass lightbox when the user clicks the Connect with MasterPass button.

<script type="text/javascript" language="Javascript"> 
    MasterPass.client.connect({ 
       "requestPairing":true,                                            //required
       "pairingRequestToken":"insert_pairing_request_token_here",        //required
       "callbackUrl":"http://www.somemerchant.com/pairingcomplete.htm", //required
       "merchantCheckoutId":"insert_checkout_id_here",                   //required
       "requestedDataTypes":["REWARD_PROGRAM", "ADDRESS", "PROFILE", "CARD"],  //required
       "version":"v6"                                                    //optional
       "successCallback": function(mpLightboxResponse){ ... },           //optional
       "failureCallback": function(mpLightboxResponse){ ... },           //optional
       "cancelCallback": function(mpLightboxResponse){ ... }             //optional
    });
</script>
  • requestPairing: To enable pairing, value must be true.
  • pairingRequestToken: Your pairing request token generated in Step 1.
  • callbackUrl: The merchant URL to which the browser will redirect when the Lightbox closes.
  • merchantCheckoutId: The unique checkout identifier obtained during the Merchant Onboarding process.
  • requestedDataTypes: The data types the merchant requests for pairing. PROFILE and CARD are required.
  • version: MasterPass API version (default is v6).
  • successCallback: The function that will be called if the MasterPass flow ends successfully.
  • failureCallback: The function that will be called if the MasterPass flow ends in failure.
  • cancelCallback: The function that will be called if the user cancels the MasterPass flow.

4. Redirect to callback URL or call callback function

After the lightbox closes, MasterPass returns data to the merchant. By default, MasterPass redirects the browser to the callback URL, returning the data via URL parameters. Optionally, if callback functions were provided in Step 4, MasterPass returns control to the page that initiated the Lightbox, and the data is passed to the callback function.

Under certain conditions, the MasterPass UI may be forced to run in Full Screen display instead of launching the Lightbox. When this occurs, the browser will redirect to the callback URL when the MasterPass flow is complete, even if callback functions were supplied.

Example Callback URL (Success)

On Success, MasterPass returns the following parameters:

  • mpstatus: String that indicates whether the MasterPass flow resulted in success, failure, or cancel.
  • pairing_verifier: The pairing verifier token that is used to retrieve the long access token in Step 6.
  • pairing_token: The pairing request token used to retrieve the long access token in Step 6.
http://www.somemerchant.com/pairingcomplete.htm
?mpstatus=success
&pairing_verifier=6c50838e31b7441e6eafa2229385452889255b13
&pairing_token=35b2a0cf87f8160fcb5d24996a12edb7cce4c530

Example Callback URL (Cancel)

http://www.somemerchant.com/pairingcomplete.htm
?mpstatus=cancel

Example Callback URL (Failure)

http://www.somemerchant.com/pairingcomplete.htm
?mpstatus=failure

Example Callback Function (Success)

function handleCallbackSuccess (data) {
    document.getElementById('pairingToken').value=data.pairing_token;
    document.getElementById('pairingVerifer').value=data.pairing_verifier;
}

5. Call Access Token Service

If the pairing was completed successfully, call the Access Token Service to retrieve a long access token. You will need the pairing request token and the pairing verifier token received in Step 4.

The long access token will be used to retrieve pre-checkout data for this consumer in the future. Store the long access token with this user's merchant account data so that it can be retrieved anytime the user logs into the merchant site.

AccessTokenResponse accessTokenResponse = AccessTokenService.create(Auth.auth("oauth_pairing_request_token"),Auth.auth("oauth_pairing_verifier_token"));
String long_accessToken = accessTokenResponse.getOauthToken();

Checkout after Pairing

1. Consumer logs onto merchant site

A consumer's long access token should have been stored with their account data for the merchant's site. When the consumer logs into their merchant site account, get their long access token.

2. Call PreCheckout Data Service

Use the consumer's long access token to retrieve pre-checkout data. The data types returned will be the types that were requested via the requestedDataTypes parameter when the Lightbox was invoked (Step 4 of Pairing During Checkout or Step 3 of Pairing Without Checkout).

String[] requestedDataTypes = {"REWARD_PROGRAM", "ADDRESS", "PROFILE", "CARD"};

PrecheckoutDataRequest preCheckoutDataRequest = new PrecheckoutDataRequest();
PairingDataTypes pairingDataTypes = new PairingDataTypes();
for(var i = 0; i < requestedDataTypes.length; i++){
    pairingDataTypes.PairingDataType(new PairingDataType().type(TypeEnum.valueOf(requestedDataTypes[i])));
}
preCheckoutDataRequest.pairingDataTypes(pairingDataTypes);

PrecheckoutDataResponse response = PrecheckoutDataApi.create(Auth.auth(longAccessToken), preCheckoutDataRequest);

3. Consumer makes card/shipping address selection

Display the wallet data retrieved in Step 2 to the consumer, and prompt the consumer to select from it. Save the selected cardId, shippingId, and (if applicable) rewardId to be used on the Place Order page of the merchant site.

4. Call Request Token Service

Call the Request Token Service to generate the request token that will be used to invoke the MasterPass Lightbox. Pass a callback_url that the browser will redirect to when the Lightbox closes.

The Request Token Service must be called before creating the Buy with MasterPass button.

String callback_url = "https://www.somemerchant.com/checkoutconfirm.htm"
RequestTokenResponse requestTokenResponse = RequestTokenService.create(Auth.auth(callback_url));
String request_token = requestTokenResponse.getOauthToken();

5. Call Shopping Cart Service

The Shopping Cart Service enables shopping cart data to be displayed to users as they proceed through the MasterPass login and checkout. This service requires the request token from Step 4.

Each ShoppingCartItem must have a description, quantity, and value. Value is represented as an integer (for example, USD 100.00 is 10000), and is calculated as the cost of a single item multiplied by the quantity of that item. A ShoppingCartItem may also have an optional imageURL.

The Shopping Cart Service must be called before creating the Buy with MasterPass button.

//Create an instance of ShoppingCartRequest
ShoppingCartRequest shoppingCartRequest = new ShoppingCartRequest()
        .shoppingCart(new ShoppingCart()
            .subtotal(11900)
            .currencyCode("USD")
            .shoppingCartItem(new ShoppingCartItem()
                .value(1900)
                .description("This is one item")
                .quantity(1))

            .shoppingCartItem(new ShoppingCartItem()
                .imageURL("https://somemerchant.com/someimage")
                .value(10000)
                .description("Five items")
                .quantity(5)))
        .oAuthToken(request_token);

//Call the ShoppingCartService with required params
ShoppingCartResponse shoppingCartResponse = ShoppingCartService.create(shoppingCartRequest);

6. Call Merchant Initialization Service

The Merchant Initialization Service is used to secure Lightbox connections between the merchant site and MasterPass. The originUrl identifies the origin of the page that will invoke the Lightbox. This service requires the request token from Step 4.

The Merchant Initialization Service must be called before creating the Buy with MasterPass button.

//Create an instance of MerchantInitializationRequest
MerchantInitializationRequest merchantInitializationRequest = new MerchantInitializationRequest()
        .originUrl("https://somemerchant.com")
        .oAuthToken(request_token);

//Call the MerchantInitializationApi with required params
MerchantInitializationResponse merchantInitializationResponse = MerchantInitializationService.create(merchantInitializationRequest);

7. Create Buy With MasterPass Button

Import jQuery, and add the MasterPass Integration Script for either the sandbox or the production environment

 <!-- url to jquery 1.10.2 -->
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/
jquery/1.10.2/jquery.min.js"></script>

<!-- url to sandbox MasterPass Lightbox -->
 <script type="text/javascript" src=" https://sandbox.masterpass.com/
lightbox/Switch/integration/MasterPass.client.js "></script>

<!-- url to production MasterPass Lightbox -->
 <!-- <script type="text/javascript" src=" https://masterpass.com/lightbox/
Switch/integration/MasterPass.client.js "></script> -->

On the Place Order page of the merchant's website, create the Buy with MasterPass button using the cardId, addressId, and rewardId from Step 3 and the request token from Step 4.

<script type="text/javascript" language="Javascript">
MasterPass.client.checkout({
     "requestToken":"insert_request_token_here",                       //required
     "callbackUrl":"http://www.somemerchant.com/checkoutcomplete.htm", //required
     "merchantCheckoutId":"insert_checkout_id_here",                   //required
     "cardId":"insert_selected_card_id_here",                          //required
     "shippingId":"insert_selected_shipping_address_id_here",          //required
     "precheckoutTransactionId":"insert_prechechout_txn_id_here",      //required
     "walletName":"insert_wallet_name_here",                           //required
     "consumerWalletId":"insert_consumer_walletid_here",               //required
     "loyaltyId":"insert_loyalty_id_here",                             //optional
     "requireShippingDestination": "true"                              //optional                                                                                                                                                                 
     "version":"v6",                                                   //optional
     "successCallback": function(mpLightboxResponse){ ... },           //optional
     "failureCallback": function(mpLightboxResponse){ ... },           //optional
     "cancelCallback": function(mpLightboxResponse){ ... }             //optional
});
</script>
  • requestToken: The request token generated in Step 4.
  • callbackUrl: The merchant URL to which the browser will redirect when the Lightbox closes.
  • merchantCheckoutId: The unique checkout identifier obtained during the Merchant Onboarding process.
  • cardId: The identifier of the selected card collected in Step 3.
  • shippingId: The identifier of the shipping information collected in Step 3.
  • precheckoutTransactionId: The pre-checkout transaction identifier collected in Step 3.
  • walletName: The consumer's wallet name collected in Step 3.
  • consumerWalletId: The consumer's wallet identifier collected in Step 3.
  • loyaltyId: The rewardId, optionally collected in Step 3.
  • requireShippingDestination: Denotes whether the consumer's shipping information is required.
  • version: MasterPass API version (default is v6).
  • successCallback: The function that will be called if the MasterPass flow ends successfully.
  • failureCallback: The function that will be called if the MasterPass flow ends in failure.
  • cancelCallback: The function that will be called if the user cancels the MasterPass flow.

8. Redirect to callback URL or call callback function

After the consumer completes checkout, MasterPass returns data to the merchant. By default, MasterPass redirects the browser to the callback URL, returning the data via URL parameters. Optionally, if callback functions were provided in Step 4, MasterPass returns control to the page that initiated the Lightbox, and the data is passed to the callback function.

Under certain conditions, the MasterPass UI may be forced to run in Full Screen display instead of launching the Lightbox. When this occurs, the browser will redirected to the callback URL when the MasterPass flow is complete, even if callback functions were supplied.

on Success

On Success, MasterPass returns the following parameters:

  • mpstatus: String that indicates whether the MasterPass flow resulted in success, failure, or cancel.
  • checkout_resource_url: The API URL that will be used to retrieve checkout information in Step 10.
  • oauth_verifier: The verifier token that is used in conjunction with the request token to retrieve the access token in Step 9.
  • oauth_token: The request token that is used in conjunction with the verifier token to retrieve the access token in Step 9. This token has the same value as the request token that is generated in Step 1.

Example Callback URL (Success)

http://www.somemerchant.com/checkoutcomplete.htm
?mpstatus=success
&checkout_resource_url=https%3A%2F%2Fsandbox.api.mastercard.com%2Fmasterpass\%2Fv6%2Fcheckout%2F10189977%3Fwallet%3Dphw
&oauth_verifier=6c50838e31b7441e6eafa2229385452889255b13
&oauth_token=d6fa60984308aebb6183d44fb9688fb9dc8332dc

Example Callback URL (Cancel)

http://www.somemerchant.com/checkoutcomplete.htm
?mpstatus=cancel

Example Callback URL (Failure)

http://www.somemerchant.com/checkoutcomplete.htm
?mpstatus=failure

Example Callback Function (Success)

function handleCallbackSuccess (data) {
    callYourServerWith(data.oauth_token, data.oauth_verifier, data.checkout_resource_url);
}

9. Call Access Token Service

If the checkout was completed successfully, call the Access Token Service to retrieve an access token. You will need the request token and the verifier token received in Step 8.

As there is no need to retrieve a long access token again, only this one call to the Access Token Service will be made.

public void accessTokenService_returnsToken() throws Exception {
    AccessTokenResponse accessTokenResponse = AccessTokenService.create(Auth.auth(request_token), Auth.auth(verifier_token));
    String accessToken = accessTokenResponse.getOauthToken();
}

10. Retrieve Payment, Shipping Data, Rewards and 3-D Secure Details

Use the Checkout Resource URL received in Step 8 and the access token from Step 9 to retrieve the constomer’s payment, shipping, reward and 3-D Secure information from MasterPass.

//TEMPORARY This is going to change to use checkout resource url
 Checkout checkout = CheckoutApi.show(checkoutid, Auth.auth(accessToken));
 
 Card card = checkout.getCard();
 Address billingAddress = card.getBillingAddress();
 Contact contact = checkout.getContact();
 AuthenticationOptions authOptions = checkout.getAuthenticationOptions(); 
 String preCheckoutTransactionId = checkout.getPreCheckoutTransactionId(); 
 RewardProgram rewardProgram = checkout.getRewardProgram(); 
 ShippingAddress shippingAddress = checkout.getShippingAddress();
 String transactionId = checkout.getTransactionId();
 String walletId = checkout.getWalletID();

11. Process Payment through a payment gateway

Using the data retrieved in Step 10, process the payment through the merchant's payment gateway.

12. Log Transactions with MasterPass

After the payment has been processed in Step 11, make a service call to communicate the result of the transaction to MasterPass.

//Create an instance of MerchantTransactions
MerchantTransactions request = new MerchantTransactions()
        .merchantTransactions(new MerchantTransaction()
            .transactionId(4549794)
            .purchaseDate("2014-08-01T14:52:57.539-05:00")
            .expressCheckoutIndicator(false)
            .approvalCode("888888") // from your payment gateway authorization
            .transactionStatus("Success")
            .orderAmount(1229) // total charged to card
            .preCheckoutTransactionId("a4a6x55-rgb1c5-hyaqkemj-1-hybxhplo-947")
            .currency("USD")
            .consumerKey("0zMKpm0nFtUv8lLXT97jDRo2bp4vNF8MFYyt3R5R87e3f3f4!414b48675861677159682b563745776b593652377939673d"));

//Call the PostbackService with required params
MerchantTransactions response = PostbackService.create(request);

C#

Ruby

PHP