Refund Query Sample
Take a look at the things you can do with our APIs

This code sample is used to query an existing Refund in OpenAPI. This implies that you've already created a Refund (see Refund Create Sample) and have recorded the TransactionId. For more information on Refund, why you would query it, and a complete service parameter breakdown, see the documentation here: [+Refund (Query)]

At the beginning of the method, we create a number of instance variables. Most of them normally would be supplied to this method in another way, usually from your user interface. The endPoint variable is pointing at the sandbox, so you would need to change this value when you are ready to use production.

This code depends on the code for the createOpenAPIConnection method found here: Java OAuth Sample Code

/*
 *  Queries a Refund in OpenAPI.
 */
public void queryRefund() {

	// Most of these values would normally be passed into the method.
	final String companyId = "changeme";
	final String companyPassword = "changeme";
	final String transactionId = "12345"; // Should be the transactionId of a Capture you created earlier.

	final String refundQueryEndPoint = "https://sandbox.api.mastercard.com/payments/v1/refund/" + transactionId + "?Format=XML&CompanyId=" + companyId + "&CompanyPassword=" + companyPassword;

	try {
		HttpsURLConnection conn = createOpenAPIConnection(refundQueryEndPoint, null);

		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		Document refundQueryDoc = docBuilder.parse(conn.getInputStream());

		if (refundQueryDoc.getFirstChild().getNodeName().equals("Refund")) {
			// Test for approval.
			if(refundQueryDoc.getElementsByTagName("TransactionResponse").item(0).getTextContent().equals("APPROVED")) {
				System.out.println("Refund queried successfully");
			}
		} else {
			if (refundQueryDoc.getFirstChild().getNodeName().equals("Errors")) {
				System.out.println("Error: " + refundQueryDoc.getElementsByTagName("Description").item(0).getTextContent());
			} else {
				System.out.println("Unknown Problem");
			}
		}

	} catch (MalformedURLException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} catch (ParserConfigurationException e) {
		e.printStackTrace();
	} catch (SAXException e) {
		e.printStackTrace();
	} catch (NoSuchAlgorithmException e) {
		e.printStackTrace();
	} catch (InvalidKeySpecException e) {
		e.printStackTrace();
	} catch (OAuthException e) {
		e.printStackTrace();
	} catch (KeyStoreException e) {
		e.printStackTrace();
	} catch (CertificateException e) {
		e.printStackTrace();
	} catch (UnrecoverableKeyException e) {
		e.printStackTrace();
	} catch (KeyManagementException e) {
		e.printStackTrace();
	}
}

© 1994-2014. MasterCard. All rights reserved.