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