activities_helper.php
1 year ago
agent_helper.php
1 year ago
auth_helper.php
1 year ago
blocks_helper.php
1 year ago
booking_helper.php
1 year ago
bricks_helper.php
1 year ago
bundles_helper.php
1 year ago
calendar_helper.php
1 year ago
carts_helper.php
1 year ago
connector_helper.php
1 year ago
csv_helper.php
1 year ago
customer_helper.php
1 year ago
database_helper.php
1 year ago
debug_helper.php
1 year ago
defaults_helper.php
1 year ago
elementor_helper.php
1 year ago
email_helper.php
1 year ago
encrypt_helper.php
1 year ago
events_helper.php
1 year ago
form_helper.php
1 year ago
icalendar_helper.php
1 year ago
image_helper.php
1 year ago
invoices_helper.php
1 year ago
license_helper.php
1 year ago
location_helper.php
1 year ago
marketing_systems_helper.php
1 year ago
meeting_systems_helper.php
1 year ago
menu_helper.php
1 year ago
meta_helper.php
1 year ago
migrations_helper.php
1 year ago
money_helper.php
1 year ago
notifications_helper.php
1 year ago
order_intent_helper.php
1 year ago
orders_helper.php
1 year ago
pages_helper.php
1 year ago
params_helper.php
1 year ago
payments_helper.php
1 year ago
price_breakdown_helper.php
1 year ago
process_jobs_helper.php
1 year ago
processes_helper.php
1 year ago
replacer_helper.php
1 year ago
resource_helper.php
1 year ago
roles_helper.php
1 year ago
router_helper.php
1 year ago
service_helper.php
1 year ago
sessions_helper.php
1 year ago
settings_helper.php
1 year ago
shortcodes_helper.php
1 year ago
sms_helper.php
1 year ago
steps_helper.php
1 year ago
stripe_connect_helper.php
1 year ago
styles_helper.php
1 year ago
support_topics_helper.php
1 year ago
time_helper.php
1 year ago
timeline_helper.php
1 year ago
transaction_helper.php
1 year ago
transaction_intent_helper.php
1 year ago
util_helper.php
1 year ago
version_specific_updates_helper.php
1 year ago
whatsapp_helper.php
1 year ago
work_periods_helper.php
1 year ago
wp_datetime.php
1 year ago
wp_user_helper.php
1 year ago
transaction_intent_helper.php
84 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2024 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | class OsTransactionIntentHelper { |
| 7 | |
| 8 | |
| 9 | public static function generate_continue_intent_url( $transaction_intent_key ) { |
| 10 | return OsRouterHelper::build_admin_post_link( [ |
| 11 | 'orders', |
| 12 | 'continue_transaction_intent' |
| 13 | ], [ 'transaction_intent_key' => $transaction_intent_key ] ); |
| 14 | } |
| 15 | |
| 16 | |
| 17 | public static function get_order_id_from_intent_key( $intent_key ) { |
| 18 | if ( empty( $intent_key ) ) { |
| 19 | return false; |
| 20 | } |
| 21 | $transaction_intent = new OsTransactionIntentModel(); |
| 22 | $transaction_intent = $transaction_intent->where( [ 'intent_key' => $intent_key ] )->set_limit( 1 )->get_results_as_models(); |
| 23 | |
| 24 | if ( $transaction_intent && $transaction_intent->order_id ) { |
| 25 | return $transaction_intent->order_id; |
| 26 | } else { |
| 27 | return null; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public static function get_transaction_intent_by_intent_key( string $intent_key ): OsTransactionIntentModel { |
| 32 | $transaction_intent = new OsTransactionIntentModel(); |
| 33 | if ( empty( $intent_key ) ) { |
| 34 | return $transaction_intent; |
| 35 | } |
| 36 | $transaction_intent = $transaction_intent->where( [ 'intent_key' => $intent_key ] )->set_limit( 1 )->get_results_as_models(); |
| 37 | if ( ! empty( $transaction_intent ) ) { |
| 38 | return $transaction_intent; |
| 39 | } else { |
| 40 | return new OsTransactionIntentModel(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public static function is_converted( $transaction_intent_id ) { |
| 45 | $transaction_intent = new OsTransactionIntentModel( $transaction_intent_id ); |
| 46 | if ( ! empty( $transaction_intent->transaction_id ) ) { |
| 47 | return $transaction_intent->transaction_id; |
| 48 | } else { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | public static function create_or_update_transaction_intent( OsInvoiceModel $invoice, array $payment_params ): OsTransactionIntentModel { |
| 54 | $transaction_intent = new OsTransactionIntentModel(); |
| 55 | |
| 56 | $transaction_intent = $transaction_intent->where( [ 'status' => LATEPOINT_TRANSACTION_INTENT_STATUS_NEW, 'invoice_id' => $invoice->id ] )->set_limit( 1 )->get_results_as_models(); |
| 57 | if ( empty( $transaction_intent ) ) { |
| 58 | $transaction_intent = new OsTransactionIntentModel(); |
| 59 | } |
| 60 | |
| 61 | $transaction_intent->charge_amount = $invoice->charge_amount; |
| 62 | $transaction_intent->invoice_id = $invoice->id; |
| 63 | $order = $invoice->get_order(); |
| 64 | $transaction_intent->order_id = $order->id; |
| 65 | $transaction_intent->customer_id = $order->customer_id; |
| 66 | |
| 67 | $transaction_intent->set_payment_data_value( 'time', LATEPOINT_PAYMENT_TIME_NOW, false ); |
| 68 | $transaction_intent->set_payment_data_value( 'portion', sanitize_text_field( $payment_params['payment_portion'] ), false ); |
| 69 | $transaction_intent->set_payment_data_value( 'method', sanitize_text_field( $payment_params['payment_method'] ), false ); |
| 70 | $transaction_intent->set_payment_data_value( 'processor', sanitize_text_field( $payment_params['payment_processor'] ), false ); |
| 71 | |
| 72 | |
| 73 | $transaction_intent->calculate_specs_charge_amount(); |
| 74 | $transaction_intent->generate_intent_key(); |
| 75 | |
| 76 | |
| 77 | if ( ! $transaction_intent->save() ) { |
| 78 | throw new Exception( __( 'Unable to save transaction intent', 'latepoint' ) ); |
| 79 | } |
| 80 | |
| 81 | return $transaction_intent; |
| 82 | } |
| 83 | |
| 84 | } |