Method for checkout when the purchase will be embedded within the external app. All sensitive data will be collected from the external application

 

Create a Config object and set API configuration parameters

Note that ipcApiUrl is different for sandbox and production environment

You can set RSA keys for request signatures by setting key content using loadPrivateKeyFromString and loadPublicKeyFromString or by setting file path using loadPrivateKeyFromFile and loadPublicKeyFromFile

import java.net.MalformedURLException; 
import java.net.URL; 

import com.mypos.myposcheckout.ipc.Config; 
import com.mypos.myposcheckout.ipc.IPCException; 

// ... 

Config cnf = new Config(); 

URL ipcApiUrl = null; 
try { 
    ipcApiUrl = new URL("https://mypos.com/vmp/checkout-test/"); 
} catch (MalformedURLException ex) { 
    // Handle the malformed URL exception 
} 

cnf.setIpcUrl(ipcApiUrl); 
cnf.setLang("en"); 
cnf.loadPrivateKeyFromFile("path_to_directory/storePrivateKey.pem"); // Replace `path_to_directory` with the actual file path 
cnf.loadPublicKeyFromFile("path_to_directory/apiPublicKey.pem"); // Replace `path_to_directory` with the actual file path 
cnf.setKeyIndex(1); 
cnf.setSid("000000000000010"); 
cnf.setVersion("1.4"); 
cnf.setWalletNumber("61938166610");


Create the public key object that is used to encrypt the sensitive data

import java.io.IOException; 
import java.security.NoSuchAlgorithmException; 
import java.security.PublicKey; 
import java.security.spec.InvalidKeySpecException; 

import com.mypos.myposcheckout.ipc.Helper; 
import com.mypos.myposcheckout.ipc.IPCException; 

// ... 

PublicKey iPayPublicKey; 

try { 
    iPayPublicKey = Helper.createPublicKeyFromString(Helper.readFile("path_to_directory/iPayPublicKey.pem")); // Replace `path_to_directory` with the actual file path 
} catch ( 
    InvalidKeySpecException | 
    IOException | 
    NoSuchAlgorithmException ex 
) { 
    throw new IPCException("Unable to load the iPay public key.", ex); 
}


Create a Cart object and set the cart items

import com.mypos.myposcheckout.ipc.Cart; 
import com.mypos.myposcheckout.ipc.CartItem; 
import com.mypos.myposcheckout.ipc.IPCException; 

// ... 

Cart cart = new Cart(); 
cart.addItem(new CartItem("Some Book", 101.23, 2)); 
cart.addItem(new CartItem("Some other book", 1.25, 8)); 
cart.addItem(new CartItem("Stuff", 0.63, 5)); 
cart.addItem(new CartItem("Discount", -5.3, 1));


Create IAPurchase object using Config object and set required params

import com.mypos.myposcheckout.ipc.IPCException; 
import com.mypos.myposcheckout.ipc.enumerable.CardType; 
import com.mypos.myposcheckout.ipc.enumerable.CommunicationFormat; 
import com.mypos.myposcheckout.ipc.enumerable.Currency; 
import com.mypos.myposcheckout.ipc.request.InAppPurchase; 

// ... 

InAppPurchase inAppPurchase = new InAppPurchase(cnf); 
inAppPurchase.setOrderId("126ca831-93d2-4dfc-ab1f-0cce1d0abe9e"); 
inAppPurchase.setCurrency(Currency.EUR); 
inAppPurchase.setCardholderName("John Doe"); 
inAppPurchase.setCardType(CardType.VISA); 
inAppPurchase.setEci(1); 
inAppPurchase.setCart(cart); 
inAppPurchase.setOutputFormat(CommunicationFormat.XML);


Set the parameters containing sensitive data

import java.io.UnsupportedEncodingException; 
import java.security.InvalidKeyException; 
import java.security.NoSuchAlgorithmException; 
import javax.crypto.BadPaddingException; 
import javax.crypto.IllegalBlockSizeException; 
import javax.crypto.NoSuchPaddingException; 

import com.mypos.myposcheckout.ipc.Helper; 
import com.mypos.myposcheckout.ipc.IPCException; 
import com.mypos.myposcheckout.ipc.request.InAppPurchase; 

// ... 

try { 
    inAppPurchase.setPan(Helper.encryptStringWithPublicKey("4111111111111111", iPayPublicKey)); 
    inAppPurchase.setExpirationDate(Helper.encryptStringWithPublicKey("12/22", iPayPublicKey)); 
    inAppPurchase.setCvc(Helper.encryptStringWithPublicKey("123", iPayPublicKey)); 
} catch ( 
    BadPaddingException | 
    IllegalBlockSizeException | 
    InvalidKeyException | 
    NoSuchAlgorithmException | 
    NoSuchPaddingException | 
    UnsupportedEncodingException ex 
) { 
    throw new IPCException("Unable to encrypt sensitive data fields.", ex); 
}


Process request

import com.mypos.myposcheckout.ipc.IPCException; 
import com.mypos.myposcheckout.ipc.enumerable.StatusCode; 
import com.mypos.myposcheckout.ipc.response.BasicResponse; 

// ... 

BasicResponse ipcResponse = inAppPurchase.process(); 
ipcResponse.processApiResponse(); 
if (ipcResponse.getStatusCode() == StatusCode.SUCCESS) { 
    // Success 
}