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 / PaymentIntent.php
PaymentIntent.php
80 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace SureCart\Models;
3
4 use SureCart\Models\Traits\HasCustomer;
5 use SureCart\Models\Traits\HasPlatformFee;
6 use SureCart\Support\Currency;
7
8 /**
9 * Payment intent model.
10 */
11 class PaymentIntent extends Model {
12 use HasCustomer;
13 use HasPlatformFee;
14
15 /**
16 * Rest API endpoint
17 *
18 * @var string
19 */
20 protected $endpoint = 'payment_intents';
21
22 /**
23 * Object name
24 *
25 * @var string
26 */
27 protected $object_name = 'payment_intent';
28
29 /**
30 * Capture the payment intent
31 *
32 * @return $this|\WP_Error
33 */
34 protected function capture() {
35 if ( $this->fireModelEvent( 'capturing' ) === false ) {
36 return false;
37 }
38
39 if ( empty( $this->attributes['id'] ) ) {
40 return new \WP_Error( 'not_saved', 'Please create a payment intent.' );
41 }
42
43 $captured = \SureCart::request(
44 $this->endpoint . '/' . $this->attributes['id'] . '/capture/',
45 [
46 'method' => 'PATCH',
47 'query' => $this->query,
48 'body' => [
49 $this->object_name => $this->getAttributes(),
50 ],
51 ]
52 );
53
54 if ( is_wp_error( $captured ) ) {
55 return $captured;
56 }
57
58 $this->resetAttributes();
59
60 $this->fill( $captured );
61
62 $this->fireModelEvent( 'captured' );
63
64 return $this;
65 }
66
67 /**
68 * Get the display amount for total fees
69 *
70 * @return array
71 */
72 public function getTotalFeesDisplayAmountAttribute() {
73 $platform_fee_amount = $this->platform_fee->amount ?? 0;
74 $service_fee_amount = $this->service_fee->amount ?? 0;
75 $total_fees = $platform_fee_amount + $service_fee_amount;
76
77 return Currency::format( $total_fees, $this->currency );
78 }
79 }
80