---
schema_version: "1"
id: c46244d7b4a42fcdbff7556d77a3b4540ee136e6856907eed047119bde818823
title: PaymentGatewayContext Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_commercepayments_PaymentGatewayContext.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4855b8521bfa25535e2f3de85ae37d536a07a3d1bbbeee4045bcf3b216f6e7e8
description: Wraps the information related to a payment request.Constructor to enable instance creation. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.Returns the payment request object.Returns the payment request type.
---
# PaymentGatewayContext Class

Wraps the information related to a payment request.

## Namespace

[CommercePayments](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_commercepayments.htm "Use the CommercePayments namespace to provide a safe and customizable platform for managing customer payments and refunds.")

## Usage

The constructor of this class takes no arguments. For example:

CommercePayments.PaymentGatewayContext pgc = new CommercePayments.PaymentGatewayContext();

## Example

global commercepayments.GatewayResponse processRequest(commercepayments.PaymentGatewayContext gatewayContext) {
    commercepayments.RequestType requestType = gatewayContext.getPaymentRequestType();
    if (requestType == commercepayments.RequestType.Capture) {
        commercepayments.CaptureRequest captureRequest = (commercepayments.CaptureRequest) gatewayContext.getPaymentRequest();
    }
}

- **[PaymentGatewayContext Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_commerce_payments_PaymentGatewayContext_constructors)**
- **[PaymentGatewayContext Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_commerce_payments_PaymentGatewayContext_methods)**

## PaymentGatewayContext Constructors

The following are constructors for PaymentGatewayContext.

- **[PaymentGatewayContext(request, requestType)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_commerce_payments_PaymentGatewayContext_ctor)**  
    Constructor to enable instance creation. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

### PaymentGatewayContext(request, requestType)

Constructor to enable instance creation. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

#### Signature

global PaymentGatewayContext(commercepayments.PaymentGatewayRequest request, String requestType)

#### Parameters

- **request**: Type: commercepayments.PaymentGatewayRequest Raw payload. Sensitive attributes are masked to ensure PCI compliance.
- **requestType**: Type: [commercepayments.RequestType Enum](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_enum_commercepayments_RequestType.htm) Defines the type of request made to the gateway

## PaymentGatewayContext Methods

The following are methods for PaymentGatewayContext.

- **[getPaymentRequest()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_commerce_payments_PaymentGatewayContext_getPaymentRequest)**  
    Returns the payment request object.
- **[getPaymentRequestType()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercepayments_PaymentGatewayContext.htm#apex_commerce_payments_PaymentGatewayContext_getPaymentRequestType)**  
    Returns the payment request type.

### getPaymentRequest()

Returns the payment request object.

#### Signature

global commercepayments.PaymentGatewayRequest getPaymentRequest()

#### Return Value

Type: PaymentGatewayRequest

### getPaymentRequestType()

Returns the payment request type.

#### Signature

global String getPaymentRequestType()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")