Skip to main content
POST
/
payment-methods
/
{payment_method_id}
/
payment-service-tokens
C#
using Gr4vy;
using Gr4vy.Models.Components;

var sdk = new Gr4vySDK(
    id: "example",
    server: SDKConfig.Server.Sandbox,
    bearerAuthSource: Auth.WithToken(privateKey),
    merchantAccountId: "default"
);

var res = await sdk.PaymentMethods.PaymentServiceTokens.CreateAsync(
    paymentMethodId: "ef9496d8-53a5-4aad-8ca2-00eb68334389",
    paymentServiceTokenCreate: new PaymentServiceTokenCreate() {
        PaymentServiceId = "fffd152a-9532-4087-9a4f-de58754210f0",
        RedirectUrl = "https://example.com/callback",
    }
);

// handle response
package main

import(
"context"
"os"
gr4vygo "github.com/gr4vy/gr4vy-go"
"github.com/gr4vy/gr4vy-go/models/components"
"log"
)

func main() {
ctx := context.Background()

s := gr4vygo.New(
gr4vygo.WithMerchantAccountID("default"),
gr4vygo.WithSecurity(os.Getenv("GR4VY_BEARER_AUTH")),
)

res, err := s.PaymentMethods.PaymentServiceTokens.Create(ctx, "ef9496d8-53a5-4aad-8ca2-00eb68334389", components.PaymentServiceTokenCreate{
PaymentServiceID: "fffd152a-9532-4087-9a4f-de58754210f0",
RedirectURL: "https://example.com/callback",
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
package hello.world;

import com.gr4vy.sdk.Gr4vy;
import com.gr4vy.sdk.models.components.PaymentServiceTokenCreate;
import com.gr4vy.sdk.models.errors.*;
import com.gr4vy.sdk.models.operations.CreatePaymentMethodPaymentServiceTokenResponse;
import java.lang.Exception;

public class Application {

public static void main(String[] args) throws Exception {

Gr4vy sdk = Gr4vy.builder()
.merchantAccountId("default")
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();

CreatePaymentMethodPaymentServiceTokenResponse res = sdk.paymentMethods().paymentServiceTokens().create()
.paymentMethodId("ef9496d8-53a5-4aad-8ca2-00eb68334389")
.paymentServiceTokenCreate(PaymentServiceTokenCreate.builder()
.paymentServiceId("fffd152a-9532-4087-9a4f-de58754210f0")
.redirectUrl("https://example.com/callback")
.build())
.call();

if (res.paymentServiceToken().isPresent()) {
System.out.println(res.paymentServiceToken().get());
}
}
}
declare(strict_types=1);

require 'vendor/autoload.php';

use Gr4vy;

$sdk = Gr4vy\SDK::builder()
->setId('example')
->setServer('sandbox')
->setSecuritySource(Auth::withToken($privateKey))
->setMerchantAccountId('default')
->build();

$paymentServiceTokenCreate = new Gr4vy\PaymentServiceTokenCreate(
paymentServiceId: 'fffd152a-9532-4087-9a4f-de58754210f0',
redirectUrl: 'https://example.com/callback',
);

$response = $sdk->paymentMethods->paymentServiceTokens->create(
paymentMethodId: 'ef9496d8-53a5-4aad-8ca2-00eb68334389',
paymentServiceTokenCreate: $paymentServiceTokenCreate

);

if ($response->paymentServiceToken !== null) {
// handle response
}
from gr4vy import Gr4vy
import os


with Gr4vy(
id="example",
server="sandbox",
merchant_account_id="default",
bearer_auth=auth.with_token(open("./private_key.pem").read())
) as g_client:

res = g_client.payment_methods.payment_service_tokens.create(payment_method_id="ef9496d8-53a5-4aad-8ca2-00eb68334389", payment_service_id="fffd152a-9532-4087-9a4f-de58754210f0", redirect_url="https://example.com/callback")

# Handle response
print(res)
import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
id: "example",
server: "sandbox",
merchantAccountId: "default",
bearerAuth: withToken({
privateKey: fs.readFileSync("private_key.pem", "utf8"),
}),
});

async function run() {
const result = await gr4vy.paymentMethods.paymentServiceTokens.create({
paymentServiceId: "fffd152a-9532-4087-9a4f-de58754210f0",
redirectUrl: "https://example.com/callback",
}, "ef9496d8-53a5-4aad-8ca2-00eb68334389");

console.log(result);
}

run();
curl --request POST \
--url https://api.sandbox.{id}.gr4vy.app/payment-methods/{payment_method_id}/payment-service-tokens \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"payment_service_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"redirect_url": "https://example.com/callback"
}
'
{
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "payment_method_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "payment_service_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "created_at": "2023-11-07T05:31:56Z",
  "updated_at": "2023-11-07T05:31:56Z",
  "type": "payment-service-token",
  "approval_url": "https://gr4vy.app/redirect/12345",
  "token": "pm_12345"
}
{
"type": "error",
"code": "bad_request",
"status": 400,
"message": "Generic error",
"details": []
}
{
"type": "error",
"code": "unauthorized",
"status": 401,
"message": "No valid API authentication found",
"details": []
}
{
"type": "error",
"code": "forbidden",
"status": 403,
"message": "Generic error",
"details": []
}
{
"type": "error",
"code": "not_found",
"status": 404,
"message": "The resource could not be found",
"details": []
}
{
"type": "error",
"code": "method_not_allowed",
"status": 405,
"message": "Method Not Allowed",
"details": []
}
{
"type": "error",
"code": "duplicate_record",
"status": 409,
"message": "Generic error",
"details": [],
"resource_id": "cdc70639-cb9c-4222-a73f-b8ce39f7821b"
}
{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}
{
"type": "error",
"code": "too_early",
"status": 425,
"message": "Generic error",
"details": []
}
{
"type": "error",
"code": "too_many_requests",
"status": 429,
"message": "Generic error",
"details": []
}
{
"type": "error",
"code": "server_error",
"status": 500,
"message": "Request could not be processed",
"details": []
}
{
"type": "error",
"code": "bad_gateway",
"status": 502,
"message": "Request could not be processed",
"details": []
}
{
"type": "error",
"code": "gateway_timeout",
"status": 504,
"message": "Request could not be processed",
"details": []
}
This endpoint requires the payment-methods.write scope.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Headers

x-gr4vy-merchant-account-id
string

The ID of the merchant account to use for this request.

Example:

"default"

Path Parameters

payment_method_id
string<uuid>
required

The ID of the payment method

Example:

"ef9496d8-53a5-4aad-8ca2-00eb68334389"

Body

application/json
payment_service_id
string<uuid>
required

The ID of the payment method to use.

Example:

"fffd152a-9532-4087-9a4f-de58754210f0"

redirect_url
required

The redirect URL to redirect a buyer to after they have authorized the payment method.

Example:

"https://example.com/callback"

security_code
string | null

The 3 or 4 digit security code often found on the card. This often referred to as the CVV or CVD.

Required string length: 3 - 4
Pattern: ^\d+$
Example:

"123"

Response

Successful Response

id
string<uuid>
required

The ID for the payment service token.

Example:

"07e70d14-a0c0-4ff5-bd4a-509959af0e4d"

payment_method_id
string<uuid>
required

The ID of the payment method used to generate this token

Example:

"ef9496d8-53a5-4aad-8ca2-00eb68334389"

payment_service_id
string<uuid>
required

The ID of the payment method used to generate this token.

Example:

"fffd152a-9532-4087-9a4f-de58754210f0"

status
enum<string>
required

The state of the payment service token.

Available options:
processing,
buyer_approval_required,
succeeded,
failed,
paused
Example:

"succeeded"

created_at
string<date-time>
required

The date and time when this payment service token was first created in our system.

Example:

"2013-07-16T19:23:00.000+00:00"

updated_at
string<date-time>
required

The date and time when this payment service token was last updated in our system.

Example:

"2013-07-16T19:23:00.000+00:00"

type
string
default:payment-service-token

Always payment-service-token.

Allowed value: "payment-service-token"
Example:

"payment-service-token"

approval_url
string | null

The optional URL that the buyer needs to be redirected to to further authorize the token creation.

Example:

"https://gr4vy.app/redirect/12345"

token
string | null

The token value. Will be present if succeeded.

Required string length: 1 - 10000
Example:

"pm_12345"