PUT Commit a Transaction

PUT /disbursement/v1/transactions/{transactionId}/commit

Development Guide

The 'Commit a Transaction' endpoint executes the transactionId and completes the transfer of funds.



1. Prepare headers & authentication:

The application must call the 'Commit a transaction' endpoint with a PUT HTTP method, providing the OAuth access_token and all other required header values.


Note: MoneyGram uses the OAuth 2.0 framework. The application must use their OAuth client credentials to generate an access_token by calling the Get access token endpoint. The token is valid for 1 hour and must be passed as a header value in all subsequent API HTTP calls. Learn More


🚀

Launch Code Example




2. Provide the transactionId resource as a path parameter and prepare the request body:

The application must persist the transactionId from the Update or Create a transaction endpoint and apply it as a path parameter to the Commit a transaction endpoint.


🚀

Launch Code Example




3. Display 'Fraud Warnings' & 'Pre-disclosure' in application UI:

It is a regulatory requirement to display Fraud Warnings (US Only, Global) and a Pre-Payment Disclosure to the consumer before the transfer of funds is executed. Both the Fraud Warnings and Pre-payment Disclosure must be displayed for all transactions (i.e. in all send countries, for all amounts, for all service options).




4. Make a request and handle the response:

The application must call the 'Commit a transaction' endpoint with a PUT HTTP method. The application must build to handle the following response scenarios:


  • Success | Parse the Response | 200 OK HTTP Status
    When the 'Commit a transaction' endpoint responds with a 200 HTTP Status the application has finalized and executed the transfer. The response payload, will return the following fields referenceNumber, and expectedPayoutDate. The funds are marked for "settlement" on the MoneyGram ledger.

  • Failed | Handle the Error | 400 Bad Request HTTP Status
    When the 'Commit a transaction' endpoint responds with 400 Bad Request HTTP Status a specific error message/s will be returned. The application will need to resolve these errors and resubmit the transaction for commit.

🚀

Launch Code Example

.




5. You're Done! Communicate the reference number to consumer:

It is recommended to prominently display the referenceNumber on the application UI and send a notification to the consumer and provide receipts




Code Examples

const axios = require('axios');
const { v4: uuidv4 } = require('uuid');

const commitTransaction = async () => {

    // Step 1: Read configuration values with upmost security
    const token = "your_access_token_from_oauth_response"
    // For production - api.moneygram.com & For test - sandboxapi.moneygram.com    
    const host = "sandboxapi.moneygram.com";
    const transactionId = "current_transaction_id";
    const url = 'https://' + host + '/disbursement/v1/transactions/' + transactionId + '/commit';

    // Step 2: Create the PUT request headers & body
    const headers = {
        'Content-Type': 'application/json',
        'X-MG-ClientRequestId': uuidv4(), // New UUID for each request tracing
        'Authorization': 'Bearer ' + token,
    };
    const request = {
        partnerTransactionId: ""
    }

    try {
        // Step 3: Send the request and obtain the response
        axios.put(url, request, { headers })
            .then(function (response) {
                // Step 4: Parse the success response and process further
                console.log(JSON.stringify(response.data, null, 2))
            })
            .catch(function (error) {
                // Step 5: Parse the error response and handle the errors
                if (error.response) {
                    console.log('Response status:', error.response.status);
                    console.log('Response body:', error.response.data);
                } else {
                    // TODO: handle generic errors
                    console.error('Error:', error.message);
                }
            });
    } catch (error) {
        // TODO: handle exception
        console.error('Error:', error.message);
    }
};

commitTransaction();
import requests
import uuid
import json

def commit_transaction():

    # Step 1: Read configuration values with upmost security
    token = "your_access_token_from_oauth_response"
    # For production - api.moneygram.com & For test - sandboxapi.moneygram.com    
    host = "sandboxapi.moneygram.com";
    transactionId = "current_transaction_id";
    url = 'https://' + host + '/disbursement/v1/transactions/' + transactionId + '/commit';

    # Step 2: Create the PUT request headers & body
    headers = {
        'Content-Type': 'application/json',
        'X-MG-ClientRequestId': str(uuid.uuid4()), # New UUID for each request tracing
        'Authorization': 'Bearer ' + token,
    }
    request = {
        'partnerTransactionId': ''
    }

    try:
        # Step 3: Send the request and obtain the response
        response = requests.put(url, json=request, headers=headers)

        # Step 4: Parse the success response and process further
        if response.status_code == 200:
            parsed_response = json.dumps(json.loads(response.text), indent=2)
            print(parsed_response)
        else:
            # Step 5: Parse the error response and handle the errors
            print("Request failed with status code:", response.status_code)
            print(json.dumps(json.loads(response.text), indent=2))

    except requests.exceptions.RequestException as e:
        # Print any error that occurred during the request
        # TODO: handle exception
        print("An error occurred:", e)

commit_transaction()
package disbursement;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonWriter;
import java.io.StringWriter;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.UUID;

public class CommitTransaction {

    public static void main(String[] args) {
        // Step 1: Read configuration values with upmost security
        String token = "your_access_token_from_oauth_response";

        // For production - api.moneygram.com & For test - sandboxapi.moneygram.com
        String host = "sandboxapi.moneygram.com";
        String transactionId = "current_transaction_id";
        String tokenEndpoint = "https://" + host + "/disbursement/v1/transactions/" + transactionId + "/commit";

        // Step 2: Create the PUT request headers & body
        // Create a JSON object
        JsonObjectBuilder requestBuilder = Json.createObjectBuilder()
                .add("partnerTransactionId", "");

        JsonObject jsonObject = requestBuilder.build();
        // Create a StringWriter to write the JSON string
        StringWriter stringWriter = new StringWriter();
        try (JsonWriter jsonWriter = Json.createWriter(stringWriter)) {
            jsonWriter.writeObject(jsonObject);
        }
        // Get the JSON string from the StringWriter
        String jsonString = stringWriter.toString();

        HttpClient httpClient = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(tokenEndpoint))
                .PUT(HttpRequest.BodyPublishers.ofString(jsonString))
                .setHeader("Authorization", "Bearer " + token)
                .setHeader("X-MG-ClientRequestId", String.valueOf(UUID.randomUUID()))
                .build();

        try {
            // Step 3: Send the request and obtain the response
            HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());

            // Retrieve the status code and body from the response
            int statusCode = response.statusCode();

            // Step 4: Parse the success response and process further
            if (statusCode == 200) {
                String responseBody = response.body();
                System.out.println(responseBody);
            } else {
                // Step 5: Parse the error response and handle the errors
                String responseBody = response.body();
                System.out.println(responseBody);
            }
        } catch (Exception e) {
            e.printStackTrace();
            // TODO: handle exception
        }
    }
}



Support APIs

To make your development easier, MoneyGram has provided a Reference Data APIs Module that can be queried to provide a list of supported fields, values and associated meta-data to use in your integration.


NameHTTP MethodEndpointsDescription
Retrieve EnumerationsGET/reference-data/v1/enumerationsRetrieves enumerated values for fields



API Structure


Header Parameters

NameRequired
/Optional
TypeDescription
X-MG-ClientRequestIdRequiredStringClient Request ID that can be passed by the client application. Client request ID must be unique within a single session for unique requests. This attribute can be used for ensuring idempotent request processing for some APIs. MoneyGram recommends using a UUID for the value of this field.
X-MG-consumerIPAddressOptionalStringIP Address of the system initiating the session



Path Parameters

Path ParameterTypeRequired
/Optional
Description
transactionIdString
Max length: 36
RequiredUnique id of the transaction resource



Request Body Fields

FieldTypeRequired/
Optional
Description
partnerTransactionIdStringRequiredPartner’s unique session identifier
additionalDetailsDynamicOptionalDynamic field key/values



Response Fields

FieldTypeRequired/
Optional
Description
referenceNumberString
Max length: 8
RequiredMoneyGram's reference number for the transaction
partnerTransactionIdStringRequiredPartners Unique identifier for the transaction resource
expectedPayoutDateStringRequiredExpected payout date (Example value - YYYY-MM-DD