Skip to main content

Create Contract

Step 2: Create a Contract​

After obtaining the access token, use it to create a payment contract.

Endpoint​

POST /apps/api/contracts

Headers

  • Authorization: Bearer {access_token}
    Replace {access_token} with the token obtained from login (Step 1).

  • Content-Type: application/json

Request Body​

{
"title": "Sell a property111",
"contractServiceType": "Product",
"BuyerParty": {
"platformRefId" : "USR_abc001", //Optional.
"phoneNumber": "966583944460", //Required if platformRefId is not provided
"firstName": "Buyer", //Required if platformRefId is not provided
"lastName": "Name", //Required if platformRefId is not provided
"KYC": //Optional.
{
"identity": "74325500958",
"dateOfBirth": "2000-01-01T10:27:39.889Z" //Optional.
}
},
"SellerParty": {
"platformRefId" : "USR_abc002", //Optional.
"phoneNumber": "966583944461", //Required if platformRefId is not provided
"firstName": "Seller", //Required if platformRefId is not provided
"lastName": "", //Required if platformRefId is not provided
"KYC": //Optional.
{
"identity": "5232210232",
"IBANNumber": "SA0380000000608010167519",
"dateOfBirth": "2000-01-01T10:27:39.889Z" //Optional.
}
},
"amount": 1000,
"description": "Extenal Iphone mobile",
"notes": "notes for mobile",
"reference": "12321",
"metaData": {
"metadata1": "1",
"metadata2": "2",
"metadata3": "",
"metadata4": ""
},
"callbackUrl": "https://yourdomain.com/usercart",
"Milestones": [
{
"Name": "milestone 1 name",
"Description": "milestone 1 description",
"Amount": 600,
"DueDate": "2026-12-20T10:00:00.000Z"
},
{
"Name": "milestone 2 name",
"Description": "milestone 2 description",
"Amount": 400,
"DueDate": "2026-12-31T09:35:30.369Z"
}
]
}

Field Descriptions​

Field NameTypeDescriptionRequired / Notes / Example
titlestringContract titleRequired
Example: "Sell a property111"
contractServiceTypestringType of service for the contractRequired
Expected Values: "Product", "Service"
BuyerPartyobject (Party)Buyer informationRequired
SellerPartyobject (Party)Seller informationRequired
amountnumberContract amountRequired
Example: 1000
descriptionstringContract descriptionOptional
Example: "Extenal Iphone mobile"
notesstringAdditional notesOptional
Example: "notes for mobile"
referencestringExternal reference identifierOptional
Example: "12321"
metaDataobject (MetaData)Custom key-value metadataOptional
callbackUrlstringCallback URL for contract eventsOptional
Example: "https://yourdomain.com/usercart"
Milestoneslist of objects (Milestone)Seperate contract into multiple milestonesOptional

Party (BuyerParty / SellerParty)

Field NameTypeDescriptionRequired / Notes / Example
platformRefId*stringUser identifier in wepay systemOptional
phoneNumberstringParty phone number (including country code)Required if platformRefId is not provided
Example: "966583944460"
firstNamestringFirst nameRequired if platformRefId is not provided
Example: "Ahmad"
lastNamestringLast nameRequired if platformRefId is not provided
Example: "Ali"

*platformRefId is optional in the request. It is a unique identifier across all parties in the system. It can be used to link the party to an existing user in your system or to store a reference for future lookups.

To get platformRefId, you can call the User Onboarding API to retrieve a user and obtain his platformRefId, if exists.

You can also choose to not provide platformRefId in the request, or just provide the party's phone number and name and WePay will try to find an existing user with the same phone number. If the user is a new one, it will be created automatically in the system and a new platformRefId will be generated for him, and will be returned in the response. You can then store this platformRefId in your system for future reference.

If you want to create a user in Wepay and get the platformRefId before creating a contract, you can use the User Creation API to create a new user and get his platformRefId, then use this platformRefId in the contract creation request.

Note: On contract creation, the seller receives an SMS with a KYC link to verify his identity.

Party (SellerParty)

Field NameTypeDescriptionRequired / Notes / Example
kycobjectkyc data for sellerOptional

Kyc object

Field NameTypeDescriptionRequired / Notes / Example
identitystringSeller national idRequired
iBANNumberstringSeller bank account IBANRequired for seller
dateOfBirthdatetimeSeller date of birthOptional

MetaData

Field NameTypeDescriptionRequired / Notes / Example
metadata1stringCustom metadata fieldOptionalExample: "1"
metadata2stringCustom metadata fieldOptionalExample: "2"
metadata3stringCustom metadata fieldOptionalExample: ""
metadata4stringCustom metadata fieldOptionalExample: ""

Milestone

Field NameTypeDescriptionRequired / Notes / Example
NamestringMilestone nameRequired OptionalExample: "milestone 1 name"
DescriptionstringMilestone DescriptionOptionalExample: "milestone 1 description"
AmountNumberMilestone amountRequired OptionalExample: 600
Note: Must be lower than contract amount and the total of all milestones amounts must be equal to the contract amount
DueDatestring (date-time)Contract creation timestamp (UTC)Required
Example: 2026-12-20T10:00:000Z

Response:​

Result<ExternalCreateContractResponse>

Field NameTypeDescriptionRequired / Notes / Example
succeededbooleanIndicates whether the request was successfulRequired
Example: true
messagestringResult messageOptional
Example: "Contract created successfully"
errorsarray of stringList of validation or business errorsOptional
dataobject (ExternalCreateContractResponse)Contract creation result dataOptional

ExternalCreateContractResponse

Field NameTypeDescriptionRequired / Notes / Example
contractIdstringUnique external contract identifierRequired

Example: "c8f1a3c2-9d12-4c8b-9f0a-123456789abc"
statusstring (ContractStatus)Current contract statusRequired

Example: "Pending"
contractServiceTypestring (ContractServiceType)Type of contract serviceRequired

Example: "Product"
checkoutUrlstringCheckout URL for completing paymentRequired

Example: "https://integration.wepay-sa.com/checkout?token=encodedToken"
The token is valid for 10 minutes. If expired, you need to request a new one by calling /apps/api/contracts/checkout
buyerPartyobject (ExternalContractParty)Buyer party detailsRequired
sellerPartyobject (ExternalContractParty)Seller party detailsRequired
referencestringExternal reference identifierOptional Nullable
metaDataobject (ContractMetaData)Custom metadataOptional Nullable
milestonesarray of MilestoneContract milestonesRequired
pricingLineItemsarray of ExternalPriceLineItemPricing breakdown itemsRequired
createdDatestring (date-time)Contract creation timestamp (UTC)Required

Example: 2024-01-15T10:30:00Z

ExternalContractParty

Field NameTypeDescriptionRequired / Notes / Example
platformRefIdstringUser identifier in wepayRequired
firstNamestringFirst nameRequired
Example: "Ahmad"
lastNamestringLast nameRequired
Example: "Ali"
phoneNumberstringPhone number including country codeRequired
Example: "966583944460"

ContractMetaData

Field NameTypeDescriptionRequired / Notes / Example
metadata1stringCustom metadata fieldOptional
metadata2stringCustom metadata fieldOptional
metadata3stringCustom metadata fieldOptional
metadata4stringCustom metadata fieldOptional

Milestone

Field NameTypeDescriptionRequired / Notes / Example
IdnumberMilestone identifierRequired
Example: 13
namestringMilestone nameRequired

Example: "Delivery"
descriptionstringMilestone descriptionOptional
amountnumberMilestone amountRequired

Example: 500
dueDatestring (date-time)Milestone due date (UTC)Required

Example: 2024-02-01T00:00:00Z
pricingLineItemsarray of ExternalPriceLineItemPricing breakdown itemsRequired

Milestone Validation Rules​

RuleRequirement
Total amountsMust equal contract amount
Milestone amountMust be > 0
DueDate formatISO 8601 UTC (with Z suffix)
NameRequired field
DescriptionOptional field

Important: Milestone Amount Calculation​

Request Amount = Base contract amount
Response Amount = Base + all fees + taxes

Example:

  • Request: 600 SAR (base)
  • Response: 686.25 SAR (includes escrow fees, platform fees, VAT)

See PricingLineItems array for full breakdown.

ExternalPriceLineItem

Field NameTypeDescriptionRequired / Notes / Example
lineTypestring (PricingLineType)Pricing line typeRequired

Example: "EscrowFee"
LineTypeDescriptionstringPricing line type descriptionRequired
rolestring (PricingRole)Party responsible for the amountRequired

Example: "Buyer"
RoleDescriptionstringRole descriptionRequired
amountnumberAmount valueRequired

Example: 50
descriptionstringPricing line descriptionOptional
orderintegerDisplay orderRequired

Example: 1

Example Request (cURL)​

curl -X POST "https://api.wepay.com.sa/apps/api/contracts" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "TEST Sell a property111",
"contractServiceType": "Product",
"BuyerParty": {
"phoneNumber": "966583944460",
"firstName": "Buyer",
"lastName": "Name aa"
},
"SellerParty": {
"phoneNumber": "966583944461",
"firstName": "Seller",
"lastName": ""
},
"amount": 1000,
"description": "TEST External Iphone mobile",
"notes": "notes for mobile",
"callbackurl": "http://localhost:3000/en/payment-success",
"Milestones": [
{
"Name": "milestone 1 name",
"Description": "milestone 1 description",
"Amount": 600,
"DueDate": "2026-12-20T10:00:00.000Z"
},
{
"Name": "milestone 2 name",
"Description": "milestone 2 description",
"Amount": 400,
"DueDate": "2026-12-31T09:35:30.369Z"
}
]
}'

Note: API uses camelCase for JSON responses:

  • Request: "Milestones" (PascalCase - C# convention)
  • Response: "milestones" (camelCase - JSON convention)

DueDate Format: Always use UTC timezone

  • Example: "2026-12-20T10:00:00.000Z"
  • System converts to Saudi time (UTC+3) for display

Note: Milestones are read-only after contract creation.

Example Response​

{
"data": {
"contractId": "CNT-2601-00100003",
"status": "pending",
"contractServiceType": "product",
"checkoutUrl": "https://integration.welink-sa.com/checkout?token=RSGFF38PXVO....",
"buyerParty": {
"platformRefId": "USR_20260405152053_5487",
"firstName": "Buyer",
"lastName": "Name aa",
"phoneNumber": "966583944460"
},
"sellerParty": {
"platformRefId": "USR_20260405151029_7034",
"firstName": "Seller",
"lastName": "",
"phoneNumber": "966583944461"
},
"reference": "12321",
"metaData": {
"metadata1": "1",
"metadata2": "2",
"metadata3": "",
"metadata4": ""
},
"milestones": [
{
"Id": 12,
"Name": "milestone 1 name",
"Description": "milestone 1 description",
"DueDate": "2026-12-20T10:00:00.000Z",
"Amount": 686.25,
"PricingLineItems": [
{
"lineType": "contractAmount",
"role": "buyer",
"amount": 600,
"description": null,
"order": 1
},
{
"lineType": "escrowFee",
"role": "thirdParty",
"amount": 15.0,
"description": null,
"order": 2
},
{
"lineType": "escrowFeeTax",
"role": "thirdParty",
"amount": 2.25,
"description": null,
"order": 3
},
{
"lineType": "externalPlatformFee",
"role": "buyer",
"amount": 60.00,
"description": null,
"order": 4
},
{
"lineType": "externalPlatformFeeTax",
"role": "buyer",
"amount": 9.00,
"description": null,
"order": 5
},
{
"lineType": "netEscrowAmountToSeller",
"role": "seller",
"amount": 600,
"description": null,
"order": 6
}
]
},
{
"Id": 13,
"Name": "milestone 2 name",
"Description": "milestone 2 description",
"DueDate": "2026-12-31T09:35:30.369Z",
"Amount": 457.5,
"PricingLineItems": [
{
"lineType": "contractAmount",
"role": "buyer",
"amount": 400,
"description": null,
"order": 1
},
{
"lineType": "escrowFee",
"role": "thirdParty",
"amount": 10.00,
"description": null,
"order": 2
},
{
"lineType": "escrowFeeTax",
"role": "thirdParty",
"amount": 1.50,
"description": null,
"order": 3
},
{
"lineType": "externalPlatformFee",
"role": "buyer",
"amount": 40.00,
"description": null,
"order": 4
},
{
"lineType": "externalPlatformFeeTax",
"role": "buyer",
"amount": 6.00,
"description": null,
"order": 5
},
{
"lineType": "netEscrowAmountToSeller",
"role": "seller",
"amount": 400,
"description": null,
"order": 6
}
]
}
],
"pricingLineItems": [
{
"lineType": "contractAmount",
"role": "buyer",
"amount": 1000,
"description": null,
"order": 1
},
{
"lineType": "escrowFee",
"role": "thirdParty",
"amount": 25.0,
"description": null,
"order": 2
},
{
"lineType": "escrowFeeTax",
"role": "thirdParty",
"amount": 3.75,
"description": null,
"order": 3
},
{
"lineType": "externalPlatformFee",
"role": "buyer",
"amount": 100.0,
"description": null,
"order": 4
},
{
"lineType": "externalPlatformFeeTax",
"role": "buyer",
"amount": 15.0,
"description": null,
"order": 5
},
{
"lineType": "netEscrowAmountToSeller",
"role": "seller",
"amount": 1000,
"description": null,
"order": 6
}
],
"createdDate": "2026-01-25T10:28:10.4874015Z"
},
"message": "Contract created successfully.",
"status": 200,
"validationErrors": []
}