# Scan and Parse QR Code
source: https://developer.mastercard.com/mastercard-merchant-presented-qr/documentation/server-apis/reference-app/scan-parse-qr-code/index.md

Now that you have the sample application running, let's understand how the sample application scans the QR code and parses the information in the QR code. MPQR Device SDKs simplify the scanning and parsing process.

![](https://static.developer.mastercard.com/content/mastercard-merchant-presented-qr/documentation/img/scan-and-parse-qr-code2.png)

### Scanning an MPQR-Compliant QR Code {#scanning-an-mpqr-compliant-qr-code}

The sample application uses the [Android QR Scan SDK](https://developer.mastercard.com/mastercard-merchant-presented-qr/documentation/device-sdks/android-qr-scan-sdk/index.md) to detect and scan a QR code with the device camera.

Sample Code located in "/app/src/main/java/com/mastercard/labs/sng/qrscantester/results/MainActivity.java" class:
* Java

```java
public void scanFromCamera(View view) { //shows the screen to scan QR code
    PPIntentIntegrator integrator = new PPIntentIntegrator(this);
    integrator.setOrientationLocked(false);
    integrator.setBeepEnabled(false);
    cameraScanStartTime = System.nanoTime();
    integrator.initiateScan();
}

public void pickImageFromAlbum(View view) { //upload QR code from Album
    Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
    innerIntent.setType("image/*");
    Intent wrapperIntent = Intent.createChooser(innerIntent, "Choose QR Code Picture");
    this.startActivityForResult(wrapperIntent, REQUEST_CODE_IMAGE);
}

/**
* Launched upon uploading or scanning an image, handles exceptions and deciphered data from QR Codes.
*
* @param requestCode type of request that is being sent
* @param resultCode  type of result that has been caught
* @param data        data contained in intent that has been passed
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CODE_IMAGE) {
            
        } else {
            Serializable qrData = data.getSerializableExtra(PPIntents.PUSH_PAYMENT_DATA);
            updateResult(null, qrData);
        }
    } else if (resultCode == RESULT_CANCELED) {
        if (data != null) {
            FormatException e = (FormatException) data.getSerializableExtra(PPIntents.PARSE_ERROR);
            if (e != null) {
                Serializable qrData = data.getSerializableExtra(PPIntents.PUSH_PAYMENT_DATA);
                updateResult(new ExceptionDetails(e), qrData);
                }
        }
    }

    this.getApplicationContext();
    getContentResolver();
    super.onActivityResult(requestCode, resultCode, data);
}
```

### Parsing a Previously-Scanned MPQR-Compliant QR Code {#parsing-a-previously-scanned-mpqr-compliant-qr-code}

Once a QR code is scanned and detected, our app passes the data from the QRScan SDK to the [Client Core SDK](https://developer.mastercard.com/mastercard-merchant-presented-qr/documentation/device-sdks/java-core-sdk/index.md). The Client Core SDK decodes the scanned image and returns an MPQR-compliant object. This object is required to perform the push payment.

Sample Code located in "/app/src/main/java/com/mastercard/labs/sng/qrscantester/results/MainActivity.java" class:
* Java

```java
private PaymentData paymentData(PushPaymentData pushPaymentData) { 
    //implementation to convert payment data model from sdk to app to be used in payment api request
    PaymentData.TipInfo tipInfo = null;
    double tip = 0;
    if (pushPaymentData.getTipOrConvenienceIndicator() != null) {
        switch (pushPaymentData.getTipOrConvenienceIndicator()) {
            case PushPaymentData.TipConvenienceIndicator.FLAT_CONVENIENCE_FEE:
                tipInfo = PaymentData.TipInfo.FLAT_CONVENIENCE_FEE;
                tip = pushPaymentData.getValueOfConvenienceFeeFixed();

                break;
            case PushPaymentData.TipConvenienceIndicator.PERCENTAGE_CONVENIENCE_FEE:
                tipInfo = PaymentData.TipInfo.PERCENTAGE_CONVENIENCE_FEE;
                tip = pushPaymentData.getValueOfConvenienceFeePercentage();

                break;
            case PushPaymentData.TipConvenienceIndicator.PROMPTED_TO_ENTER_TIP:
                tipInfo = PaymentData.TipInfo.PROMPTED_TO_ENTER_TIP;
                tip = 0;

                break;
        }
    }

    PaymentInstrument selectedPaymentInstrument = new PaymentInstrument();
    AdditionalData additionalData = pushPaymentData.getAdditionalData();

    return new PaymentData(101, selectedPaymentInstrument.getId(), true, pushPaymentData.getTransactionAmount(), tipInfo, tip, pushPaymentData.getTransactionCurrencyCode(), additionalData == null ? null : additionalData.getMobileNumber(), merchant(pushPaymentData));
}

private Merchant merchant(PushPaymentData pushPaymentData) { 
    // fetch merchant data from payment data
    Merchant merchant = new Merchant();

    merchant.setName(pushPaymentData.getMerchantName());
    merchant.setCity(pushPaymentData.getMerchantCity());
    merchant.setCategoryCode(pushPaymentData.getMerchantCategoryCode());
    merchant.setIdentifierVisa02(pushPaymentData.getMerchantIdentifierVisa02());
    merchant.setIdentifierVisa03(pushPaymentData.getMerchantIdentifierVisa03());
    merchant.setIdentifierMastercard04(pushPaymentData.getMerchantIdentifierMastercard04());
    merchant.setIdentifierMastercard05(pushPaymentData.getMerchantIdentifierMastercard05());
    merchant.setIdentifierNPCI06(pushPaymentData.getMerchantIdentifierNPCI06());
    merchant.setIdentifierNPCI07(pushPaymentData.getMerchantIdentifierNPCI07());
    if (pushPaymentData.getAdditionalData() != null) {
        merchant.setTerminalNumber(pushPaymentData.getAdditionalData().getTerminalId());
        merchant.setStoreId(pushPaymentData.getAdditionalData().getStoreId());
    }

    return merchant;
}
```

