-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathclient.py
More file actions
1612 lines (1292 loc) · 56.7 KB
/
Copy pathclient.py
File metadata and controls
1612 lines (1292 loc) · 56.7 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
# This file was auto-generated by Fern from our API Definition.
import typing
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..requests.money import MoneyParams
from ..requests.phase import PhaseParams
from ..requests.phase_input import PhaseInputParams
from ..requests.search_subscriptions_query import SearchSubscriptionsQueryParams
from ..requests.subscription import SubscriptionParams
from ..requests.subscription_source import SubscriptionSourceParams
from ..types.bulk_swap_plan_response import BulkSwapPlanResponse
from ..types.cancel_subscription_response import CancelSubscriptionResponse
from ..types.change_billing_anchor_date_response import ChangeBillingAnchorDateResponse
from ..types.change_timing import ChangeTiming
from ..types.create_subscription_response import CreateSubscriptionResponse
from ..types.delete_subscription_action_response import DeleteSubscriptionActionResponse
from ..types.get_subscription_response import GetSubscriptionResponse
from ..types.list_subscription_events_response import ListSubscriptionEventsResponse
from ..types.pause_subscription_response import PauseSubscriptionResponse
from ..types.resume_subscription_response import ResumeSubscriptionResponse
from ..types.search_subscriptions_response import SearchSubscriptionsResponse
from ..types.subscription_event import SubscriptionEvent
from ..types.swap_plan_response import SwapPlanResponse
from ..types.update_subscription_response import UpdateSubscriptionResponse
from .raw_client import AsyncRawSubscriptionsClient, RawSubscriptionsClient
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class SubscriptionsClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawSubscriptionsClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> RawSubscriptionsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawSubscriptionsClient
"""
return self._raw_client
def create(
self,
*,
location_id: str,
customer_id: str,
idempotency_key: typing.Optional[str] = OMIT,
plan_variation_id: typing.Optional[str] = OMIT,
start_date: typing.Optional[str] = OMIT,
canceled_date: typing.Optional[str] = OMIT,
tax_percentage: typing.Optional[str] = OMIT,
price_override_money: typing.Optional[MoneyParams] = OMIT,
card_id: typing.Optional[str] = OMIT,
timezone: typing.Optional[str] = OMIT,
source: typing.Optional[SubscriptionSourceParams] = OMIT,
monthly_billing_anchor_date: typing.Optional[int] = OMIT,
phases: typing.Optional[typing.Sequence[PhaseParams]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateSubscriptionResponse:
"""
Enrolls a customer in a subscription.
If you provide a card on file in the request, Square charges the card for
the subscription. Otherwise, Square sends an invoice to the customer's email
address. The subscription starts immediately, unless the request includes
the optional `start_date`. Each individual subscription is associated with a particular location.
For more information, see [Create a subscription](https://developer.squareup.com/docs/subscriptions-api/manage-subscriptions#create-a-subscription).
Parameters
----------
location_id : str
The ID of the location the subscription is associated with.
customer_id : str
The ID of the [customer](entity:Customer) subscribing to the subscription plan variation.
idempotency_key : typing.Optional[str]
A unique string that identifies this `CreateSubscription` request.
If you do not provide a unique string (or provide an empty string as the value),
the endpoint treats each request as independent.
For more information, see [Idempotency keys](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency).
plan_variation_id : typing.Optional[str]
The ID of the [subscription plan variation](https://developer.squareup.com/docs/subscriptions-api/plans-and-variations#plan-variations) created using the Catalog API.
start_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date to start the subscription.
If it is unspecified, the subscription starts immediately.
canceled_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date when the newly created subscription is scheduled for cancellation.
This date overrides the cancellation date set in the plan variation configuration.
If the cancellation date is earlier than the end date of a subscription cycle, the subscription stops
at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle.
When the subscription plan of the newly created subscription has a fixed number of cycles and the `canceled_date`
occurs before the subscription plan completes, the specified `canceled_date` sets the date when the subscription
stops through the end of the last cycle.
tax_percentage : typing.Optional[str]
The tax to add when billing the subscription.
The percentage is expressed in decimal form, using a `'.'` as the decimal
separator and without a `'%'` sign. For example, a value of 7.5
corresponds to 7.5%.
price_override_money : typing.Optional[MoneyParams]
A custom price which overrides the cost of a subscription plan variation with `STATIC` pricing.
This field does not affect itemized subscriptions with `RELATIVE` pricing. Instead,
you should edit the Subscription's [order template](https://developer.squareup.com/docs/subscriptions-api/manage-subscriptions#phases-and-order-templates).
card_id : typing.Optional[str]
The ID of the [subscriber's](entity:Customer) [card](entity:Card) to charge.
If it is not specified, the subscriber receives an invoice via email with a link to pay for their subscription.
timezone : typing.Optional[str]
The timezone that is used in date calculations for the subscription. If unset, defaults to
the location timezone. If a timezone is not configured for the location, defaults to "America/New_York".
Format: the IANA Timezone Database identifier for the location timezone. For
a list of time zones, see [List of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
source : typing.Optional[SubscriptionSourceParams]
The origination details of the subscription.
monthly_billing_anchor_date : typing.Optional[int]
The day-of-the-month to change the billing date to.
phases : typing.Optional[typing.Sequence[PhaseParams]]
array of phases for this subscription
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CreateSubscriptionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.create(
idempotency_key="8193148c-9586-11e6-99f9-28cfe92138cf",
location_id="S8GWD5R9QB376",
plan_variation_id="6JHXF3B2CW3YKHDV4XEM674H",
customer_id="CHFGVKYY8RSV93M5KCYTG4PN0G",
start_date="2023-06-20",
card_id="ccof:qy5x8hHGYsgLrp4Q4GB",
timezone="America/Los_Angeles",
source={"name": "My Application"},
phases=[
{"ordinal": 0, "order_template_id": "U2NaowWxzXwpsZU697x7ZHOAnCNZY"}
],
)
"""
_response = self._raw_client.create(
location_id=location_id,
customer_id=customer_id,
idempotency_key=idempotency_key,
plan_variation_id=plan_variation_id,
start_date=start_date,
canceled_date=canceled_date,
tax_percentage=tax_percentage,
price_override_money=price_override_money,
card_id=card_id,
timezone=timezone,
source=source,
monthly_billing_anchor_date=monthly_billing_anchor_date,
phases=phases,
request_options=request_options,
)
return _response.data
def bulk_swap_plan(
self,
*,
new_plan_variation_id: str,
old_plan_variation_id: str,
location_id: str,
request_options: typing.Optional[RequestOptions] = None,
) -> BulkSwapPlanResponse:
"""
Schedules a plan variation change for all active subscriptions under a given plan
variation. For more information, see [Swap Subscription Plan Variations](https://developer.squareup.com/docs/subscriptions-api/swap-plan-variations).
Parameters
----------
new_plan_variation_id : str
The ID of the new subscription plan variation.
This field is required.
old_plan_variation_id : str
The ID of the plan variation whose subscriptions should be swapped. Active subscriptions
using this plan variation will be subscribed to the new plan variation on their next billing
day.
location_id : str
The ID of the location to associate with the swapped subscriptions.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
BulkSwapPlanResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.bulk_swap_plan(
new_plan_variation_id="FQ7CDXXWSLUJRPM3GFJSJGZ7",
old_plan_variation_id="6JHXF3B2CW3YKHDV4XEM674H",
location_id="S8GWD5R9QB376",
)
"""
_response = self._raw_client.bulk_swap_plan(
new_plan_variation_id=new_plan_variation_id,
old_plan_variation_id=old_plan_variation_id,
location_id=location_id,
request_options=request_options,
)
return _response.data
def search(
self,
*,
cursor: typing.Optional[str] = OMIT,
limit: typing.Optional[int] = OMIT,
query: typing.Optional[SearchSubscriptionsQueryParams] = OMIT,
include: typing.Optional[typing.Sequence[str]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SearchSubscriptionsResponse:
"""
Searches for subscriptions.
Results are ordered chronologically by subscription creation date. If
the request specifies more than one location ID,
the endpoint orders the result
by location ID, and then by creation date within each location. If no locations are given
in the query, all locations are searched.
You can also optionally specify `customer_ids` to search by customer.
If left unset, all customers
associated with the specified locations are returned.
If the request specifies customer IDs, the endpoint orders results
first by location, within location by customer ID, and within
customer by subscription creation date.
Parameters
----------
cursor : typing.Optional[str]
When the total number of resulting subscriptions exceeds the limit of a paged response,
specify the cursor returned from a preceding response here to fetch the next set of results.
If the cursor is unset, the response contains the last page of the results.
For more information, see [Pagination](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination).
limit : typing.Optional[int]
The upper limit on the number of subscriptions to return
in a paged response.
query : typing.Optional[SearchSubscriptionsQueryParams]
A subscription query consisting of specified filtering conditions.
If this `query` field is unspecified, the `SearchSubscriptions` call will return all subscriptions.
include : typing.Optional[typing.Sequence[str]]
An option to include related information in the response.
The supported values are:
- `actions`: to include scheduled actions on the targeted subscriptions.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SearchSubscriptionsResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.search(
query={
"filter": {
"customer_ids": ["CHFGVKYY8RSV93M5KCYTG4PN0G"],
"location_ids": ["S8GWD5R9QB376"],
"source_names": ["My App"],
}
},
)
"""
_response = self._raw_client.search(
cursor=cursor, limit=limit, query=query, include=include, request_options=request_options
)
return _response.data
def get(
self,
subscription_id: str,
*,
include: typing.Optional[str] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetSubscriptionResponse:
"""
Retrieves a specific subscription.
Parameters
----------
subscription_id : str
The ID of the subscription to retrieve.
include : typing.Optional[str]
A query parameter to specify related information to be included in the response.
The supported query parameter values are:
- `actions`: to include scheduled actions on the targeted subscription.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetSubscriptionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.get(
subscription_id="subscription_id",
include="include",
)
"""
_response = self._raw_client.get(subscription_id, include=include, request_options=request_options)
return _response.data
def update(
self,
subscription_id: str,
*,
subscription: typing.Optional[SubscriptionParams] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> UpdateSubscriptionResponse:
"""
Updates a subscription by modifying or clearing `subscription` field values.
To clear a field, set its value to `null`.
Parameters
----------
subscription_id : str
The ID of the subscription to update.
subscription : typing.Optional[SubscriptionParams]
The subscription object containing the current version, and fields to update.
Unset fields will be left at their current server values, and JSON `null` values will
be treated as a request to clear the relevant data.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
UpdateSubscriptionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.update(
subscription_id="subscription_id",
subscription={"card_id": "{NEW CARD ID}"},
)
"""
_response = self._raw_client.update(subscription_id, subscription=subscription, request_options=request_options)
return _response.data
def delete_action(
self, subscription_id: str, action_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> DeleteSubscriptionActionResponse:
"""
Deletes a scheduled action for a subscription.
Parameters
----------
subscription_id : str
The ID of the subscription the targeted action is to act upon.
action_id : str
The ID of the targeted action to be deleted.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
DeleteSubscriptionActionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.delete_action(
subscription_id="subscription_id",
action_id="action_id",
)
"""
_response = self._raw_client.delete_action(subscription_id, action_id, request_options=request_options)
return _response.data
def change_billing_anchor_date(
self,
subscription_id: str,
*,
monthly_billing_anchor_date: typing.Optional[int] = OMIT,
effective_date: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> ChangeBillingAnchorDateResponse:
"""
Changes the [billing anchor date](https://developer.squareup.com/docs/subscriptions-api/subscription-billing#billing-dates)
for a subscription.
Parameters
----------
subscription_id : str
The ID of the subscription to update the billing anchor date.
monthly_billing_anchor_date : typing.Optional[int]
The anchor day for the billing cycle.
effective_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date when the scheduled `BILLING_ANCHOR_CHANGE` action takes
place on the subscription.
When this date is unspecified or falls within the current billing cycle, the billing anchor date
is changed immediately.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ChangeBillingAnchorDateResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.change_billing_anchor_date(
subscription_id="subscription_id",
monthly_billing_anchor_date=1,
)
"""
_response = self._raw_client.change_billing_anchor_date(
subscription_id,
monthly_billing_anchor_date=monthly_billing_anchor_date,
effective_date=effective_date,
request_options=request_options,
)
return _response.data
def cancel(
self, subscription_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> CancelSubscriptionResponse:
"""
Schedules a `CANCEL` action to cancel an active subscription. This
sets the `canceled_date` field to the end of the active billing period. After this date,
the subscription status changes from ACTIVE to CANCELED.
Parameters
----------
subscription_id : str
The ID of the subscription to cancel.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CancelSubscriptionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.cancel(
subscription_id="subscription_id",
)
"""
_response = self._raw_client.cancel(subscription_id, request_options=request_options)
return _response.data
def list_events(
self,
subscription_id: str,
*,
cursor: typing.Optional[str] = None,
limit: typing.Optional[int] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> SyncPager[SubscriptionEvent, ListSubscriptionEventsResponse]:
"""
Lists all [events](https://developer.squareup.com/docs/subscriptions-api/actions-events) for a specific subscription.
Parameters
----------
subscription_id : str
The ID of the subscription to retrieve the events for.
cursor : typing.Optional[str]
When the total number of resulting subscription events exceeds the limit of a paged response,
specify the cursor returned from a preceding response here to fetch the next set of results.
If the cursor is unset, the response contains the last page of the results.
For more information, see [Pagination](https://developer.squareup.com/docs/build-basics/common-api-patterns/pagination).
limit : typing.Optional[int]
The upper limit on the number of subscription events to return
in a paged response.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SyncPager[SubscriptionEvent, ListSubscriptionEventsResponse]
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
response = client.subscriptions.list_events(
subscription_id="subscription_id",
cursor="cursor",
limit=1,
)
for item in response:
yield item
# alternatively, you can paginate page-by-page
for page in response.iter_pages():
yield page
"""
return self._raw_client.list_events(
subscription_id, cursor=cursor, limit=limit, request_options=request_options
)
def pause(
self,
subscription_id: str,
*,
pause_effective_date: typing.Optional[str] = OMIT,
pause_cycle_duration: typing.Optional[int] = OMIT,
resume_effective_date: typing.Optional[str] = OMIT,
resume_change_timing: typing.Optional[ChangeTiming] = OMIT,
pause_reason: typing.Optional[str] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> PauseSubscriptionResponse:
"""
Schedules a `PAUSE` action to pause an active subscription.
Parameters
----------
subscription_id : str
The ID of the subscription to pause.
pause_effective_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date when the scheduled `PAUSE` action takes place on the subscription.
When this date is unspecified or falls within the current billing cycle, the subscription is paused
on the starting date of the next billing cycle.
pause_cycle_duration : typing.Optional[int]
The number of billing cycles the subscription will be paused before it is reactivated.
When this is set, a `RESUME` action is also scheduled to take place on the subscription at
the end of the specified pause cycle duration. In this case, neither `resume_effective_date`
nor `resume_change_timing` may be specified.
resume_effective_date : typing.Optional[str]
The date when the subscription is reactivated by a scheduled `RESUME` action.
This date must be at least one billing cycle ahead of `pause_effective_date`.
resume_change_timing : typing.Optional[ChangeTiming]
The timing whether the subscription is reactivated immediately or at the end of the billing cycle, relative to
`resume_effective_date`.
See [ChangeTiming](#type-changetiming) for possible values
pause_reason : typing.Optional[str]
The user-provided reason to pause the subscription.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
PauseSubscriptionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.pause(
subscription_id="subscription_id",
)
"""
_response = self._raw_client.pause(
subscription_id,
pause_effective_date=pause_effective_date,
pause_cycle_duration=pause_cycle_duration,
resume_effective_date=resume_effective_date,
resume_change_timing=resume_change_timing,
pause_reason=pause_reason,
request_options=request_options,
)
return _response.data
def resume(
self,
subscription_id: str,
*,
resume_effective_date: typing.Optional[str] = OMIT,
resume_change_timing: typing.Optional[ChangeTiming] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> ResumeSubscriptionResponse:
"""
Schedules a `RESUME` action to resume a paused or a deactivated subscription.
Parameters
----------
subscription_id : str
The ID of the subscription to resume.
resume_effective_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date when the subscription reactivated.
resume_change_timing : typing.Optional[ChangeTiming]
The timing to resume a subscription, relative to the specified
`resume_effective_date` attribute value.
See [ChangeTiming](#type-changetiming) for possible values
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
ResumeSubscriptionResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.resume(
subscription_id="subscription_id",
)
"""
_response = self._raw_client.resume(
subscription_id,
resume_effective_date=resume_effective_date,
resume_change_timing=resume_change_timing,
request_options=request_options,
)
return _response.data
def swap_plan(
self,
subscription_id: str,
*,
new_plan_variation_id: typing.Optional[str] = OMIT,
phases: typing.Optional[typing.Sequence[PhaseInputParams]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> SwapPlanResponse:
"""
Schedules a `SWAP_PLAN` action to swap a subscription plan variation in an existing subscription.
For more information, see [Swap Subscription Plan Variations](https://developer.squareup.com/docs/subscriptions-api/swap-plan-variations).
Parameters
----------
subscription_id : str
The ID of the subscription to swap the subscription plan for.
new_plan_variation_id : typing.Optional[str]
The ID of the new subscription plan variation.
This field is required.
phases : typing.Optional[typing.Sequence[PhaseInputParams]]
A list of PhaseInputs, to pass phase-specific information used in the swap.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
SwapPlanResponse
Success
Examples
--------
from square import Square
client = Square(
token="YOUR_TOKEN",
)
client.subscriptions.swap_plan(
subscription_id="subscription_id",
new_plan_variation_id="FQ7CDXXWSLUJRPM3GFJSJGZ7",
phases=[
{"ordinal": 0, "order_template_id": "uhhnjH9osVv3shUADwaC0b3hNxQZY"}
],
)
"""
_response = self._raw_client.swap_plan(
subscription_id, new_plan_variation_id=new_plan_variation_id, phases=phases, request_options=request_options
)
return _response.data
class AsyncSubscriptionsClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawSubscriptionsClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> AsyncRawSubscriptionsClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawSubscriptionsClient
"""
return self._raw_client
async def create(
self,
*,
location_id: str,
customer_id: str,
idempotency_key: typing.Optional[str] = OMIT,
plan_variation_id: typing.Optional[str] = OMIT,
start_date: typing.Optional[str] = OMIT,
canceled_date: typing.Optional[str] = OMIT,
tax_percentage: typing.Optional[str] = OMIT,
price_override_money: typing.Optional[MoneyParams] = OMIT,
card_id: typing.Optional[str] = OMIT,
timezone: typing.Optional[str] = OMIT,
source: typing.Optional[SubscriptionSourceParams] = OMIT,
monthly_billing_anchor_date: typing.Optional[int] = OMIT,
phases: typing.Optional[typing.Sequence[PhaseParams]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> CreateSubscriptionResponse:
"""
Enrolls a customer in a subscription.
If you provide a card on file in the request, Square charges the card for
the subscription. Otherwise, Square sends an invoice to the customer's email
address. The subscription starts immediately, unless the request includes
the optional `start_date`. Each individual subscription is associated with a particular location.
For more information, see [Create a subscription](https://developer.squareup.com/docs/subscriptions-api/manage-subscriptions#create-a-subscription).
Parameters
----------
location_id : str
The ID of the location the subscription is associated with.
customer_id : str
The ID of the [customer](entity:Customer) subscribing to the subscription plan variation.
idempotency_key : typing.Optional[str]
A unique string that identifies this `CreateSubscription` request.
If you do not provide a unique string (or provide an empty string as the value),
the endpoint treats each request as independent.
For more information, see [Idempotency keys](https://developer.squareup.com/docs/build-basics/common-api-patterns/idempotency).
plan_variation_id : typing.Optional[str]
The ID of the [subscription plan variation](https://developer.squareup.com/docs/subscriptions-api/plans-and-variations#plan-variations) created using the Catalog API.
start_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date to start the subscription.
If it is unspecified, the subscription starts immediately.
canceled_date : typing.Optional[str]
The `YYYY-MM-DD`-formatted date when the newly created subscription is scheduled for cancellation.
This date overrides the cancellation date set in the plan variation configuration.
If the cancellation date is earlier than the end date of a subscription cycle, the subscription stops
at the canceled date and the subscriber is sent a prorated invoice at the beginning of the canceled cycle.
When the subscription plan of the newly created subscription has a fixed number of cycles and the `canceled_date`
occurs before the subscription plan completes, the specified `canceled_date` sets the date when the subscription
stops through the end of the last cycle.
tax_percentage : typing.Optional[str]
The tax to add when billing the subscription.
The percentage is expressed in decimal form, using a `'.'` as the decimal
separator and without a `'%'` sign. For example, a value of 7.5
corresponds to 7.5%.
price_override_money : typing.Optional[MoneyParams]
A custom price which overrides the cost of a subscription plan variation with `STATIC` pricing.
This field does not affect itemized subscriptions with `RELATIVE` pricing. Instead,
you should edit the Subscription's [order template](https://developer.squareup.com/docs/subscriptions-api/manage-subscriptions#phases-and-order-templates).
card_id : typing.Optional[str]
The ID of the [subscriber's](entity:Customer) [card](entity:Card) to charge.
If it is not specified, the subscriber receives an invoice via email with a link to pay for their subscription.
timezone : typing.Optional[str]
The timezone that is used in date calculations for the subscription. If unset, defaults to
the location timezone. If a timezone is not configured for the location, defaults to "America/New_York".
Format: the IANA Timezone Database identifier for the location timezone. For
a list of time zones, see [List of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
source : typing.Optional[SubscriptionSourceParams]
The origination details of the subscription.
monthly_billing_anchor_date : typing.Optional[int]
The day-of-the-month to change the billing date to.
phases : typing.Optional[typing.Sequence[PhaseParams]]
array of phases for this subscription
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
CreateSubscriptionResponse
Success
Examples
--------
import asyncio
from square import AsyncSquare
client = AsyncSquare(
token="YOUR_TOKEN",
)
async def main() -> None:
await client.subscriptions.create(
idempotency_key="8193148c-9586-11e6-99f9-28cfe92138cf",
location_id="S8GWD5R9QB376",
plan_variation_id="6JHXF3B2CW3YKHDV4XEM674H",
customer_id="CHFGVKYY8RSV93M5KCYTG4PN0G",
start_date="2023-06-20",
card_id="ccof:qy5x8hHGYsgLrp4Q4GB",
timezone="America/Los_Angeles",
source={"name": "My Application"},
phases=[
{"ordinal": 0, "order_template_id": "U2NaowWxzXwpsZU697x7ZHOAnCNZY"}
],
)
asyncio.run(main())
"""
_response = await self._raw_client.create(
location_id=location_id,
customer_id=customer_id,
idempotency_key=idempotency_key,
plan_variation_id=plan_variation_id,
start_date=start_date,
canceled_date=canceled_date,
tax_percentage=tax_percentage,
price_override_money=price_override_money,
card_id=card_id,
timezone=timezone,
source=source,
monthly_billing_anchor_date=monthly_billing_anchor_date,
phases=phases,
request_options=request_options,
)
return _response.data
async def bulk_swap_plan(
self,
*,
new_plan_variation_id: str,
old_plan_variation_id: str,
location_id: str,
request_options: typing.Optional[RequestOptions] = None,
) -> BulkSwapPlanResponse:
"""
Schedules a plan variation change for all active subscriptions under a given plan
variation. For more information, see [Swap Subscription Plan Variations](https://developer.squareup.com/docs/subscriptions-api/swap-plan-variations).
Parameters
----------
new_plan_variation_id : str
The ID of the new subscription plan variation.
This field is required.
old_plan_variation_id : str
The ID of the plan variation whose subscriptions should be swapped. Active subscriptions
using this plan variation will be subscribed to the new plan variation on their next billing
day.
location_id : str
The ID of the location to associate with the swapped subscriptions.
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
BulkSwapPlanResponse
Success
Examples
--------
import asyncio
from square import AsyncSquare
client = AsyncSquare(
token="YOUR_TOKEN",
)
async def main() -> None:
await client.subscriptions.bulk_swap_plan(
new_plan_variation_id="FQ7CDXXWSLUJRPM3GFJSJGZ7",
old_plan_variation_id="6JHXF3B2CW3YKHDV4XEM674H",
location_id="S8GWD5R9QB376",
)
asyncio.run(main())
"""
_response = await self._raw_client.bulk_swap_plan(
new_plan_variation_id=new_plan_variation_id,
old_plan_variation_id=old_plan_variation_id,
location_id=location_id,
request_options=request_options,
)
return _response.data
async def search(