PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.2.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.2.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Controllers / Rest / InvoicesController.php
InvoicesController.php
103 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Controllers\Rest;
4
5 use SureCart\Models\Invoice;
6
7 /**
8 * Handle Invoice requests through the REST API
9 */
10 class InvoicesController extends RestController {
11 /**
12 * Always fetch with these subcollections.
13 *
14 * @var array
15 */
16 protected $with = [
17 'checkout',
18 'checkout.line_items',
19 'line_item.price',
20 'line_item.fees',
21 'line_item.variant',
22 'price.product',
23 'product.featured_product_media',
24 'product_media.media',
25 'checkout.customer',
26 'customer.shipping_address',
27 'customer.billing_address',
28 'checkout.payment_intent',
29 'checkout.discount',
30 'discount.promotion',
31 'discount.coupon',
32 'checkout.shipping_address',
33 'checkout.billing_address',
34 'checkout.shipping_choices',
35 'shipping_choices.shipping_method',
36 'payment_method.card',
37 'checkout.tax_identifier',
38 'checkout.order',
39 'checkout.payment_method',
40 'checkout.manual_payment_method',
41 ];
42
43 /**
44 * Class to make the requests.
45 *
46 * @var string
47 */
48 protected $class = Invoice::class;
49
50 /**
51 * Make draft invoice.
52 *
53 * @param \WP_REST_Request $request Request object.
54 *
55 * @return Invoice|\WP_Error
56 */
57 public function makeDraft( \WP_REST_Request $request ) {
58 $class = new $this->class( $request->get_json_params() );
59 $class->id = $request['id'];
60 $model = $this->middleware( $class, $request );
61
62 if ( is_wp_error( $model ) ) {
63 return $model;
64 }
65
66 return $model->where( $request->get_query_params() )->makeDraft( $request['id'] );
67 }
68
69 /**
70 * Open an invoice.
71 *
72 * @param \WP_REST_Request $request Request object.
73 *
74 * @return Invoice|\WP_Error
75 */
76 public function open( \WP_REST_Request $request ) {
77 $class = new $this->class( $request->get_json_params() );
78 $class->id = $request['id'];
79 $model = $this->middleware( $class, $request );
80
81 if ( is_wp_error( $model ) ) {
82 return $model;
83 }
84
85 return $model->where( $request->get_query_params() )->open( $request['id'] );
86 }
87
88 /**
89 * Resend invoice notification.
90 *
91 * @param \WP_REST_Request $request Rest Request.
92 *
93 * @return \WP_REST_Response
94 */
95 public function resend_notification( \WP_REST_Request $request ) {
96 $model = $this->middleware( new $this->class(), $request );
97 if ( is_wp_error( $model ) ) {
98 return $model;
99 }
100 return $model->where( $request->get_query_params() )->resend_notification( $request['id'] );
101 }
102 }
103