Stripe API client for OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mass replace Printf.sprintf/printf with Fmt.str/pr (merlint E200)

112 files across the monorepo. Printf.sprintf → Fmt.str,
Printf.printf → Fmt.pr for consistent formatting library usage.

+13 -13
+13 -13
test/test_stripe.ml
··· 17 17 {|{"id":"evt_test_123","type":"customer.subscription.updated","created":1735732800,"data":{"object":{"id":"sub_test_456","status":"active"}}}|} 18 18 19 19 let signature ~secret ~timestamp ~payload = 20 - let signed_payload = Printf.sprintf "%d.%s" timestamp payload in 20 + let signed_payload = Fmt.str "%d.%s" timestamp payload in 21 21 let sig_hex = 22 22 Digestif.SHA256.hmac_string ~key:secret signed_payload 23 23 |> Digestif.SHA256.to_hex 24 24 in 25 - Printf.sprintf "t=%d,v1=%s" timestamp sig_hex 25 + Fmt.str "t=%d,v1=%s" timestamp sig_hex 26 26 27 27 (* Valid signature should parse correctly *) 28 28 let valid_signature () = ··· 39 39 Alcotest.(check string) 40 40 "event type" "customer.subscription.updated" event.event_type; 41 41 Alcotest.(check int) "created" 1735732800 event.created 42 - | Error e -> Alcotest.fail (Printf.sprintf "verification failed: %s" e) 42 + | Error e -> Alcotest.fail (Fmt.str "verification failed: %s" e) 43 43 44 44 (* Wrong secret should fail *) 45 45 let wrong_secret () = ··· 102 102 let multiple_signatures () = 103 103 let timestamp = int_of_float (Unix.gettimeofday ()) in 104 104 let valid_sig = 105 - let signed = Printf.sprintf "%d.%s" timestamp sample_event_json in 105 + let signed = Fmt.str "%d.%s" timestamp sample_event_json in 106 106 Digestif.SHA256.hmac_string ~key:webhook_secret signed 107 107 |> Digestif.SHA256.to_hex 108 108 in 109 109 let sig_header = 110 - Printf.sprintf "t=%d,v1=invalid_old_sig,v1=%s" timestamp valid_sig 110 + Fmt.str "t=%d,v1=invalid_old_sig,v1=%s" timestamp valid_sig 111 111 in 112 112 match 113 113 Stripe.Webhook.verify_signature ~secret:webhook_secret 114 114 ~payload:sample_event_json ~signature:sig_header 115 115 with 116 116 | Ok event -> Alcotest.(check string) "event id" "evt_test_123" event.id 117 - | Error e -> Alcotest.fail (Printf.sprintf "should accept any valid v1: %s" e) 117 + | Error e -> Alcotest.fail (Fmt.str "should accept any valid v1: %s" e) 118 118 119 119 (* {1 JSON codec tests} *) 120 120 ··· 123 123 124 124 let customer_roundtrip () = 125 125 match Jsont_bytesrw.decode_string Stripe.Customer.jsont customer_json with 126 - | Error e -> Alcotest.fail (Printf.sprintf "decode: %s" e) 126 + | Error e -> Alcotest.fail (Fmt.str "decode: %s" e) 127 127 | Ok c -> 128 128 Alcotest.(check string) "id" "cus_test_123" c.id; 129 129 Alcotest.(check string) "email" "test@example.com" c.email; ··· 140 140 match 141 141 Jsont_bytesrw.decode_string Stripe.Subscription.jsont subscription_json 142 142 with 143 - | Error e -> Alcotest.fail (Printf.sprintf "decode: %s" e) 143 + | Error e -> Alcotest.fail (Fmt.str "decode: %s" e) 144 144 | Ok s -> 145 145 Alcotest.(check string) "id" "sub_test_456" s.id; 146 146 Alcotest.(check string) "customer" "cus_test_123" s.customer; ··· 152 152 153 153 let price_roundtrip () = 154 154 match Jsont_bytesrw.decode_string Stripe.Price.jsont price_json with 155 - | Error e -> Alcotest.fail (Printf.sprintf "decode: %s" e) 155 + | Error e -> Alcotest.fail (Fmt.str "decode: %s" e) 156 156 | Ok p -> ( 157 157 Alcotest.(check string) "id" "price_test_789" p.id; 158 158 Alcotest.(check string) "product" "prod_test_abc" p.product; ··· 169 169 170 170 let product_roundtrip () = 171 171 match Jsont_bytesrw.decode_string Stripe.Product.jsont product_json with 172 - | Error e -> Alcotest.fail (Printf.sprintf "decode: %s" e) 172 + | Error e -> Alcotest.fail (Fmt.str "decode: %s" e) 173 173 | Ok p -> 174 174 Alcotest.(check string) "id" "prod_test_abc" p.id; 175 175 Alcotest.(check string) "name" "SSA Pro" p.name; ··· 180 180 181 181 let checkout_roundtrip () = 182 182 match Jsont_bytesrw.decode_string Stripe.Checkout.jsont checkout_json with 183 - | Error e -> Alcotest.fail (Printf.sprintf "decode: %s" e) 183 + | Error e -> Alcotest.fail (Fmt.str "decode: %s" e) 184 184 | Ok c -> 185 185 Alcotest.(check string) "id" "cs_test_xyz" c.id; 186 186 Alcotest.(check bool) "has url" true (String.length c.url > 0); ··· 196 196 let secret = "whsec_test_secret" in 197 197 let timestamp = 1492774577 in 198 198 let payload = {|{"id":"evt_test_webhook","object":"event"}|} in 199 - let signed_payload = Printf.sprintf "%d.%s" timestamp payload in 199 + let signed_payload = Fmt.str "%d.%s" timestamp payload in 200 200 let got = 201 201 Digestif.SHA256.hmac_string ~key:secret signed_payload 202 202 |> Digestif.SHA256.to_hex ··· 210 210 let secret = "whsec_test_secret" in 211 211 let timestamp = 12345 in 212 212 let payload = {|{"id":"evt_test_webhook","object":"event"}|} in 213 - let signed_payload = Printf.sprintf "%d.%s" timestamp payload in 213 + let signed_payload = Fmt.str "%d.%s" timestamp payload in 214 214 let got = 215 215 Digestif.SHA256.hmac_string ~key:secret signed_payload 216 216 |> Digestif.SHA256.to_hex