Blocks
2 months ago
Concerns
6 months ago
Traits
2 weeks ago
Wordpress
1 year ago
AbandonedCheckout.php
1 year ago
AbandonedCheckoutProtocol.php
3 years ago
Account.php
10 months ago
AccountPortalSession.php
3 years ago
Activation.php
1 year ago
Affiliation.php
1 year ago
AffiliationProduct.php
1 year ago
AffiliationProtocol.php
2 years ago
AffiliationRequest.php
1 year ago
ApiToken.php
6 months ago
AutoFee.php
5 months ago
AutoFeeProtocol.php
5 months ago
BalanceTransaction.php
1 year ago
Batch.php
3 days ago
Brand.php
4 months ago
BulkAction.php
2 years ago
Bump.php
1 year ago
BuyLink.php
2 years ago
CancellationAct.php
1 year ago
CancellationReason.php
3 years ago
Charge.php
9 months ago
Checkout.php
2 months ago
Click.php
1 year ago
Collection.php
3 months ago
CommissionStructure.php
2 years ago
Component.php
4 months ago
Coupon.php
2 months ago
Customer.php
2 weeks ago
CustomerLink.php
3 years ago
CustomerNotificationProtocol.php
3 years ago
CustomerPortalProtocol.php
1 year ago
DatabaseModel.php
2 months ago
Discount.php
1 year ago
DisplayCurrency.php
1 year ago
Dispute.php
9 months ago
Download.php
3 years ago
Event.php
3 years ago
Export.php
2 years ago
ExternalApiModel.php
3 months ago
Fee.php
1 year ago
Form.php
3 years ago
Fulfillment.php
1 year ago
FulfillmentItem.php
1 year ago
GalleryItem.php
9 months ago
GalleryItemAttachment.php
5 months ago
GalleryItemImageAttachment.php
3 months ago
GalleryItemMedia.php
1 year ago
GalleryItemProductMedia.php
1 month ago
GalleryItemVideoAttachment.php
3 months ago
Import.php
6 months ago
ImportRow.php
2 months ago
IncomingWebhook.php
1 year ago
Integration.php
2 years ago
IntegrationCatalog.php
3 days ago
Invoice.php
1 year ago
License.php
1 year ago
LineItem.php
9 months ago
ManualPaymentMethod.php
1 year ago
Media.php
1 month ago
Model.php
3 days ago
ModelInterface.php
3 years ago
Order.php
2 weeks ago
OrderProtocol.php
3 years ago
ParcelTemplate.php
3 months ago
PaymentFailure.php
1 year ago
PaymentInstrument.php
2 months ago
PaymentIntent.php
1 year ago
PaymentMethod.php
1 year ago
Payout.php
1 year ago
PayoutGroup.php
2 years ago
Period.php
1 year ago
PlatformFee.php
1 year ago
PortalSession.php
3 years ago
Price.php
6 months ago
Processor.php
1 year ago
Product.php
3 days ago
ProductCollection.php
1 year ago
ProductCollectionImport.php
6 months ago
ProductGroup.php
1 year ago
ProductImport.php
6 months ago
ProductMedia.php
4 months ago
Promotion.php
1 year ago
ProvisionalAccount.php
2 months ago
Purchase.php
2 years ago
Referral.php
1 year ago
ReferralItem.php
2 years ago
Refund.php
1 year ago
RefundItem.php
1 year ago
RegisteredWebhook.php
2 months ago
ReturnItem.php
2 years ago
ReturnReason.php
2 years ago
ReturnRequest.php
1 year ago
Review.php
4 months ago
ReviewProtocol.php
4 months ago
RuleSchema.php
5 months ago
ServiceFee.php
1 year ago
ShippingChoice.php
1 year ago
ShippingMethod.php
3 years ago
ShippingProfile.php
3 years ago
ShippingProtocol.php
3 years ago
ShippingRate.php
3 years ago
ShippingZone.php
3 years ago
Statistic.php
3 years ago
Subscription.php
2 weeks ago
SubscriptionProtocol.php
3 years ago
Swap.php
1 year ago
TaxOverride.php
2 years ago
TaxProtocol.php
3 years ago
TaxRegistration.php
1 year ago
TaxZone.php
3 years ago
Upload.php
3 years ago
Upsell.php
1 year ago
UpsellFunnel.php
1 year ago
User.php
1 month ago
Variant.php
3 days ago
VariantOption.php
2 years ago
VariantOptionValue.php
1 year ago
VariantValue.php
2 years ago
VerificationCode.php
3 years ago
Webhook.php
1 year ago
WebhookRegistration.php
2 years ago
PaymentMethod.php
101 lines
| 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 |