Pre-Authorization Request

1. Perform the Pre-Authorization

// Build the preauth request
MyPOSPreauthorization preauth = MyPOSPreauthorization.builder()
	// Mandatoy parameters
        .productAmount(1.23)
        .currency(Currency.EUR)
        .foreignTransactionId(UUID.randomUUID().toString())
	// Optional parameters
	// Reference number. Maximum length: 20 alpha numeric characters
	.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
        // Set print receipt mode
	.printMerchantReceipt(MyPOSUtil.RECEIPT_ON)
	.printCustomerReceipt(MyPOSUtil.RECEIPT_ON)
        .build();
	
// If you want to initiate a moto transaction:
payment.setMotoTransaction(true)

// Start the transaction
MyPOSAPI.createPreauthorization(MainActivity.this, preauth, PREAUTH_REQUEST_CODE);

 

2. Perform the Pre-Authorization Completion

// Build the preauth completion
MyPOSPreauthorizationCompletion preauthCompletion = MyPOSPreauthorizationCompletion.builder()
	// Mandatory parameters
        .productAmount(1.23)
        .currency(Currency.EUR)
	.preauthorizationCode("1111")
        .foreignTransactionId(UUID.randomUUID().toString())
	// Optional parameters
	// Reference number. Maximum length: 20 alpha numeric characters
	.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
        // Set print receipt mode
	.printMerchantReceipt(MyPOSUtil.RECEIPT_ON)
	.printCustomerReceipt(MyPOSUtil.RECEIPT_ON)
        .build();

// Start the transaction
MyPOSAPI.completePreauthorization(MainActivity.this, preauthCompletion, PREAUTH_COMPLETION_REQUEST_CODE);

 

3. Perform the Pre-Authorization Cancellation

// Build the preauth cancellation
MyPOSPreauthorizationCancellation preauthCancellation = MyPOSPreauthorizationCancellation.builder()
	// Mandatoy parameters
	.preauthorizationCode("1111")
        .foreignTransactionId(UUID.randomUUID().toString())
	// Optional parameters
	// Reference number. Maximum length: 20 alpha numeric characters
	.reference("asd123asd", ReferenceType.REFERENCE_NUMBER)
        // Set print receipt mode
	.printMerchantReceipt(MyPOSUtil.RECEIPT_ON)
	.printCustomerReceipt(MyPOSUtil.RECEIPT_ON)
        .build();

// Start the transaction
MyPOSAPI.cancelPreauthorization(MainActivity.this, preauthCancellation, PREAUTH_CANCELLATION_REQUEST_CODE);

 

4. Handle the result

In your calling Activity, override the onActivityResult method to handle the result of the payment:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // The same request code as when calling MyPOSAPI.createPreauthorization
    if (requestCode == PREAUTH_REQUEST_CODE) {
        // The transaction was processed, handle the response
        if (resultCode == RESULT_OK) {
            // Something went wrong in the Payment core app and the result couldn't be returned properly
            if (data == null) {
                Toast.makeText(this, "Transaction cancelled", Toast.LENGTH_SHORT).show();
                return;
            }
            int transactionResult = data.getIntExtra("status", TransactionProcessingResult.TRANSACTION_FAILED);

            Toast.makeText(this, "Pre-Auth transaction has completed. Result: " + transactionResult, Toast.LENGTH_SHORT).show();

            // TODO: handle each transaction response accordingly
            if (transactionResult == TransactionProcessingResult.TRANSACTION_SUCCESS) {
	    	String preauthCode = data.getStringExtra("preauth_code");
                // Transaction is successful
            }
        } else {
            // The user cancelled the transaction
            Toast.makeText(this, "Transaction cancelled", Toast.LENGTH_SHORT).show();
        }
    }
}

 

Read the pre-authorization code from transaction response:

String preauthCode = data.getStringExtra("preauth_code");