-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhooks-api.yaml
More file actions
5868 lines (5648 loc) · 204 KB
/
webhooks-api.yaml
File metadata and controls
5868 lines (5648 loc) · 204 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.1.0
info:
title: Two webhooks
description: |-
## Overview and usage
Two provides webhooks via a [portal](https://www.svix.com) that allows you to self-manage your application's webhook
subscriptions and related configuration options when receiving these webhooks.
Please refer to the portal's [Receiving webhooks documentation](https://docs.svix.com/receiving/introduction) for more
details about using the portal and how to consume webhook events.
### Getting started
1. Login to the [Two Merchant Portal](https://portal.two.inc/auth/merchant/login).
2. Within the Two Merchant Portal, go to the "Integrations" page and press the "Manage webhook subscriptions" button.
You should be directed to the webhooks portal.
3. Once you are logged in to the webhooks portal, please refer to the [webhook portal documentation](https://docs.svix.com/receiving/introduction)
for details on how to configure your subscriptions.
4. In the webhooks portal, once you have configured an endpoint to receive webhooks, you can send test/example payloads
to the endpoint by going to Endpoints, selecting one of your configured endpoints, selecting the Testing tab,
choosing which event type to send and then hitting the Send Example button.
5. Alternatively, you can use one of our simulation endpoints to emit webhooks matching one of the event type schemas.
See details under schemas for each webhook.
## Webhooks Postman Collection
To get started using the simulation endpoints and events that trigger webhooks, we have a downloadable
[Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
#¤ Environments
### Testing
`https://api.sandbox.two.inc`
### Production
`TBC`
## Pre-requisites
1. An API key to access our checkout API. You can get an API key (which you should keep protected) for your application
from the [Two Merchant Portal](https://portal.two.inc/auth/merchant/login).
2. An email address to receive invoices and similar notifications, such as credit notes (optional).
The simulation endpoints we provide to trigger certain webhooks are made for testing purposes only and are only
available in our sandbox environment. There are some limitations with these and may not always provide fully accurate
data in some edge cases.
## Interpreting order reconciliation events
Order reconciliation events (event types with prefix `order.reconciliation.`) describe financial events related to
orders that are relevant to the buyer.
All order reconciliation events have an `amount` field in the payload, which can be summed over multiple events to
calculate the amount owed by buyers (a.k.a. the outstanding amount).
The outstanding amount can be calculated on different levels by grouping/filtering on other IDs carried in the order
reconciliation events, for instance:
- Grouping the sum by order ID yields outstanding amount for that order.
- Grouping by billing period ID yields the outstanding amount on a billing statement level.
Payment allocation events (`order.reconciliation.payment_allocated.v1`) describe the portion of a payment used to cover
an invoice. The `payment` sub-structure of the payload contains information on the actual payment itself. It may be
larger than a single allocation, and may show up on multiple allocation events if used to cover more than one invoice.
## Event Reference
version: 0.0.1
paths: {}
webhooks:
reconciliation-invoiced:
post:
tags:
- Order Reconciliation
summary: Order Invoiced
description: |-
Type: `order.reconciliation.invoiced.v1`
Occurs when an order has been successfully fulfilled and the corresponding invoice has been created by Two.
#### Payload
The `data` object in the payload contains IDs that link the order and the invoice, along with the amount and
currency of the invoice to be paid back by the buyer.
#### Example:
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.reconciliation.invoiced.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"invoice_id": "7a5a7b9b-7d9e-4e9e-b9b1-2d7c658e1a4d",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"billing_period_id": "175bda61-c6f2-4b9d-a429-5f31c83ecc10",
"amount": "150.65",
"currency": "GBP"
}
}
```
#### Triggering in sandbox
1. [Create](/docs/api/checkout/create-order-handler-post/) an order through
the checkout API service in your sandbox environment. Capture the order ID from the resulting response.
2. [Fulfill](/docs/api/checkout/mark-fulfilled-order-handler-post/) the
order. There may be a short delay while the fulfilment process completes asynchronously.
3. Once the order state moves from `FULFILLING` to `FULFILLED`, the buyer representative email specified in the order request will receive an invoice. Simultaneously, the `order.reconciliation.invoiced.v1` webhook will be sent by the webhook gateway to any endpoints you have configured to receive it.
operationId: order_invoicedreconciliation_invoiced_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderReconciliationInvoiced"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
reconciliation-payment-allocated:
post:
tags:
- Order Reconciliation
summary: Payment Allocation
description: |-
Type: `order.reconciliation.payment_allocated.v1`
Occurs when either:
1. A payment is made and confirmed as allocated to a specific invoice or statement issued by Two.
2. A previously matched payment is deallocated, for example when a credit note takes priority over the payment.
It is important to note these webhooks are sent only once the payment has been matched (or unmatched) in Two's
system to a specific invoice or statement, so there may be a delay between the buyer making the payment and Two
being able to match that payment to an invoice/statement.
As an example, the following sequence of events show when this webhook may be issued:
* A buyer is issued with an invoice of 1000 GBP (Two issues an Order Invoiced webhook).
* The buyer later pays 400 GBP to Two using the reference provided on the invoice.
* Two will match that payment to the invoice: **a Payment Allocation webhook is issued**.
* The webhook payload will contain the invoice or statement reference Two matched the buyer's payment with
(in the `matched_reference` attribute) as well as some details of the original payment made by the buyer
in the `payment` object.
* The buyer later makes another payment of 600 GBP to Two with the same reference (600 being the remaining
balance to pay for that invoice).
* Two matches the second incoming payment of 600 GBP to the same invoice: **another Payment Allocation webhook
is issued**.
* This webhook will have the same `matched_reference` value, but the details in the `payment` object will be
different because it is a distinct payment from the original 400 GBP payment.
* A credit note is issued against the original invoice of 300 GBP (Two issues a Order Credited webhook).
* One of the payments Two previously matched will be "unmatched" because the refund of 300 GBP against
specific invoices has a higher priority than payments. **Two issues another Payment Allocation webhook,
but the amount will be negative**.
#### Payload
The `data` object in the payload contains IDs that indicate the order and invoice the payment has been allocated
to. Also note the following within the payload:
* `amount`: The amount for this event represents the amount of the buyer's payment that has been used by this
allocation. For payments to Two that are allocated to invoices, this amount will be negative.
For deallocation events (for example, where a credit note has a higher priority than an already-reconciled
payment and causes us to deallocate an existing allocation), the `amount` will be positive. A deallocation
event would typically result in a later `payment_allocated` event where all or part of the same payment
previously allocated is re-allocated against a different invoice; in this situation another
payment allocation event will be sent.
* `payment`: Contains data about the actual transaction Two received from the buyer that has been used in this
payment allocation. See the schema description of this child object for details of each field.
#### Example
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.reconciliation.payment_allocated.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "652a57e2-c2de-437b-96a7-2eeac0a37814",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"invoice_id": "7a5a7b9b-7d9e-4e9e-b9b1-2d7c658e1a4d",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"billing_period_id": "175bda61-c6f2-4b9d-a429-5f31c83ecc10",
"amount": "-123.45",
"currency": "GBP",
"matched_reference": "ACB12345",
"payment": {
"payment_id": "1346ef4c-fae1-43a2-b637-24e0c756d4ce",
"payment_reference": "ABC12345",
"booked_at": "2023-06-21T12:30:12.012345Z",
"payment_amount": "500.05",
"currency": "GBP"
}
}
}
```
#### Triggering in sandbox
1. Create and fulfil a new order (see the `order.reconciliation.invoiced.v1` webhook description for how
to do this) or use an existing order ID for the following steps.
2. Use the "Simulate pay in" endpoint provided in the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
3. Once the simulated payment to us has been received the payment allocation webhook will be sent to any
endpoints subscribed to this event.
Alternatively:
1. [Refund an order](/docs/api/checkout/refund-order-handler-post/) either
fully or partially.
2. A payment allocation webhook will be sent indicating an existing payment has been deallocated for this order
to any endpoints subscribed to this event.
operationId: payment_allocationreconciliation_payment_allocated_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderReconciliationPaymentAllocated"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
reconciliation-credited:
post:
tags:
- Order Reconciliation
summary: Order Credited
description: |-
Type: `order.reconciliation.credited.v1`
Occurs when a credit note is applied against an invoice.
#### Payload
The `data` object in the payload contains IDs that indicate the order and invoice the credit note has been
applied to. Also note the following within the payload:
* `credit_note`: Contains information about the credit note itself, including its ID, the amount on the credit
note and when the credit note was applied.
#### Example
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.reconciliation.credited.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "652a57e2-c2de-437b-96a7-2eeac0a37814",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"invoice_id": "7a5a7b9b-7d9e-4e9e-b9b1-2d7c658e1a4d",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"billing_period_id": "175bda61-c6f2-4b9d-a429-5f31c83ecc10",
"amount": "-101.65",
"currency": "GBP",
"credit_note": {
"refund_id": "433401fe-76ae-4e10-b091-59788c90a5df",
"credited_at": "2023-06-21T12:30:12.012345Z",
"credit_note_amount": "101.65"
}
}
}
```
#### Triggering in sandbox
1. Create and fulfil an order (see the `order.reconciliation.invoiced.v1` webhook for details).
2. [Refund the order](/docs/api/checkout/refund-order-handler-post/) by
using the "Refund order" endpoint from the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
3. Once the refund process is completed, the `order.reconciliation.credited.v1` webhook will be sent to any endpoints subscribed to this event.
operationId: order_creditedreconciliation_credited_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderReconciliationCredited"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
reconciliation-recoursed:
post:
tags:
- Order Reconciliation
summary: Order Recoursed
description: |-
Type: `order.reconciliation.recoursed.v1`
Occurs when Two applies the option to recourse an invoice back to the merchant. This may not be applicable to
your contract with Two so you may never see recourse events.
#### Payload
The `data` object in the payload contains IDs that indicate the order and invoice that have been recoursed. Also
note the following child object within the payload:
* `recourse`: Contains specific information about the recourse event as recorded in the Two system, including
the specific amount that has been recoursed back to the merchant.
#### Example
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.reconciliation.recoursed.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "652a57e2-c2de-437b-96a7-2eeac0a37814",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"invoice_id": "7a5a7b9b-7d9e-4e9e-b9b1-2d7c658e1a4d",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"billing_period_id": "175bda61-c6f2-4b9d-a429-5f31c83ecc10",
"amount": "-101.65",
"currency": "GBP",
"recourse": {
"recourse_id": "4228e51d-45ba-4a7f-a279-0f332bfead9c",
"recoursed_at": "2023-06-31T12:34:56.123456",
"recourse_amount": "101.65"
}
}
}
```
#### Triggering in sandbox
1. Create and fulfil an order (see the `order.reconciliation.invoiced.v1` webhook for details).
2. Recourse the order by using "Recourse order" endpoint from the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
3. Once the recourse simulation is completed, the `order.reconciliation.recoursed.v1` webhook will be sent to any endpoints subscribed to this event.
operationId: order_recoursedreconciliation_recoursed_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderReconciliationRecoursed"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
reconciliation-collected:
post:
tags:
- Order Reconciliation
summary: Order Collected
description: |-
Type: `order.reconciliation.collected.v1`
Occurs when Two reverts to using a collection agency for recovering any outstanding amounts owed by a buyer for
an invoice.
#### Payload
The `data` object in the payload contains IDs that indicate the order and invoice that have been sent to the
collection agency. Also note the following child object within the payload:
* `collection`: Contains specific information about the collection that caused this event, including the amount
Two has asked the collection agency to recover.
#### Example
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.reconciliation.collected.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "652a57e2-c2de-437b-96a7-2eeac0a37814",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"invoice_id": "7a5a7b9b-7d9e-4e9e-b9b1-2d7c658e1a4d",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"billing_period_id": "175bda61-c6f2-4b9d-a429-5f31c83ecc10",
"amount": "-101.65",
"currency": "GBP",
"collection": {
"collection_id": "8d5f0cf6-0aee-4cb3-9723-ee221cdfc681",
"collected_at": "2023-06-30T12:34:56.123456",
"collection_amount": "101.65"
},
}
}
```
#### Triggering in sandbox
1. Create and fulfil an order (see the `order.reconciliation.invoiced.v1` webhook for details).
2. Send the invoice for this order to collections by using the "Collect order" endpoint from the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
3. Once the collection simulation process is completed, the `order.reconciliation.collected.v1` webhook will be sent to any endpoint subscribed to this event.
operationId: order_collectedreconciliation_collected_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderReconciliationCollected"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
verified:
post:
tags:
- Order
summary: Order Verified
description: |-
Type: `order.verified.v1`
Occurs when an order has been successfully verified and is in a fulfillable state.
#### Payload
The `data` object in the payload contains order ID, along with the amount and currency.
#### Example:
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.verified.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_order_id": "999999",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"gross_amount": "150.65",
"invoice_amount": "150.65",
"payable_amount": "150.65",
"prepaid_amount": "0.00",
"currency": "GBP"
"buyer_company_name": "TWO B2B LTD",
"status": "APPROVED",
"state": "VERIFIED",
}
}
```
#### Triggering in sandbox
1. [Create](/docs/api/checkout/create-order-handler-post/) an order through
the checkout API service in your sandbox environment. Capture the order ID from the resulting response.
2. Open the `payment_url` in the response body and complete verification (in production, this step would be completed by the buyer).
3. Once the order state moves from `UNVERIFIED` to `VERIFIED`, the `order.state.verified.v1` webhook will be sent by the webhook gateway to any endpoints you have configured to receive it.
operationId: order_verifiedverified_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderVerified"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
cancelled:
post:
tags:
- Order
summary: Order Cancelled
description: |-
Type: `order.cancelled.v1`
Occurs when an order has been cancelled
#### Payload
The `data` object in the payload contains order ID, along with the amount and currency.
#### Example:
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.cancelled.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_order_id": "999999",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"gross_amount": "150.65",
"invoice_amount": "150.65",
"payable_amount": "150.65",
"prepaid_amount": "0.00",
"currency": "GBP"
"buyer_company_name": "TWO B2B LTD",
"status": "APPROVED",
"state": "CANCELLED",
}
}
```
#### Triggering in sandbox
1. [Create](/docs/api/checkout/create-order-handler-post/) an order through
the checkout API service in your sandbox environment. Capture the order ID from the resulting response.
2. Using the order ID captured, [Cancel](/docs/api/checkout/cancel-order-handler-post/) the order through the checkout API service in your sandbox environment.
3. Once the order state moves from to `CANCELLED`, the `order.cancelled.v1` webhook will be sent by the webhook gateway to any endpoints you have configured to receive it.
operationId: order_cancelledcancelled_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderCancelled"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
fulfilled:
post:
tags:
- Order
summary: Order Fulfilled
description: |-
Type: `order.fulfilled.v1`
Occurs when an order has been fulfilled
#### Payload
The `data` object in the payload contains order ID, along with the amount and currency
#### Example:
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.fulfilled.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_order_id": "999999",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"gross_amount": "150.65",
"invoice_amount": "150.65",
"payable_amount": "150.65",
"prepaid_amount": "0.00",
"currency": "GBP"
"buyer_company_name": "TWO B2B LTD",
"status": "APPROVED",
"state": "FULFILLED",
}
}
```
#### Triggering in sandbox
1. [Create](/docs/api/checkout/create-order-handler-post/) an order through
the checkout API service in your sandbox environment. Capture the order ID from the resulting response.
2. Open the `payment_url` in the response body and complete verification (in production, this step would be completed by the buyer).
3. Using the order ID captured, [Fulfill](/docs/api/checkout/fulfill-order-handler-post/) the order through
the checkout API service in your sandbox environment.
4. Once the order state moves from `Fulfilling` to `Fulfilled`, the `order.fulfilled.v1` webhook will be sent by the webhook gateway to any endpoints you have configured to receive it.
operationId: order_fulfilledfulfilled_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderFulfilled"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
refunded:
post:
tags:
- Order
summary: Order Refunded
description: |-
Type: `order.refunded.v1`
Occurs when an order has been refunded
#### Payload
The `data` object in the payload contains order ID, along with the amount, currency and the amount refunded
#### Example:
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.refunded.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"refund_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_refund_reference": "merchant_refund_reference",
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_order_id": "999999",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"gross_amount": "150.65",
"invoice_amount": "150.65",
"payable_amount": "150.65",
"prepaid_amount": "0.00",
"currency": "GBP"
"buyer_company_name": "TWO B2B LTD",
"refunded_gross_amount": "100.65",
"refunded_payable_amount": "100.65",
"refunded_prepaid_amount": "0.00"
"status": "APPROVED",
"state": "REFUNDED",
}
}
```
#### Triggering in sandbox
1. [Create](/docs/api/checkout/create-order-handler-post/) an order through
the checkout API service in your sandbox environment. Capture the order ID from the resulting response.
2. Open the `payment_url` in the response body and complete verification (in production, this step would be completed by the buyer).
3. Using the order ID captured, [Fulfill](/docs/api/checkout/fulfill-order-handler-post/) the order through
the checkout API service in your sandbox environment.
4. Once the order state moves from `Fulfilling` to `Fulfilled`,
use the order ID captured to [Refund](/docs/api/checkout/refund-order-handler-post/) the order through the checkout API service in your sandbox environment.
5. Once the order state moves to `REFUNDED`, the `order.refunded.v1` webhook will be sent by the webhook gateway to any endpoints you have configured to receive it.
operationId: order_refundedrefunded_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderRefunded"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
rejected:
post:
tags:
- Order
summary: Order Rejected
description: |-
Type: `order.rejected.v1`
Occurs when an order has been rejected
#### Payload
The `data` object in the payload contains order ID, along with the amount, currency and the reason for rejection
#### Example:
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "order.rejected.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "order/a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"refund_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_refund_reference": "merchant_refund_reference",
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"merchant_order_id": "999999",
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"gross_amount": "150.65",
"invoice_amount": "150.65",
"payable_amount": "150.65",
"prepaid_amount": "0.00",
"currency": "GBP"
"buyer_company_name": "TWO B2B LTD",
"decline_reason": "TOO_HIGH_RISK"
"status": "REJECTED",
"state": "UNVERIFIED",
}
}
```
#### Triggering in sandbox
1. [Create](/docs/api/checkout/create-order-handler-post/) an order through
the checkout API service in your sandbox environment. Two can provide example of buyer company to use in
sandbox that will be rejected for credit and should result in `order.refunded.v1` webhook being sent.
operationId: order_rejectedrejected_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderRejected"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
credit-limit-change:
post:
tags:
- Customer Credit Limit
summary: Credit Limit Updated
description: |-
Type: `customer.credit_limit.updated.v1`
Occurs when the available credit for a merchant's buyer changes.
#### Payload
The `data` object in the payload contains identifiers for the buyer organisation, as well as the new available
credit limit information. If the credit limit changes such that Two no longer accepts the buyer, the payload may
include a reason for the change.
#### Example
```json
{
"specversion":"1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "customer.credit_limit.updated.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "customer/GB/12345678",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"buyer_organization_number": "12345678",
"country": "GB",
"credit_limit": "1000.00",
"credit_limit_balance": "800.00",
"max_single_order_value": "100.00",
"buyer_is_in_arrears": true,
"currency": "GBP",
"credit_approved": false,
"decline_reason": "Buyer is late on existing active invoices that need to be cleared before they are able to place more orders."
}
}
```
#### Triggering in sandbox
1. Create and fulfil an order (see the `order.reconciliation.invoiced.v1` webhook for details).
2. [Refund the order](/docs/api/checkout/refund-order-handler-post/). You can use the example provided in the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
3. Once the refund is processed, the `customer.credit_limit.updated.v1` webhook will be sent to any endpoints subscribed to this event.
Alternatively, you can trigger a simulated credit limit update for a given combination of buyer organisation number, country code and currency using the "Simulate credit limit update" endpoint in the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
operationId: credit_limit_updatedcredit_limit_change_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/CreditLimitUpdatedEvent"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
billing-statement-issued:
post:
tags:
- Billing Statement
summary: Billing Statement Issued
description: |-
Type: `billing_statement.created.v1`
Occurs when a billing statement is issued.
#### Payload
The `data` object in the payload contains details of all invoices and credit notes related to the statement.
These credit notes and invoices will all have the same `billing_period_id` in the credit note issued and invoice
issued webhooks, respectively.
#### Example
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "billing_statement.created.v1",
"time": "2023-06-21T12:34:56.123456Z",
"source": "https://api.two.inc",
"subject": "billing_account/c8b27c7c-3362-4c10-b4e5-7d68c8b554be",
"twomerchantid":"b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"data": {
"invoices": [
{
"root_order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"order_id": "a9f5d2d3-5d6d-4e2a-a4b4-6c7f8a9d0f1e",
"invoice_id": "7a5a7b9b-7d9e-4e9e-b9b1-2d7c658e1a4d",
"amount": "190.65",
},
]
"credit_notes": [
{
"refund_id": "433401fe-76ae-4e10-b091-59788c90a5df",
"credited_amount": "-40.00"
},
]
"merchant_id": "b6b9d5d1-f6b7-4e15-9703-9c32c6e5c1c2",
"billing_period_id": "175bda61-c6f2-4b9d-a429-5f31c83ecc10",
"statement_number": "1004",
"payment_reference": "234234234",
"gross_amount": "150.65",
"outstanding_amount": "120.65",
"currency": "GBP"
"due_date": "2023-06-21T12:34:56.123456Z",
"issue_date": "2023-06-05T12:34:56.123456Z",
"billing_account_id": "c8b27c7c-3362-4c10-b4e5-7d68c8b554be",
}
}
```
#### Triggering in sandbox
1. [Create a billing account](/docs/api/billing-account/create-billing-account-post/) using the billing account API.
This is also available in the [Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
Note the ID of the billing account returned in the response to use in the next step.
2. [Create an order](/docs/api/checkout/create-order-handler-post/) and use the billing account ID returned in the response from step 1 in the `"billing_account_id": "<id>"` field
in the body of the request.
3. Fulfil the order (see the `order.reconciliation.invoiced.v1` for details).
4. (Optional) If you want to include multiple orders in the statement, repeat steps 2 and 3 to create multiple fulfilled orders for the same billing account.
5. Create a statement by using the "Simulate close billing statement" endpoint from the
[Two webhooks Postman collection](/docs/guides/order-webhooks-api-page/#webhook-postman-collection).
6. One the billing statement has been issued, the `billing_statement.created.v1` webhook will be sent to any endpoints subscribed to this event.
operationId: billing_statement_issuedbilling_statement_issued_post
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/BillingStatementEvent"
required: true
responses:
"200":
description: Successful Response
content:
application/json:
schema: {}
"422":
description: Validation Error
content:
application/json:
schema:
$ref: "#/components/schemas/HTTPValidationError"
business-registry-approved:
post:
tags:
- Business Registry
summary: Business Registry Approved
description: |-
Type: `business_registry.approved.v1`
Occurs when a proposal to enroll a new business (e.g. a sole trader) has been approved, the enrollment has
been completed, and the new business is ready for ordering/trade account creation/etc.
#### Payload
The `data` object in the payload contains the following:
- <merchant_id> is your unique identifier within TWO's system
- <proposal_id> is the identifier of the proposal that has been approved. You may retrieve this proposal via the
Business Registration API.
- <organization_number> is the synthetic organization number generated by TWO for the newly enrolled business.
Use this organization number when creating trade accounts, orders or other assets on behalf of the buyer.
#### Example
```json
{
"specversion": "1.0",
"id": "01FBJ0PYJ7931K0CJ6GMP8N3WG",
"type": "business_registry.approved.v1",