CanFinalize.php
3 years ago
HasCharge.php
3 years ago
HasCheckout.php
3 years ago
HasCoupon.php
3 years ago
HasCustomer.php
3 years ago
HasDiscount.php
3 years ago
HasImageSizes.php
2 years ago
HasOrder.php
3 years ago
HasPaymentIntent.php
3 years ago
HasPaymentMethod.php
3 years ago
HasPrice.php
3 years ago
HasProcessorType.php
3 years ago
HasProduct.php
3 years ago
HasPurchase.php
3 years ago
HasPurchases.php
3 years ago
HasRefund.php
3 years ago
HasShippingAddress.php
3 years ago
HasSubscription.php
3 years ago
HasSubscriptions.php
3 years ago
SyncsCustomer.php
3 years ago
CanFinalize.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Models\Traits; |
| 4 | |
| 5 | /** |
| 6 | * If the model has an attached customer. |
| 7 | */ |
| 8 | trait CanFinalize { |
| 9 | /** |
| 10 | * Finalize the session for checkout. |
| 11 | * |
| 12 | * @return $this|\WP_Error |
| 13 | */ |
| 14 | protected function finalize() { |
| 15 | if ( $this->fireModelEvent( 'finalizing' ) === false ) { |
| 16 | return false; |
| 17 | } |
| 18 | |
| 19 | if ( empty( $this->attributes['id'] ) ) { |
| 20 | return new \WP_Error( 'not_saved', 'Please create the checkout session.' ); |
| 21 | } |
| 22 | |
| 23 | $finalized = \SureCart::request( |
| 24 | $this->endpoint . '/' . $this->attributes['id'] . '/finalize/', |
| 25 | [ |
| 26 | 'method' => 'PATCH', |
| 27 | 'query' => $this->query, |
| 28 | 'body' => [ |
| 29 | $this->object_name => $this->getAttributes(), |
| 30 | ], |
| 31 | ] |
| 32 | ); |
| 33 | |
| 34 | if ( is_wp_error( $finalized ) ) { |
| 35 | return $finalized; |
| 36 | } |
| 37 | |
| 38 | $this->resetAttributes(); |
| 39 | |
| 40 | $this->fill( $finalized ); |
| 41 | |
| 42 | $this->fireModelEvent( 'finalized' ); |
| 43 | |
| 44 | return $this; |
| 45 | } |
| 46 | |
| 47 | } |
| 48 |