Creating an On-Demand Plan

This document provides a comprehensive guide for creating an On-Demand Plan using the PortOne API. An On-Demand Plan allows merchants to charge customers based on their usage or activity without fixed intervals.


API Endpoint

POST https://api.portone.cloud/api/subscription/createPlan


Headers

HeaderTypeRequiredDescription
Content-TypestringYesSet to application/json.
X-Portone-Client-KeystringYesThe unique PortOne key for the merchant.
AuthorizationstringYesJWT for authenticating API requests. Learn how to generate the token here.

Request Body Parameters

Below are the required and optional parameters for creating an On-Demand Plan:

General Parameters

ParameterTypeRequiredDescription
portone_keystringYesThe unique PortOne key for the merchant.
signature_hashstringYesSignature hash generated as per On-Demand Plan Request Signature Documentation.
merchant_order_refstringYesThe unique merchant order reference generated by the merchant.
sourcestringYesThe source of plan creation: default, api, or checkout.
descriptionstringNoA description of the plan.
environmentstringYesPlan environment, either live or sandbox.
namestringYesName of the plan.
notesarray of objectsNoAdditional notes related to the plan.

On-Demand Plan-Specific Parameters

ParameterTypeRequiredDescription
currencystringYesCurrency of the plan (e.g., USD).
plan_typestringYesType of plan. Set to ONDEMAND.

Request Example

On-Demand Plan Request

Request Body:

{
  "portone_key": "PORTONE_KEY",
  "signature_hash": "GENERATED_SIGNATURE",
  "merchant_order_ref": "MerchantRef12345",
  "source": "api",
  "description": "Pay-As-You-Go Subscription Plan",
  "environment": "live",
  "name": "On-Demand Plan",
  "notes": [
    {
      "key": "Plan Note",
      "value": "This is a flexible plan for on-demand usage."
    }
  ],
  "currency": "USD",
  "plan_type": "ONDEMAND"
}


Response

Success Response

{
  "status": "success",
  "message": "Plan created successfully.",
  "data": {
    "plan_id": "Plan12345",
    "name": "On-Demand Plan",
    "type": "ONDEMAND",
    "currency": "USD",
    "environment": "live",
    "created_at": "2024-11-21T10:00:00Z"
  }
}

 

Error Response

{
  "status": "error",
  "message": "Invalid signature_hash.",
  "error_code": 401
}



Signature Hash Generation

To ensure the authenticity of the request, generate the signature_hash by following the On-Demand Plan Request Signature Documentation.

Steps for Generating the Signature

  1. Concatenate the required parameters (currency, merchant_order_ref) into a single string in alphabetical order.
  2. Calculate the SHA-256 hash of the resulting string.
  3. Base64-encode the hash to obtain the signature_hash.

Best Practices

  • Environment Selection: Use sandbox for testing and live for production.
  • Validation: Ensure all required fields are correctly validated before sending the request.
  • Testing: Test your API integration in the sandbox environment before moving to production.
  • Secure API Keys: Never expose your portone_key or authorization tokens publicly.
  • Monitor Responses: Regularly monitor API responses to ensure the correct plan creation.

Key Notes

  • Regular Plans: Suitable for fixed recurring payments like subscriptions or memberships.
  • Frequency and Period: Ensure the values align with the intended billing cycle.
  • Descriptive Details: Use descriptive names and notes for easier plan management and tracking.

This document serves as a comprehensive guide to creating Regular Plans with the PortOne API. Let me know if additional details or sections are needed!