@jskit-ai/payments-core 0.2.36 → 0.2.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +72 -8
- package/contracts/configuration.schema.json +56 -1
- package/contracts/conformance.json +484 -0
- package/docs/conformance.md +34 -5
- package/docs/contract.md +59 -2
- package/docs/standalone.md +18 -4
- package/locales/en.json +17 -5
- package/migrations/payments_core_top_ups.cjs +28 -0
- package/package.json +10 -6
- package/src/server/checkout.js +111 -5
- package/src/server/errors.js +4 -3
- package/src/server/paymentResources.js +16 -2
- package/src/server/paymentStore.js +35 -3
- package/src/server/stripe.js +112 -1
- package/src/server/topUps.js +97 -0
- package/src/server/types.js +76 -1
- package/src/shared/configuration.js +9 -0
- package/src/shared/topUps.js +5 -0
- package/test/checkout.test.js +4 -4
- package/test/conformance.test.js +76 -1
- package/test/history.test.js +1 -1
- package/test/i18nCatalog.test.js +3 -1
- package/test/paymentStore.mysql.test.js +3 -3
- package/test/paymentStoreFeature.test.js +15 -3
- package/test/support/fakeStripe.js +112 -0
- package/test/support/migrations.js +11 -0
- package/test/support/topUpApp.js +85 -0
- package/test/topUps.mysql.test.js +104 -0
- package/test/topUps.test.js +307 -0
|
@@ -468,6 +468,201 @@
|
|
|
468
468
|
},
|
|
469
469
|
"schemaValid": true,
|
|
470
470
|
"configurationValid": false
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"id": "stripe-top-ups",
|
|
474
|
+
"document": {
|
|
475
|
+
"integrations": {
|
|
476
|
+
"billing": {
|
|
477
|
+
"provider": "stripe",
|
|
478
|
+
"accountMode": "shared",
|
|
479
|
+
"authentication": {
|
|
480
|
+
"method": "api-key",
|
|
481
|
+
"secretRef": "env:STRIPE_KEY"
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
"extensions": {
|
|
486
|
+
"payments": {
|
|
487
|
+
"version": 1,
|
|
488
|
+
"environments": {
|
|
489
|
+
"sandbox": {
|
|
490
|
+
"integrationId": "billing",
|
|
491
|
+
"providerAccountId": "acct_fixture",
|
|
492
|
+
"webhookSecretRef": "env:STRIPE_WEBHOOK_SECRET",
|
|
493
|
+
"returnUrlRef": "env:BILLING_RETURN_URL"
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
"plans": {},
|
|
497
|
+
"topUps": {
|
|
498
|
+
"name": "Credits",
|
|
499
|
+
"currency": "USD",
|
|
500
|
+
"minimumAmount": 100,
|
|
501
|
+
"maximumAmount": 50000
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
"schemaValid": true,
|
|
507
|
+
"configurationValid": true
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
"id": "paddle-top-ups",
|
|
511
|
+
"document": {
|
|
512
|
+
"integrations": {
|
|
513
|
+
"billing": {
|
|
514
|
+
"provider": "paddle",
|
|
515
|
+
"accountMode": "shared",
|
|
516
|
+
"authentication": {
|
|
517
|
+
"method": "api-key",
|
|
518
|
+
"secretRef": "env:STRIPE_KEY"
|
|
519
|
+
},
|
|
520
|
+
"settings": {
|
|
521
|
+
"environment": "sandbox"
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
"extensions": {
|
|
526
|
+
"payments": {
|
|
527
|
+
"version": 1,
|
|
528
|
+
"environments": {
|
|
529
|
+
"sandbox": {
|
|
530
|
+
"integrationId": "billing",
|
|
531
|
+
"providerAccountId": "acct_fixture",
|
|
532
|
+
"webhookSecretRef": "env:STRIPE_WEBHOOK_SECRET",
|
|
533
|
+
"returnUrlRef": "env:BILLING_RETURN_URL",
|
|
534
|
+
"taxCategory": "saas",
|
|
535
|
+
"publicClientTokenRef": "env:PADDLE_CLIENT_TOKEN"
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
"plans": {
|
|
539
|
+
"pro": {
|
|
540
|
+
"name": "Pro",
|
|
541
|
+
"amount": 1200,
|
|
542
|
+
"currency": "USD",
|
|
543
|
+
"interval": "month",
|
|
544
|
+
"features": [
|
|
545
|
+
"export"
|
|
546
|
+
],
|
|
547
|
+
"renewalCredits": 100
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
"topUps": {
|
|
551
|
+
"name": "Credits",
|
|
552
|
+
"currency": "USD",
|
|
553
|
+
"minimumAmount": 100,
|
|
554
|
+
"maximumAmount": 50000
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
},
|
|
559
|
+
"schemaValid": true,
|
|
560
|
+
"configurationValid": false
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
"id": "top-up-below-stripe-minimum",
|
|
564
|
+
"document": {
|
|
565
|
+
"integrations": {
|
|
566
|
+
"billing": {
|
|
567
|
+
"provider": "stripe",
|
|
568
|
+
"accountMode": "shared",
|
|
569
|
+
"authentication": {
|
|
570
|
+
"method": "api-key",
|
|
571
|
+
"secretRef": "env:STRIPE_KEY"
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
"extensions": {
|
|
576
|
+
"payments": {
|
|
577
|
+
"version": 1,
|
|
578
|
+
"environments": {
|
|
579
|
+
"sandbox": {
|
|
580
|
+
"integrationId": "billing",
|
|
581
|
+
"providerAccountId": "acct_fixture",
|
|
582
|
+
"webhookSecretRef": "env:STRIPE_WEBHOOK_SECRET",
|
|
583
|
+
"returnUrlRef": "env:BILLING_RETURN_URL"
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
"plans": {},
|
|
587
|
+
"topUps": {
|
|
588
|
+
"name": "Credits",
|
|
589
|
+
"currency": "USD",
|
|
590
|
+
"minimumAmount": 49,
|
|
591
|
+
"maximumAmount": 50000
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
"schemaValid": false,
|
|
597
|
+
"configurationValid": false
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"id": "top-up-range-inverted",
|
|
601
|
+
"document": {
|
|
602
|
+
"integrations": {
|
|
603
|
+
"billing": {
|
|
604
|
+
"provider": "stripe",
|
|
605
|
+
"accountMode": "shared",
|
|
606
|
+
"authentication": {
|
|
607
|
+
"method": "api-key",
|
|
608
|
+
"secretRef": "env:STRIPE_KEY"
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
"extensions": {
|
|
613
|
+
"payments": {
|
|
614
|
+
"version": 1,
|
|
615
|
+
"environments": {
|
|
616
|
+
"sandbox": {
|
|
617
|
+
"integrationId": "billing",
|
|
618
|
+
"providerAccountId": "acct_fixture",
|
|
619
|
+
"webhookSecretRef": "env:STRIPE_WEBHOOK_SECRET",
|
|
620
|
+
"returnUrlRef": "env:BILLING_RETURN_URL"
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
"plans": {},
|
|
624
|
+
"topUps": {
|
|
625
|
+
"name": "Credits",
|
|
626
|
+
"currency": "USD",
|
|
627
|
+
"minimumAmount": 5000,
|
|
628
|
+
"maximumAmount": 1000
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
},
|
|
633
|
+
"schemaValid": true,
|
|
634
|
+
"configurationValid": false
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
"id": "nothing-to-sell",
|
|
638
|
+
"document": {
|
|
639
|
+
"integrations": {
|
|
640
|
+
"billing": {
|
|
641
|
+
"provider": "stripe",
|
|
642
|
+
"accountMode": "shared",
|
|
643
|
+
"authentication": {
|
|
644
|
+
"method": "api-key",
|
|
645
|
+
"secretRef": "env:STRIPE_KEY"
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
},
|
|
649
|
+
"extensions": {
|
|
650
|
+
"payments": {
|
|
651
|
+
"version": 1,
|
|
652
|
+
"environments": {
|
|
653
|
+
"sandbox": {
|
|
654
|
+
"integrationId": "billing",
|
|
655
|
+
"providerAccountId": "acct_fixture",
|
|
656
|
+
"webhookSecretRef": "env:STRIPE_WEBHOOK_SECRET",
|
|
657
|
+
"returnUrlRef": "env:BILLING_RETURN_URL"
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
"plans": {}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
"schemaValid": false,
|
|
665
|
+
"configurationValid": false
|
|
471
666
|
}
|
|
472
667
|
],
|
|
473
668
|
"accountScenario": {
|
|
@@ -714,5 +909,294 @@
|
|
|
714
909
|
}
|
|
715
910
|
}
|
|
716
911
|
]
|
|
912
|
+
},
|
|
913
|
+
"topUpScenario": {
|
|
914
|
+
"document": {
|
|
915
|
+
"integrations": {
|
|
916
|
+
"billing": {
|
|
917
|
+
"provider": "stripe",
|
|
918
|
+
"accountMode": "shared",
|
|
919
|
+
"authentication": {
|
|
920
|
+
"method": "api-key",
|
|
921
|
+
"secretRef": "env:STRIPE_KEY"
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
"extensions": {
|
|
926
|
+
"payments": {
|
|
927
|
+
"version": 1,
|
|
928
|
+
"environments": {
|
|
929
|
+
"sandbox": {
|
|
930
|
+
"integrationId": "billing",
|
|
931
|
+
"providerAccountId": "acct_fixture",
|
|
932
|
+
"webhookSecretRef": "env:STRIPE_WEBHOOK_SECRET",
|
|
933
|
+
"returnUrlRef": "env:BILLING_RETURN_URL"
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
"plans": {
|
|
937
|
+
"pro": {
|
|
938
|
+
"name": "Pro",
|
|
939
|
+
"amount": 1200,
|
|
940
|
+
"currency": "USD",
|
|
941
|
+
"interval": "month",
|
|
942
|
+
"features": [
|
|
943
|
+
"export"
|
|
944
|
+
],
|
|
945
|
+
"renewalCredits": 100
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
"topUps": {
|
|
949
|
+
"name": "Credits",
|
|
950
|
+
"currency": "USD",
|
|
951
|
+
"minimumAmount": 100,
|
|
952
|
+
"maximumAmount": 50000
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
},
|
|
957
|
+
"scope": {
|
|
958
|
+
"applicationId": "app-fixture",
|
|
959
|
+
"integrationId": "billing",
|
|
960
|
+
"providerAccountId": "acct_fixture",
|
|
961
|
+
"environment": "sandbox",
|
|
962
|
+
"subjectId": "tenant-a"
|
|
963
|
+
},
|
|
964
|
+
"steps": [
|
|
965
|
+
{
|
|
966
|
+
"operation": "topUp",
|
|
967
|
+
"topUp": "first",
|
|
968
|
+
"input": {
|
|
969
|
+
"amount": 99,
|
|
970
|
+
"requestId": "top-up-one"
|
|
971
|
+
},
|
|
972
|
+
"error": "payment_top_up_amount_invalid"
|
|
973
|
+
},
|
|
974
|
+
{
|
|
975
|
+
"operation": "topUp",
|
|
976
|
+
"topUp": "first",
|
|
977
|
+
"input": {
|
|
978
|
+
"amount": 500,
|
|
979
|
+
"requestId": "top-up-one"
|
|
980
|
+
},
|
|
981
|
+
"expect": {
|
|
982
|
+
"status": "open",
|
|
983
|
+
"amount": 500,
|
|
984
|
+
"currency": "USD"
|
|
985
|
+
}
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
"operation": "topUp",
|
|
989
|
+
"topUp": "first",
|
|
990
|
+
"input": {
|
|
991
|
+
"amount": 700,
|
|
992
|
+
"requestId": "top-up-one"
|
|
993
|
+
},
|
|
994
|
+
"error": "payment_reference_conflict"
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
"operation": "topUp",
|
|
998
|
+
"topUp": "first",
|
|
999
|
+
"input": {
|
|
1000
|
+
"amount": 500,
|
|
1001
|
+
"requestId": "top-up-one"
|
|
1002
|
+
},
|
|
1003
|
+
"expect": {
|
|
1004
|
+
"status": "open",
|
|
1005
|
+
"amount": 500,
|
|
1006
|
+
"currency": "USD"
|
|
1007
|
+
}
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
"operation": "settle",
|
|
1011
|
+
"topUp": "first",
|
|
1012
|
+
"door": "return",
|
|
1013
|
+
"facts": {
|
|
1014
|
+
"outcome": "open",
|
|
1015
|
+
"amount": 500,
|
|
1016
|
+
"currency": "USD"
|
|
1017
|
+
},
|
|
1018
|
+
"expect": {
|
|
1019
|
+
"status": "open",
|
|
1020
|
+
"credited": false
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
"operation": "settle",
|
|
1025
|
+
"topUp": "first",
|
|
1026
|
+
"door": "webhook",
|
|
1027
|
+
"facts": {
|
|
1028
|
+
"outcome": "processing",
|
|
1029
|
+
"amount": 500,
|
|
1030
|
+
"currency": "USD"
|
|
1031
|
+
},
|
|
1032
|
+
"expect": {
|
|
1033
|
+
"status": "processing",
|
|
1034
|
+
"credited": false
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
1037
|
+
{
|
|
1038
|
+
"operation": "settle",
|
|
1039
|
+
"topUp": "first",
|
|
1040
|
+
"door": "webhook",
|
|
1041
|
+
"facts": {
|
|
1042
|
+
"outcome": "paid",
|
|
1043
|
+
"amount": 400,
|
|
1044
|
+
"currency": "USD"
|
|
1045
|
+
},
|
|
1046
|
+
"error": "payment_provider_result_invalid"
|
|
1047
|
+
},
|
|
1048
|
+
{
|
|
1049
|
+
"operation": "credits",
|
|
1050
|
+
"expect": []
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
"operation": "settle",
|
|
1054
|
+
"topUp": "first",
|
|
1055
|
+
"door": "return",
|
|
1056
|
+
"facts": {
|
|
1057
|
+
"outcome": "paid",
|
|
1058
|
+
"amount": 500,
|
|
1059
|
+
"currency": "USD"
|
|
1060
|
+
},
|
|
1061
|
+
"expect": {
|
|
1062
|
+
"status": "paid",
|
|
1063
|
+
"credited": true
|
|
1064
|
+
}
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
"operation": "settle",
|
|
1068
|
+
"topUp": "first",
|
|
1069
|
+
"door": "webhook",
|
|
1070
|
+
"facts": {
|
|
1071
|
+
"outcome": "paid",
|
|
1072
|
+
"amount": 500,
|
|
1073
|
+
"currency": "USD"
|
|
1074
|
+
},
|
|
1075
|
+
"expect": {
|
|
1076
|
+
"status": "paid",
|
|
1077
|
+
"credited": false
|
|
1078
|
+
}
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
"operation": "settle",
|
|
1082
|
+
"topUp": "first",
|
|
1083
|
+
"door": "webhook",
|
|
1084
|
+
"facts": {
|
|
1085
|
+
"outcome": "failed",
|
|
1086
|
+
"amount": 500,
|
|
1087
|
+
"currency": "USD"
|
|
1088
|
+
},
|
|
1089
|
+
"expect": {
|
|
1090
|
+
"status": "paid",
|
|
1091
|
+
"credited": false
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
"operation": "credits",
|
|
1096
|
+
"expect": [
|
|
1097
|
+
{
|
|
1098
|
+
"subjectId": "tenant-a",
|
|
1099
|
+
"amount": 500,
|
|
1100
|
+
"currency": "USD"
|
|
1101
|
+
}
|
|
1102
|
+
]
|
|
1103
|
+
},
|
|
1104
|
+
{
|
|
1105
|
+
"operation": "topUp",
|
|
1106
|
+
"topUp": "other",
|
|
1107
|
+
"subjectId": "tenant-b",
|
|
1108
|
+
"input": {
|
|
1109
|
+
"amount": 300,
|
|
1110
|
+
"requestId": "top-up-one"
|
|
1111
|
+
},
|
|
1112
|
+
"expect": {
|
|
1113
|
+
"status": "open",
|
|
1114
|
+
"amount": 300,
|
|
1115
|
+
"currency": "USD"
|
|
1116
|
+
}
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
"operation": "settle",
|
|
1120
|
+
"topUp": "other",
|
|
1121
|
+
"subjectId": "tenant-b",
|
|
1122
|
+
"door": "webhook",
|
|
1123
|
+
"facts": {
|
|
1124
|
+
"outcome": "failed",
|
|
1125
|
+
"amount": 300,
|
|
1126
|
+
"currency": "USD"
|
|
1127
|
+
},
|
|
1128
|
+
"expect": {
|
|
1129
|
+
"status": "failed",
|
|
1130
|
+
"credited": false
|
|
1131
|
+
}
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
"operation": "settle",
|
|
1135
|
+
"topUp": "other",
|
|
1136
|
+
"subjectId": "tenant-b",
|
|
1137
|
+
"door": "webhook",
|
|
1138
|
+
"facts": {
|
|
1139
|
+
"outcome": "expired",
|
|
1140
|
+
"amount": 300,
|
|
1141
|
+
"currency": "USD"
|
|
1142
|
+
},
|
|
1143
|
+
"expect": {
|
|
1144
|
+
"status": "failed",
|
|
1145
|
+
"credited": false
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
"operation": "topUp",
|
|
1150
|
+
"topUp": "third",
|
|
1151
|
+
"subjectId": "tenant-b",
|
|
1152
|
+
"input": {
|
|
1153
|
+
"amount": 300,
|
|
1154
|
+
"requestId": "top-up-two"
|
|
1155
|
+
},
|
|
1156
|
+
"expect": {
|
|
1157
|
+
"status": "open"
|
|
1158
|
+
}
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
"operation": "settle",
|
|
1162
|
+
"topUp": "third",
|
|
1163
|
+
"subjectId": "tenant-b",
|
|
1164
|
+
"door": "return",
|
|
1165
|
+
"facts": {
|
|
1166
|
+
"outcome": "expired",
|
|
1167
|
+
"amount": 300,
|
|
1168
|
+
"currency": "USD"
|
|
1169
|
+
},
|
|
1170
|
+
"expect": {
|
|
1171
|
+
"status": "expired",
|
|
1172
|
+
"credited": false
|
|
1173
|
+
}
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
"operation": "settle",
|
|
1177
|
+
"topUp": "third",
|
|
1178
|
+
"subjectId": "tenant-b",
|
|
1179
|
+
"door": "webhook",
|
|
1180
|
+
"facts": {
|
|
1181
|
+
"outcome": "processing",
|
|
1182
|
+
"amount": 300,
|
|
1183
|
+
"currency": "USD"
|
|
1184
|
+
},
|
|
1185
|
+
"expect": {
|
|
1186
|
+
"status": "expired",
|
|
1187
|
+
"credited": false
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
{
|
|
1191
|
+
"operation": "credits",
|
|
1192
|
+
"expect": [
|
|
1193
|
+
{
|
|
1194
|
+
"subjectId": "tenant-a",
|
|
1195
|
+
"amount": 500,
|
|
1196
|
+
"currency": "USD"
|
|
1197
|
+
}
|
|
1198
|
+
]
|
|
1199
|
+
}
|
|
1200
|
+
]
|
|
717
1201
|
}
|
|
718
1202
|
}
|
package/docs/conformance.md
CHANGED
|
@@ -28,6 +28,9 @@ For each named payment environment:
|
|
|
28
28
|
4. For Paddle, require the integration's `settings.environment` to equal the
|
|
29
29
|
payment environment, and require `taxCategory` and `publicClientTokenRef` in
|
|
30
30
|
the payment binding. Their values already passed the payment schema.
|
|
31
|
+
5. With `topUps`, refuse every environment bound to a Paddle integration (top-ups
|
|
32
|
+
are Stripe Checkout payments), and refuse a `minimumAmount` above
|
|
33
|
+
`maximumAmount`.
|
|
31
34
|
|
|
32
35
|
The examples distinguish malformed prices/credits/features and inline secrets
|
|
33
36
|
from structurally valid but unresolved or mismatched merchant connections.
|
|
@@ -63,6 +66,30 @@ from another tenant, expiry exactly at period end, expired refunds, promotional
|
|
|
63
66
|
credits and rejection of overspending. Credit expiry and feature access are
|
|
64
67
|
separate assertions. An expired allowance never becomes a fresh grant on retry.
|
|
65
68
|
|
|
69
|
+
## Top-up sequence
|
|
70
|
+
|
|
71
|
+
`topUpScenario` supplies a configuration with `topUps`, a merchant and subject
|
|
72
|
+
scope, and `steps` run in order against a fresh database, with a controlled
|
|
73
|
+
provider in place of Stripe:
|
|
74
|
+
|
|
75
|
+
- `topUp` starts a top-up for the step's subject (`subjectId`, else the
|
|
76
|
+
scenario's) with `input` (`amount`, `requestId`), authorized by that subject.
|
|
77
|
+
`topUp` names it for later steps. The controlled provider answers each new
|
|
78
|
+
Checkout session with an id of its own.
|
|
79
|
+
- `settle` reports `facts` (`outcome`, `amount`, `currency`) for the named
|
|
80
|
+
top-up's session through `door`: `webhook` as a verified provider event,
|
|
81
|
+
`return` as the return page's confirmation, for which the server reads those
|
|
82
|
+
facts from the provider. Both doors settle through the same operation.
|
|
83
|
+
- `credits` lists every credit the application's credit function received, in
|
|
84
|
+
order, as `subjectId`, `amount` and `currency`.
|
|
85
|
+
|
|
86
|
+
`expect` and `error` work as in the account sequence. The sequence covers the
|
|
87
|
+
amount limits, a repeated request and a conflicting one, an unpaid return, a
|
|
88
|
+
bank payment still processing, a paid amount that differs from the top-up's
|
|
89
|
+
(refused, nothing credited), the return and the webhook reporting one payment
|
|
90
|
+
(credited once), a late failure after payment, another subject's top-up with the
|
|
91
|
+
same request id, and failed and expired top-ups that a later report never moves.
|
|
92
|
+
|
|
66
93
|
## Framework and CLI ownership
|
|
67
94
|
|
|
68
95
|
A Laravel application uses its own JSON parser/validator, policies, models,
|
|
@@ -78,11 +105,13 @@ preserve these same values rather than inventing a different hosted payment form
|
|
|
78
105
|
|
|
79
106
|
## Evidence boundaries
|
|
80
107
|
|
|
81
|
-
The package's `test/conformance.test.js` checks all configuration examples
|
|
82
|
-
|
|
83
|
-
An independent Python draft-07 validator plus the explicit
|
|
84
|
-
checked the 11 configuration examples without
|
|
85
|
-
|
|
108
|
+
The package's `test/conformance.test.js` checks all configuration examples, the
|
|
109
|
+
full account sequence and the top-up sequence against the actual JSKIT service
|
|
110
|
+
and SQLite storage. An independent Python draft-07 validator plus the explicit
|
|
111
|
+
reference rules also checked the first 11 configuration examples without
|
|
112
|
+
importing Node or JSKIT; the five top-up examples added later have been checked
|
|
113
|
+
by the JSKIT test only. This establishes independent interpretation of
|
|
114
|
+
configuration, not a PHP payment engine.
|
|
86
115
|
|
|
87
116
|
Native Laravel execution, cross-process MySQL/PostgreSQL transactions, raw webhook
|
|
88
117
|
delivery and real provider checkout are separate evidence. These examples do not
|
package/docs/contract.md
CHANGED
|
@@ -48,6 +48,13 @@ payment environment are refused with `payment_sandbox_only` (409), before any
|
|
|
48
48
|
provider write; the sandbox environment works everywhere. Pass
|
|
49
49
|
`appEnv: appEnvironment(env)` to `createPaymentCheckoutService`.
|
|
50
50
|
|
|
51
|
+
A live Stripe key (`sk_live_`, `rk_live_`) is refused outside production as
|
|
52
|
+
well: `createStripePaymentAdapter` takes `appEnv` and throws
|
|
53
|
+
`payment_live_key_refused` (409) unless it is `production`. Test keys work in
|
|
54
|
+
every environment. Its `apiBaseUrl`, a stand-in for Stripe's API so that tests
|
|
55
|
+
never reach Stripe, is taken only in `development` and `test`
|
|
56
|
+
(`payment_stand_in_refused`, 409, elsewhere).
|
|
57
|
+
|
|
51
58
|
An amount is an integer in the currency's smallest unit. ISO-looking currency
|
|
52
59
|
syntax is not evidence the provider accepts that currency. Initial plans are
|
|
53
60
|
one recurring item, quantity one, monthly or yearly. Logical plan IDs are source
|
|
@@ -74,10 +81,58 @@ Cancellation removes feature access but does not revoke an existing credit lot
|
|
|
74
81
|
before its recorded expiry. Monetary refunds/chargebacks do not yet implement
|
|
75
82
|
automatic credit clawback: that remains explicit application reconciliation.
|
|
76
83
|
|
|
77
|
-
|
|
84
|
+
## Prepaid top-ups
|
|
85
|
+
|
|
86
|
+
`topUps`, beside `plans`, lets a person pay a one-off amount they choose into the
|
|
87
|
+
application's own balance:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
"topUps": { "name": "Credits", "currency": "USD", "minimumAmount": 100, "maximumAmount": 50000 }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`name` is the product line on the payment page. Amounts are integers in the
|
|
94
|
+
currency's smallest unit; Stripe takes nothing below 50, and `minimumAmount`
|
|
95
|
+
must not exceed `maximumAmount`. A configuration sells plans, top-ups or both:
|
|
96
|
+
`plans` may be empty only when `topUps` is present. Top-ups are one-off Stripe
|
|
97
|
+
Checkout payments: an environment bound to a Paddle connection fails validation
|
|
98
|
+
at its `integrationId` with `payments.configuration.paddleTopUps`.
|
|
99
|
+
|
|
100
|
+
A top-up is written down before the provider hears of it, for the billable
|
|
101
|
+
subject the application authorized (action `topUp`) and the amount it chose
|
|
102
|
+
within the limits (`payment_top_up_amount_invalid`, 422, outside them). One
|
|
103
|
+
request ID is one top-up: a repeated request answers it, and the same request
|
|
104
|
+
ID with another amount is `payment_reference_conflict`. Its Checkout payment
|
|
105
|
+
comes back to the application's return URL with `?paymentTopUp=<topUpId>`,
|
|
106
|
+
paid or not. That parameter only names the top-up; it is never evidence.
|
|
107
|
+
|
|
108
|
+
Two doors settle a top-up, and both take one path. The verified webhook carries
|
|
109
|
+
the provider's signed facts; the return page asks the server to confirm, and the
|
|
110
|
+
server reads the Checkout session from the provider with its own key. Neither
|
|
111
|
+
door names a subject: the top-up written down at checkout is the authority, and
|
|
112
|
+
an event for a session not made for one of this merchant's top-ups is
|
|
113
|
+
acknowledged and ignored. Under the top-up's row lock the reported outcome moves
|
|
114
|
+
its status (`open`, `processing` for a bank payment that has not cleared, then
|
|
115
|
+
`paid`, `failed` or `expired`); paid wins over every other status, and failed or
|
|
116
|
+
expired never undo a payment. Only the move to `paid` credits, by calling the
|
|
117
|
+
application's credit function inside the same database transaction, with a
|
|
118
|
+
stable reference `top-up:<topUpId>`, the amount and the currency, after checking
|
|
119
|
+
that the provider took exactly the top-up's amount and currency. Whichever door
|
|
120
|
+
comes second finds the top-up paid and credits nothing. A credit that fails
|
|
121
|
+
rolls the settlement back, and the next report credits it.
|
|
122
|
+
|
|
123
|
+
The application's balance is its own: a balance in its database writes the
|
|
124
|
+
credit through the transaction options it is given, so the credit and the
|
|
125
|
+
settlement commit together; a balance kept elsewhere must stay idempotent on the
|
|
126
|
+
reference, since the call can run again after a rolled-back attempt.
|
|
127
|
+
|
|
128
|
+
A trusted app can grant promotional or other usage units with `grantCredits`:
|
|
78
129
|
positive integer `units`, stable business `reference`, and either an explicit
|
|
79
130
|
millisecond expiry or `null` for no expiry. This call does not collect money or
|
|
80
|
-
prove payment. Only call it after the app's own verified funding/business event
|
|
131
|
+
prove payment. Only call it after the app's own verified funding/business event,
|
|
132
|
+
such as a top-up's credit call. It commits in a transaction of its own, once per
|
|
133
|
+
reference, so a credit function that grants through it is idempotent on the
|
|
134
|
+
top-up's reference but not atomic with the settlement; on a database with one
|
|
135
|
+
connection (SQLite in tests) it would wait for the settlement's own.
|
|
81
136
|
|
|
82
137
|
Debits consume the soonest-expiring valid lot first and cannot create a negative
|
|
83
138
|
balance. A stable reference denotes one business action. Reusing it with a
|
|
@@ -103,6 +158,8 @@ must preserve these observable behaviors:
|
|
|
103
158
|
| Inspect account | Authenticated access to the billable subject; balance, features, subscriptions; no remote mutation |
|
|
104
159
|
| Billing history | Explicit billing-read policy for the subject; app-resolved customer, one filtered provider page, bounded display fields; no grant or mutation |
|
|
105
160
|
| Checkout | Billing-management policy, configured logical plan, trusted contact email and stable request ID; provider URL |
|
|
161
|
+
| Top up | `topUp` policy for the subject, an amount within the configured limits and a stable request ID; the top-up recorded before the provider is asked; provider URL |
|
|
162
|
+
| Settle a top-up | Verified webhook facts or the provider's session read with the server's key; the recorded top-up's subject and amount; status and credit committed together, once |
|
|
106
163
|
| Portal | Billing-management policy, server-bound customer; provider URL |
|
|
107
164
|
| Verify webhook | Raw bytes and signing secret for the exact environment; no reliance on a browser session |
|
|
108
165
|
| Reconcile event | Verified event, server customer binding, fresh provider facts and atomic receipt/state/grant |
|
package/docs/standalone.md
CHANGED
|
@@ -126,16 +126,25 @@ const historicalPriceBindings = Object.fromEntries(published.history
|
|
|
126
126
|
.map((plan) => [plan.priceId, plan.planId]));
|
|
127
127
|
const adapter = createStripePaymentAdapter({
|
|
128
128
|
apiKey, webhookSecret, environment, providerAccountId: binding.providerAccountId,
|
|
129
|
-
priceBindings, historicalPriceBindings
|
|
129
|
+
priceBindings, historicalPriceBindings,
|
|
130
|
+
// A live key (sk_live_, rk_live_) is refused unless APP_ENV is production; test keys work everywhere.
|
|
131
|
+
appEnv: appEnvironment(process.env)
|
|
130
132
|
});
|
|
131
133
|
const catalogue = createPaymentCatalogue({ store, adapter, scope: merchantScope, configuration });
|
|
132
134
|
const checkout = createPaymentCheckoutService({
|
|
133
135
|
adapter, store, payments, merchantScope, returnUrl, authorize: authorizeBilling,
|
|
134
136
|
// Only production (APP_ENV) takes real money; elsewhere the live payment environment is refused.
|
|
135
|
-
appEnv: appEnvironment(process.env)
|
|
137
|
+
appEnv: appEnvironment(process.env),
|
|
138
|
+
// Only when the configuration declares topUps: the application's balance gains each paid top-up once.
|
|
139
|
+
...(configuration.topUps ? { topUps: { offer: configuration.topUps, credit: creditBalance } } : {})
|
|
136
140
|
});
|
|
137
141
|
```
|
|
138
142
|
|
|
143
|
+
`creditBalance({reference, subjectId, amount, currency}, options)` is the
|
|
144
|
+
application's own: it adds a paid top-up to the subject's balance, writing
|
|
145
|
+
through `options` (its handles join the settling transaction), and is called
|
|
146
|
+
once per paid top-up.
|
|
147
|
+
|
|
139
148
|
The returned objects stay inside the backend. Never serialize the environment,
|
|
140
149
|
adapter or secret-bearing startup variables to the client. `authorizeBilling`
|
|
141
150
|
must return exactly `true` only for an actor allowed to manage the requested
|
|
@@ -150,7 +159,11 @@ publication, rebuild this composition from the current bindings (or restart the
|
|
|
150
159
|
app) before accepting checkout requests. An empty catalogue cannot sell a plan.
|
|
151
160
|
|
|
152
161
|
Map authenticated checkout and portal routes to the corresponding `checkout`
|
|
153
|
-
methods
|
|
162
|
+
methods, and, with top-ups, a route that starts one
|
|
163
|
+
(`checkout.topUp({actor, subjectId, amount, requestId})`) and the return page's
|
|
164
|
+
confirmation (`checkout.confirmTopUp({actor, subjectId, topUpId})`, with
|
|
165
|
+
`topUpId` from the `paymentTopUp` query parameter, `TOP_UP_RETURN_PARAMETER`
|
|
166
|
+
from `@jskit-ai/payments-core/shared/topUps`). Map the webhook route to `checkout.webhook({rawBody, signature})`,
|
|
154
167
|
preserving the unmodified request Buffer. Enforce features using
|
|
155
168
|
`payments.requireFeature({...merchantScope, subjectId}, 'export')`; debit credits
|
|
156
169
|
using a stable business-operation reference. A successful checkout redirect is
|
|
@@ -218,7 +231,8 @@ application responsibilities; focused package tests use controlled fixtures.
|
|
|
218
231
|
## Customer-facing billing page
|
|
219
232
|
|
|
220
233
|
The optional `@jskit-ai/payments-web` package owns the reusable Vue/Vuetify
|
|
221
|
-
`PaymentAccount`
|
|
234
|
+
`PaymentAccount` and `PaymentTopUp` views, and `openPaymentPage(url)`, which
|
|
235
|
+
opens a Checkout URL in this tab, or in a new one when the app runs framed. Its README specifies the props, emitted actions and
|
|
222
236
|
existing JSKIT HTTP-hook composition. Node-only consumers do not install Vue.
|
|
223
237
|
`checkout.account({actor, subjectId})` authorizes action `account`, then returns
|
|
224
238
|
balance, features, subscriptions and a `hasCustomer` flag without provider customer
|