This guide describes how to set up your Google Cloud project and API credentials to use the Merchant API.
1. Google Cloud Project Setup
Follow these steps to create a Google Cloud project and enable the Merchant API:
- Sign in to the Google Cloud Console.
- Create a new project (or select an existing one).
- From the navigation menu, select APIs & Services > Library.
- Search for "Payments".
- Select the Payments Merchant API tile.
- Click the Enable button.
2. Create API Credentials
To authorize your application, you must create a service account:
- On the Payments Merchant API page in Cloud Console, click the Create Credentials button.
- Select Application data as the type of data you will be accessing, and click **Next**.
- Fill in the service account name and ID.
- Click Create and Continue, then click Done.
- You can verify the newly created service account under the Credentials tab of the Payments Merchant API dashboard.
For additional information on using service accounts, see Using OAuth 2.0 for Server to Server Applications.
3. Set Up Your Local Environment
To test the API using the gcloud CLI, follow these steps to set up your local environment:
- Install the latest version of the gcloud CLI.
- Initialize the CLI and authenticate with your user account.
- Run the following commands to set up your shell environment variables, grant yourself the necessary roles, and enable required APIs.
Set Up Environment Variables
Replace the placeholders with your actual project ID and email:
GCP_PROJECT_ID="your-gcp-project-id" SERVICE_ACCOUNT="your-service-account@$GCP_PROJECT_ID.iam.gserviceaccount.com" USER_EMAIL="your-email@example.com"
Grant Service Account Token Creator Role
Grant yourself the roles/iam.serviceAccountTokenCreator role on the service account. This lets you impersonate the service account and generate short-lived access tokens.
gcloud iam service-accounts add-iam-policy-binding $SERVICE_ACCOUNT \ --member="user:$USER_EMAIL" \ --role="roles/iam.serviceAccountTokenCreator" \ --project "$GCP_PROJECT_ID"
Enable the IAM Service Account Credentials API
Enable the iamcredentials.googleapis.com API in your project, which is required for token generation:
gcloud services enable iamcredentials.googleapis.com --project "$GCP_PROJECT_ID"
Next Steps
Once your project is set up and credentials are created, you can proceed to the Integration Guide to start calling the API.