Run a pre-authorization
A merchant can use pre-authorizations to hold an amount on a customer’s card to capture later. The merchant can run pre-authorizations only if we have enabled the function on their account. If we have not enabled pre-authorizations on the merchant’s account, we run pre-authorization attempts as sales with a status of ‘pending’.
If a merchant needs to capture more than they originally pre-authorized, they can adjust the pre-authorization amount before they capture it. For example:
- A hotel pre-authorizes a one-night stay for a customer at $100.
- The customer decides to have dinner in the hotel for $50. The hotel adjusts the $100 pre-authorization to $150.
- At checkout, the hotel captures $150 from the customer’s account for the one- night stay and dinner.
Integration steps
Step 1. Create a payment.
Step 2. (Optional) Adjust a payment.
Step 3. Capture a payment.
Before you begin
Bearer tokens
Use our Identity Service to generate a Bearer token to include in the header of your requests. To generate your Bearer token, complete the following steps:
- Include your API key in the x-api-key parameter in the header of a POST request.
- Send your request to https://identity.payroc.com/authorize.
Note: You need to generate a new Bearer token before the previous Bearer token expires.
Example request
$ curl --location --request POST 'https://identity.payroc.com/authorize' --header 'x-api-key: <api key>'
Example response
If your request is successful, we return a response that contains your Bearer token, information about its scope, and when it expires.
1 { 2 "access_token": "eyJhbGc....adQssw5c", 3 "expires_in": 3600, 4 "scope": "service_a service_b", 5 "token_type": "Bearer" 6 }
Headers
To create the header of each POST request, you must include the following parameters:
- Content-Type: Include application/json as the value for this parameter.
- Authorization: Include your Bearer token in this parameter.
- Idempotency-Key: Include a UUID v4 to make the request idempotent.
$ curl $ -H "Content-Type: application/json" $ -H "Authorization: <Bearer token>" $ -H "Idempotency-Key: <UUID v4>"
Errors
If your request is unsuccessful, we return an error. For more information about errors, see Errors.
Step 1. Create a payment
To run a pre-authorization, set both autoCapture and processAsSale to false in the request body. If both parameters are set to true, the transaction runs as a sale instead of a pre-authorization.
To run a pre-authorization, send a POST request to our Payments endpoint.
| Endpoint | Prefix | URL |
|---|---|---|
| Test | api.uat. | https://api.uat.payroc.com/v1/payments |
| Production | api. | https://api.payroc.com/v1/payments |
Request parameters
To create the body of your request, use the following parameters:
Request
4-50 characters0-50 characterstruefalseExample request
1 using Payroc; 2 using System.Threading.Tasks; 3 using Payroc.CardPayments.Payments; 4 5 namespace Usage; 6 7 public class Example 8 { 9 public async Task Do() { 10 var client = new BasePayrocClient(); 11 12 await client.CardPayments.Payments.CreateAsync( 13 new PaymentRequest { 14 IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324", 15 Channel = PaymentRequestChannel.Web, 16 ProcessingTerminalId = "1234001", 17 Order = new PaymentOrderRequest { 18 Amount = 4999L, 19 Currency = Currency.Usd, 20 OrderId = "1234567890W", 21 Description = "Card Transaction (APPLE)" 22 }, 23 PaymentMethod = new PaymentRequestPaymentMethod( 24 new DigitalWalletPayload { 25 EncryptedData = "7b2262696c6c696e67436f6e74616374223a7b2266616d696c794e616d65223a22222c22676976656e4e616d65223a22222c2270686f6e6574696346616d696c794e616d65223a22222c2270686f6e65746963476976656e4e616d65223a22227d2c227368697070696e67436f6e74616374223a7b22656d61696c41646472657373223a227465737440646f6d61696e2e636f6d222c2266616d696c794e616d65223a22222c22676976656e4e616d65223a22222c2270686f6e6574696346616d696c794e616d65223a22222c2270686f6e65746963476976656e4e616d65223a22227d2c22746f6b656e223a7b227061796d656e7444617461223a7b2264617461223a2259314b37626731573479755568587473335941627a6150756c384d31795057304c724637734e2f70415950456d3871647969716c6257777356792b7732334c666c74344e6932525a684c2f6a52727563356f69496235537437763248543739682b74702f78517838496b6a5631485354594d747156644c6a413977686379774f654f70326575556d306e56386b50726569564273726a596c355931437a30576371495648595134424e737a4b5876675063686a497a6f4d4b456336425650744c7335777654667a434b51574a496a646b62516161306265685958524b422b7941773872537a6a4a476f3758523061467a414b4e70346c6f436e69484e564838373244504e4a77364b30336e544d69724b37725a615566485356754d477544473348366e4d78336c48436e6b517478764551474771754132676c416434424f427943414976483541566671655173534137776a4459702f494c6c66614e64307469467478344d6235566f6952513249387379384548547670307736667861316973613874636f484855614b32353857486474673d3d222c227369676e6174757265223a224d494147435371475349623344514548417143414d494143415145784454414c42676c67686b67425a514d45416745776741594a4b6f5a496876634e415163424141436767444343412b517767674f4c6f414d434151494343466e596f627971394f504e4d416f4743437147534d343942414d434d486f784c6a417342674e5642414d4d4a5546776347786c4945467763477870593246306157397549456c756447566e636d46306157397549454e4249433067527a4d784a6a416b42674e564241734d485546776347786c49454e6c636e52705a6d6c6a59585270623234675158563061473979615852354d524d77455159445651514b44417042634842735a53424a626d4d754d517377435159445651514745774a56557a4165467730794d5441304d6a41784f544d334d444261467730794e6a41304d546b784f544d324e546c614d4749784b44416d42674e5642414d4d4832566a5979317a62584174596e4a76613256794c584e705a32356656554d304c564e42546b5243543167784644415342674e564241734d43326c505579425465584e305a57317a4d524d77455159445651514b44417042634842735a53424a626d4d754d517377435159445651514745774a56557a425a4d424d4742797147534d34394167454743437147534d34394177454841304941424949772f6176446e50646549437851325a74464575593334716b423357797a344c484e53314a6e6d506a505472336f4769576f7768354d4d39334f6a697157777661766f5a4d445263546f656b516d7a7055624570576a676749524d4949434454414d42674e5648524d4241663845416a41414d42384741315564497751594d42614146435079536352506b2b54764a2b62453969687350364b372f53354c4d45554743437347415155464277454242446b774e7a4131426767724267454642516377415959706148523063446f764c32396a633341755958427762475575593239744c32396a633341774e433168634842735a5746705932457a4d4449776767456442674e5648534145676745554d4949424544434341517747435371475349623359325146415443422f6a4342777759494b77594242515548416749776762594d67624e535a5778705957356a5a5342766269423061476c7a49474e6c636e52705a6d6c6a5958526c49474a35494746756553427759584a306553426863334e316257567a4947466a593256776447467559325567623259676447686c4948526f5a5734675958427762476c6a59574a735a53427a644746755a4746795a4342305a584a7463794268626d5167593239755a476c3061573975637942765a6942316332557349474e6c636e52705a6d6c6a5958526c4948427662476c6a65534268626d51675932567964476c6d61574e6864476c7662694277636d466a64476c6a5a53427a644746305a57316c626e527a4c6a4132426767724267454642516343415259716148523063446f764c33643364793568634842735a53356a623230765932567964476c6d61574e68644756686458526f62334a7064486b764d44514741315564487751744d4373774b61416e6f43574749326830644841364c79396a636d77755958427762475575593239744c3246776347786c59576c6a59544d7559334a734d4230474131556444675157424251434a44414c6d753774526a4758704b5a614b5a3543635949635254414f42674e56485138424166384542414d43423441774477594a4b6f5a496876646a5a415964424149464144414b42676771686b6a4f5051514441674e4841444245416942306f624d6b32304a4a517733544a307851644d53416a5a6f6653413436686358424e69566d4d6c2b386f7749676154615155367631433170532b6659415463574b725778517039594961446551344b63363042354b3259457767674c754d49494364614144416745434167684a62532b2f4f706a616c7a414b42676771686b6a4f50515144416a426e4d527377475159445651514444424a42634842735a5342536232393049454e4249433067527a4d784a6a416b42674e564241734d485546776347786c49454e6c636e52705a6d6c6a59585270623234675158563061473979615852354d524d77455159445651514b44417042634842735a53424a626d4d754d517377435159445651514745774a56557a4165467730784e4441314d4459794d7a51324d7a4261467730794f5441314d4459794d7a51324d7a42614d486f784c6a417342674e5642414d4d4a5546776347786c4945467763477870593246306157397549456c756447566e636d46306157397549454e4249433067527a4d784a6a416b42674e564241734d485546776347786c49454e6c636e52705a6d6c6a59585270623234675158563061473979615852354d524d77455159445651514b44417042634842735a53424a626d4d754d517377435159445651514745774a56557a425a4d424d4742797147534d34394167454743437147534d34394177454841304941425041584559515a31325346315270654a594548647569416f752f656536354e34493338533550684d3162565a6c733172694c516c33594e496b353775676a396468664f694d743275325a7776736a6f4b59542f5645576a6766637767665177526759494b77594242515548415145454f6a41344d4459474343734741515546427a41426869706f644852774f69387662324e7a63433568634842735a53356a6232307662324e7a634441304c5746776347786c636d397664474e685a7a4d77485159445652304f4242594546435079536352506b2b54764a2b62453969687350364b372f53354c4d41384741315564457745422f7751464d414d4241663877487759445652306a42426777466f4155753744656f56677a694a716b69706e65767233727239724c4a4b73774e77594456523066424441774c6a41736f4371674b49596d6148523063446f764c324e7962433568634842735a53356a623230765958427762475679623239305932466e4d79356a636d777744675944565230504151482f42415144416745474d42414743697147534962335932514741673445416755414d416f4743437147534d343942414d43413263414d4751434d447250636f4e5246706d78687673317731624b59722f30462b335a4433564e6f6f362b385a7942586b4b33696669593935745a6e356a56515132506e656e432f6749774d693356524347776f7756336246337a4f4475515a2f305866437768625a5a50786e4a7067684a76565068366652755a7935734a6953466842706b50435a4964414141786767474a4d4949426851494241544342686a42364d5334774c4159445651514444435642634842735a5342426348427361574e6864476c766269424a626e526c5a334a6864476c7662694244515341744945637a4d5359774a4159445651514c44423142634842735a5342445a584a3061575a7059324630615739754945463164476876636d6c30655445544d424547413155454367774b51584277624755675357356a4c6a454c4d416b474131554542684d4356564d4343466e596f627971394f504e4d417347435743475341466c41775143416143426b7a415942676b71686b69473977304243514d784377594a4b6f5a496876634e415163424d42774743537147534962334451454a42544550467730794e4445794d5449784e6a51774d5452614d43674743537147534962334451454a4e4445624d426b774377594a59495a4941575544424149426f516f4743437147534d343942414d434d43384743537147534962334451454a4244456942434335615768366c647944637435626844536b62345835494a612b576f746d6d74344a624c74386949754a6b6a414b42676771686b6a4f50515144416752494d45594349514437637561364c6430697a6148716d5371713747303433476770363467484d6b514e523577757a32736137674968414e44643730585a6639432f412b58774e716a75672b76684c39534c4c4966465159746f6745377842534c774141414141414141222c22686561646572223a7b227075626c69634b657948617368223a225542347255754d6b7044627054564b7448636a6452525a496f643465766562754d4f696b7a4156556441593d222c22657068656d6572616c5075626c69634b6579223a224d466b77457759484b6f5a497a6a3043415159494b6f5a497a6a3044415163445167414557556a70324f663878427449432f354335535349544e443554736f75564c423831464547383847504b7243394e394d753365534e72586c32636564757533552f504f53652f616f75384477556a674e6670584d7831673d3d222c227472616e73616374696f6e4964223a2231363431326566383238303362633133356338333165396235663732376432366165623661616130363364633138353861313562323734386666346636333739227d2c2276657273696f6e223a2245435f7631227d2c227061796d656e744d6574686f64223a7b22646973706c61794e616d65223a224d6173746572436172642031343731222c226e6574776f726b223a224d617374657243617264222c2274797065223a226465626974227d2c227472616e73616374696f6e4964656e746966696572223a2231363431326566383238303362633133356338333165396235663732376432366165623661616130363364633138353861313562323734386666346636333739227d7d", 26 ServiceProvider = DigitalWalletPayloadServiceProvider.Apple 27 } 28 ), 29 Operator = "Jane" 30 } 31 ); 32 } 33 34 }
Response fields
Important: Save the paymentId to use when you capture the payment.
If your request is successful, we send a pre-authorization request to the customer’s bank or card company for the specific amount. The response contains the following fields:
Response
=10 characters4-50 characters0-50 charactersExample response
1 { 2 "paymentId": "J9VULKIKFP", 3 "processingTerminalId": "1234001", 4 "order": { 5 "amount": 4999, 6 "currency": "USD", 7 "orderId": "1234567890W", 8 "dateTime": "2024-07-02T15:30:00Z", 9 "description": "Card Transaction (APPLE)" 10 }, 11 "card": { 12 "type": "MasterCard", 13 "entryMethod": "keyed", 14 "cardNumber": "500165******0000", 15 "expiryDate": "0328", 16 "securityChecks": { 17 "avsResult": "U" 18 } 19 }, 20 "transactionResult": { 21 "status": "ready", 22 "responseCode": "A", 23 "type": "sale", 24 "approvalCode": "OK3", 25 "authorizedAmount": 4999, 26 "currency": "USD", 27 "responseMessage": "APPROVAL", 28 "processorResponseCode": "00" 29 }, 30 "operator": "Jane", 31 "supportedOperations": [ 32 "capture", 33 "fullyReverse", 34 "partiallyReverse", 35 "incrementAuthorization", 36 "adjustTip", 37 "setAsPending" 38 ] 39 }
Step 2. (Optional) Adjust a payment
Important: A merchant can capture more than they originally pre-authorized, however each card brand sets different limits to the additional amount that the merchant can capture. If a merchant needs to capture more than they originally pre-authorized, we recommend that they adjust the pre-authorization before they capture it.
To adjust a pre-authorized amount, send a POST request to our Payments endpoint.
| Endpoint | Prefix | URL |
|---|---|---|
| Test | api.uat. | https://api.uat.payroc.com/v1/payments/{paymentId}/adjust |
| Production | api. | https://api.payroc.com/v1/payments/{paymentId}/adjust |
Request parameters
To create the body of your request, use the following parameters:
Request
0-50 charactersExample request
1 using Payroc; 2 using System.Threading.Tasks; 3 using Payroc.CardPayments.Payments; 4 using System.Collections.Generic; 5 6 namespace Usage; 7 8 public class Example 9 { 10 public async Task Do() { 11 var client = new BasePayrocClient(); 12 13 await client.CardPayments.Payments.AdjustAsync( 14 new PaymentAdjustment { 15 PaymentId = "M2MJOG6O2Y", 16 IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324", 17 Adjustments = new List<PaymentAdjustmentAdjustmentsItem>(){ 18 new PaymentAdjustmentAdjustmentsItem( 19 new CustomerAdjustment { 20 ShippingAddress = new Shipping { 21 RecipientName = "Sarah Hopper", 22 Address = new Address { 23 Address1 = "1 Example Ave.", 24 City = "Chicago", 25 State = "Illinois", 26 Country = "US", 27 PostalCode = "60056", 28 Address2 = "Example Address Line 2", 29 Address3 = "Example Address Line 3" 30 } 31 } 32 } 33 ), 34 new PaymentAdjustmentAdjustmentsItem( 35 new OrderAdjustment { 36 Amount = 3999L 37 } 38 ), 39 } 40 41 } 42 ); 43 } 44 45 }
Response fields
If your request is successful, we adjust the pre-authorization amount and return a response. The response contains the following fields:
Response
=10 characters4-50 characters0-50 charactersExample response
1 { 2 "paymentId": "M2MJOG6O2Y", 3 "processingTerminalId": "1234001", 4 "order": { 5 "amount": 4999, 6 "currency": "USD", 7 "orderId": "OrderRef6543", 8 "dateTime": "2024-07-02T15:30:00Z", 9 "description": "Example payment" 10 }, 11 "card": { 12 "type": "MasterCard", 13 "entryMethod": "keyed", 14 "cardNumber": "453985******7062", 15 "expiryDate": "1230", 16 "securityChecks": { 17 "cvvResult": "M", 18 "avsResult": "Y" 19 } 20 }, 21 "transactionResult": { 22 "status": "ready", 23 "responseCode": "A", 24 "type": "sale", 25 "approvalCode": "OK6", 26 "authorizedAmount": 4999, 27 "currency": "USD", 28 "responseMessage": "OK6" 29 }, 30 "customer": { 31 "firstName": "Sarah", 32 "lastName": "Hopper", 33 "billingAddress": { 34 "address1": "1 Example Ave.", 35 "address2": "Example Address Line 2", 36 "address3": "Example Address Line 3", 37 "city": "Chicago", 38 "state": "Illinois", 39 "country": "US", 40 "postalCode": "60056" 41 }, 42 "shippingAddress": { 43 "recipientName": "Sarah Hopper", 44 "address": { 45 "address1": "1 Example Ave.", 46 "address2": "Example Address Line 2", 47 "address3": "Example Address Line 3", 48 "city": "Chicago", 49 "state": "Illinois", 50 "country": "US", 51 "postalCode": "60056" 52 } 53 } 54 }, 55 "supportedOperations": [ 56 "capture", 57 "fullyReverse", 58 "partiallyReverse", 59 "incrementAuthorization", 60 "adjustTip", 61 "setAsPending" 62 ], 63 "customFields": [ 64 { 65 "name": "yourCustomField", 66 "value": "abc123" 67 } 68 ] 69 }
Step 3. Capture a payment
To capture the pre-authorization, send a POST request to our Payments endpoint.
| Endpoint | Prefix | URL |
|---|---|---|
| Test | api.uat. | https://api.uat.payroc.com/v1/payments/{paymentId}/capture |
| Production | api. | https://api.payroc.com/v1/payments/{paymentId}/capture |
Request parameters
To create the body of your request, use the following parameters:
Request
4-50 characters0-50 charactersExample request
1 using Payroc; 2 using System.Threading.Tasks; 3 using Payroc.CardPayments.Payments; 4 using System.Collections.Generic; 5 6 namespace Usage; 7 8 public class Example 9 { 10 public async Task Do() { 11 var client = new BasePayrocClient(); 12 13 await client.CardPayments.Payments.CaptureAsync( 14 new PaymentCapture { 15 PaymentId = "M2MJOG6O2Y", 16 IdempotencyKey = "8e03978e-40d5-43e8-bc93-6894a57f9324", 17 ProcessingTerminalId = "1234001", 18 Operator = "Jane", 19 Amount = 4999L, 20 Breakdown = new ItemizedBreakdownRequest { 21 Subtotal = 4999L, 22 DutyAmount = 499L, 23 FreightAmount = 500L, 24 Items = new List<LineItemRequest>(){ 25 new LineItemRequest { 26 Quantity = 1, 27 UnitPrice = 4000 28 }, 29 } 30 31 } 32 } 33 ); 34 } 35 36 }
Response fields
If your request is successful, we capture the pre-authorization and return a response. The response contains the following fields:
Response
=10 characters4-50 characters0-50 charactersExample response
1 { 2 "paymentId": "M2MJOG6O2Y", 3 "processingTerminalId": "1234001", 4 "order": { 5 "amount": 4999, 6 "currency": "USD", 7 "orderId": "OrderRef6543", 8 "dateTime": "2024-07-02T15:30:00Z", 9 "description": "Large Pepperoni Pizza" 10 }, 11 "card": { 12 "type": "MasterCard", 13 "entryMethod": "keyed", 14 "cardNumber": "453985******7062", 15 "expiryDate": "1230", 16 "securityChecks": { 17 "cvvResult": "M", 18 "avsResult": "Y" 19 } 20 }, 21 "transactionResult": { 22 "status": "ready", 23 "responseCode": "A", 24 "type": "sale", 25 "approvalCode": "OK3", 26 "authorizedAmount": 4999, 27 "currency": "USD", 28 "responseMessage": "OK3" 29 }, 30 "operator": "Jane", 31 "customer": { 32 "firstName": "Sarah", 33 "lastName": "Hopper", 34 "billingAddress": { 35 "address1": "1 Example Ave.", 36 "address2": "Example Address Line 2", 37 "address3": "Example Address Line 3", 38 "city": "Chicago", 39 "state": "Illinois", 40 "country": "US", 41 "postalCode": "60056" 42 }, 43 "shippingAddress": { 44 "recipientName": "Sarah Hopper", 45 "address": { 46 "address1": "1 Example Ave.", 47 "address2": "Example Address Line 2", 48 "address3": "Example Address Line 3", 49 "city": "Chicago", 50 "state": "Illinois", 51 "country": "US", 52 "postalCode": "60056" 53 } 54 } 55 }, 56 "supportedOperations": [ 57 "capture", 58 "fullyReverse", 59 "partiallyReverse", 60 "incrementAuthorization", 61 "adjustTip", 62 "setAsPending" 63 ], 64 "customFields": [ 65 { 66 "name": "yourCustomField", 67 "value": "abc123" 68 } 69 ] 70 }
Test cases
Before you run test cases, read the Payments page in Test Your Integration.
Run a pre-authorization
Send a POST request to the following endpoint:
POST https://api.uat.payroc.com/v1/payments
Note: Set the value for the autoCapture parameter to false.
Example response
1 { 2 "paymentId": "C7BHY7KWCW", 3 "processingTerminalId": "3204001", 4 "operator": "Davi-Crisostomo-CHP", 5 "order": { 6 "orderId": "1234567890Q1", 7 "dateTime": "2023-06-20T21:03:30.925+01:00", 8 "description": "PreAuth Card Transaction (WEB) - Sale - KEYED (plain_text) with CVV", 9 "amount": 12346, 10 "currency": "USD" 11 }, 12 "card": { 13 "type": "Visa Credit", 14 "entryMethod": "keyed", 15 "cardholderName": "Davi", 16 "cardNumber": "444433******1111", 17 "expiryDate": "1223", 18 "securityChecks": { 19 "cvvResult": "M", 20 "avsResult": "Y" 21 } 22 }, 23 "transactionResult": { 24 "type": "sale", 25 "status": "pending", 26 "approvalCode": "OK24233", 27 "authorizedAmount": 12346, 28 "currency": "USD", 29 "responseCode": "A", 30 "responseMessage": "OK24233" 31 } 32 }
Capture a pre-authorization
Send a POST request to the following endpoint:
POST https://api.uat.payroc.com/v1/payments/{paymentId}/capture
Example response
1 { 2 "paymentId": "C7BHY7KWCW", 3 "processingTerminalId": "3204001", 4 "operator": "Davi-Crisostomo-CHP", 5 "order": { 6 "orderId": "1234567890Q1", 7 "dateTime": "2023-06-20T21:03:31+01:00", 8 "description": "PreAuth Card Transaction (WEB) - Sale - KEYED (plain_text) with CVV", 9 "amount": 6532, 10 "currency": "USD" 11 }, 12 "card": { 13 "type": "Visa Credit", 14 "entryMethod": "keyed", 15 "cardholderName": "Davi", 16 "cardNumber": "444433******1111", 17 "expiryDate": "1223", 18 "securityChecks": { 19 "cvvResult": "M", 20 "avsResult": "Y" 21 } 22 }, 23 "transactionResult": { 24 "type": "sale", 25 "status": "ready", 26 "approvalCode": "OK24233", 27 "authorizedAmount": 6532, 28 "currency": "USD", 29 "responseCode": "A", 30 "responseMessage": "OK24233" 31 } 32 }