@@ -13,24 +13,32 @@ private typedef Impl = Remote<stripe.api.Stripe>;
1313
1414@:forward
1515abstract Stripe (Impl ) {
16- public inline function new (apiKey , client ) {
17- this = new Impl (new AuthedClient (apiKey , client ), new RemoteEndpoint (new Host (' api.stripe.com' , 443 )));
16+ public inline function new (apiKey , client : Client , ? idempotencyKey ) {
17+ client = new AuthedClient (apiKey , client );
18+ if (idempotencyKey != null ) client = new IdempotentClient (idempotencyKey , client );
19+ this = new Impl (client , new RemoteEndpoint (new Host (' api.stripe.com' , 443 )));
1820 }
1921}
2022
21- class AuthedClient implements ClientObject {
22- var apiKey : String ;
23+ class AuthedClient extends AppendHeaderClient {
24+ public function new (apiKey , client )
25+ super (AUTHORIZATION , 'Bearer $apiKey ', client );
26+ }
27+
28+ class IdempotentClient extends AppendHeaderClient {
29+ public function new (key , client )
30+ super ('Idempotency -Key ', key , client );
31+ }
32+
33+ class AppendHeaderClient implements ClientObject {
34+ var field : HeaderField ;
2335 var client : Client ;
24- public function new (apiKey , client ) {
25- this .apiKey = apiKey ;
36+
37+ public function new (name , value , client ) {
38+ this .field = new HeaderField (name , value );
2639 this .client = client ;
2740 }
2841
29- public function request (req : OutgoingRequest ): Promise <IncomingResponse > {
30- trace (haxe. Json .stringify (apiKey ));
31- return client .request (new OutgoingRequest (
32- req .header .concat ([new HeaderField (AUTHORIZATION , ' Bearer $apiKey ' )]),
33- req .body
34- ));
35- }
42+ public function request (req : OutgoingRequest ): Promise <IncomingResponse >
43+ return client .request (new OutgoingRequest (req .header .concat ([field ]), req .body ));
3644}
0 commit comments