PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.4.1
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.4.1
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 / PaymentMethod.php
PaymentMethod.php
101 lines 1.9 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\HasPaymentInstrument;
6 use SureCart\Models\Traits\HasPaymentIntent;
7
8 /**
9 * Payment method model.
10 */
11 class PaymentMethod extends Model {
12 use HasCustomer;
13 use HasPaymentIntent;
14 use HasPaymentInstrument;
15
16 /**
17 * Rest API endpoint
18 *
19 * @var string
20 */
21 protected $endpoint = 'payment_methods';
22
23 /**
24 * Object name
25 *
26 * @var string
27 */
28 protected $object_name = 'payment_method';
29
30 /**
31 * Detach from a customer.
32 *
33 * @return $this|\WP_Error
34 */
35 protected function detach() {
36 if ( $this->fireModelEvent( 'detaching' ) === false ) {
37 return false;
38 }
39
40 if ( empty( $this->attributes['id'] ) ) {
41 return new \WP_Error( 'not_saved', 'Please create the payment method.' );
42 }
43
44 $detached = \SureCart::request(
45 $this->endpoint . '/' . $this->attributes['id'] . '/detach/',
46 [
47 'method' => 'PATCH',
48 'query' => $this->query,
49 'body' => [
50 $this->object_name => $this->getAttributes(),
51 ],
52 ]
53 );
54
55 if ( is_wp_error( $detached ) ) {
56 return $detached;
57 }
58
59 $this->resetAttributes();
60
61 $this->fill( $detached );
62
63 $this->fireModelEvent( 'detached' );
64
65 return $this;
66 }
67
68 /**
69 * Get the translated payment method name.
70 *
71 * @return string
72 */
73 public function getPaymentMethodNameAttribute(): string {
74 return $this->payment_instrument->display_name ?? '';
75 }
76
77 /**
78 * Get the processor name.
79 *
80 * @return string
81 */
82 public function getProcessorNameAttribute(): string {
83 switch ( $this->processor_type ) {
84 case 'stripe':
85 return __( 'Stripe', 'surecart' );
86 case 'paypal':
87 return __( 'PayPal', 'surecart' );
88 case 'razorpay':
89 return __( 'Razorpay', 'surecart' );
90 case 'paystack':
91 return __( 'Paystack', 'surecart' );
92 case 'mollie':
93 return __( 'Mollie', 'surecart' );
94 case 'square':
95 return __( 'Square', 'surecart' );
96 default:
97 return __( 'Processor', 'surecart' );
98 }
99 }
100 }
101