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 / Models / Period.php
Period.php
97 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Models;
4
5 use SureCart\Models\Traits\HasCheckout;
6 use SureCart\Models\Traits\HasPrice;
7 use SureCart\Models\Traits\HasSubscription;
8 use SureCart\Support\TimeDate;
9
10 /**
11 * Period model
12 */
13 class Period extends Model {
14 use HasSubscription, HasCheckout, HasPrice;
15
16 /**
17 * Rest API endpoint
18 *
19 * @var string
20 */
21 protected $endpoint = 'periods';
22
23 /**
24 * Object name
25 *
26 * @var string
27 */
28 protected $object_name = 'period';
29
30 /**
31 * Restore a subscription
32 *
33 * @param string $id Model id.
34 * @return $this|\WP_Error
35 */
36 protected function retryPayment( $id = null ) {
37 if ( $id ) {
38 $this->setAttribute( 'id', $id );
39 }
40
41 if ( $this->fireModelEvent( 'retrying_payment' ) === false ) {
42 return false;
43 }
44
45 if ( empty( $this->attributes['id'] ) ) {
46 return new \WP_Error( 'not_saved', 'Please create the period.' );
47 }
48
49 $restored = \SureCart::request(
50 $this->endpoint . '/' . $this->attributes['id'] . '/retry_payment/',
51 [
52 'method' => 'PATCH',
53 'query' => $this->query,
54 ]
55 );
56
57 if ( is_wp_error( $restored ) ) {
58 return $restored;
59 }
60
61 $this->resetAttributes();
62
63 $this->fill( $restored );
64
65 $this->fireModelEvent( 'payment_retry_success' );
66
67 return $this;
68 }
69
70 /**
71 * Get the start at date.
72 *
73 * @return string
74 */
75 public function getStartAtDateAttribute() {
76 return ! empty( $this->start_at ) ? TimeDate::formatDate( $this->start_at ) : '';
77 }
78
79 /**
80 * Get the end at date.
81 *
82 * @return string
83 */
84 public function getEndAtDateAttribute() {
85 return ! empty( $this->end_at ) ? TimeDate::formatDate( $this->end_at ) : '';
86 }
87
88 /**
89 * Get the next payment retry at date time.
90 *
91 * @return string
92 */
93 public function getNextPaymentRetryAtDateTimeAttribute() {
94 return ! empty( $this->next_payment_retry_at ) ? TimeDate::formatDateAndTime( $this->next_payment_retry_at ) : '';
95 }
96 }
97