PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / square / donations / class-charitable-square-donation-log.php

class-charitable-square-donation-log.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/square/donations/class-charitable-square-donation-log.php

131 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class responsible for adding logs & meta about Square donations.
4 *
5 * @package Charitable Square/Classes/Charitable_Square_Donation_Log
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.7
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Square_Donation_Log' ) ) :
18
19 /**
20 * Charitable_Square_Donation_Log
21 *
22 * @since 1.4.0
23 */
24 class Charitable_Square_Donation_Log {
25
26 /**
27 * The donation object.
28 *
29 * @since 1.4.0
30 *
31 * @var Charitable_Donation
32 */
33 protected $donation;
34
35 /**
36 * Create class object.
37 *
38 * @since 1.4.0
39 *
40 * @param Charitable_Donation $donation The donation object.
41 */
42 public function __construct( Charitable_Donation $donation ) {
43 $this->donation = $donation;
44 }
45
46 /**
47 * Log the payment update details.
48 *
49 * @since 1.8.7
50 *
51 * @param array $payment_data The payment data.
52 * @param array $charge The charge data.
53 * @param boolean $add_to_log Whether to add the payment update details to the donation log.
54 * @return boolean Whether the payment update details were logged.
55 */
56 public function log_payment_update_details( $payment_data = array(), $charge = array(), $add_to_log = true ) {
57 $logged = false;
58
59 if ( empty( $payment_data ) || empty( $charge ) ) {
60 return false;
61 }
62
63 if ( charitable_is_debug( 'square' ) ) {
64 // phpcs:disable
65 error_log( 'charitable_square_donation_log - log_payment_update_details - the payment data is ' . print_r( $payment_data, true ) );
66 // phpcs:enable
67 }
68
69 // $payment_id = ! empty( $payment_data['payment_id'] ) ? $payment_data['payment_id'] : 'Not Available';
70 $payment_id = ! empty( $payment_data['payment_id'] ) ? $payment_data['payment_id'] : 'Not Available';
71
72 if ( $payment_id ) {
73 $this->donation->set_gateway_payment_id( $payment_id );
74 }
75
76 if ( $add_to_log ) {
77 $this->donation->update_donation_log(
78 sprintf(
79 /* translators: %s: link to Square payment intent details */
80 __( 'Square Webhook: Payment status updated to %1$s and card details status is %2$s. Payment ID: %3$s', 'charitable' ),
81 ucfirst( $payment_data['payment_status'] ),
82 ucfirst( $payment_data['card_details_status'] ),
83 $payment_data['payment_id']
84 )
85 );
86
87 if ( charitable_is_debug( 'square' ) ) {
88 // phpcs:disable
89 error_log( 'charitable_square_donation_log - log_payment_update_details - the donation id is ' . $this->donation->ID );
90 error_log( 'charitable_square_donation_log - log_payment_update_details - the charge is ' . print_r( $charge, true ) );
91 // phpcs:enable
92 }
93 }
94
95 $logged = true;
96
97 return $logged;
98 }
99
100 /**
101 * Log a custom message.
102 *
103 * @since 1.8.7
104 *
105 * @param string $message The message to log.
106 */
107 public function log_custom_message( $message ) {
108 $this->donation->update_donation_log( $message );
109 }
110
111 /**
112 * Return the link for a particular resource.
113 *
114 * @since 1.8.7
115 *
116 * @param string $type The type of resource.
117 * @param string $object_id The id of the object.
118 * @return string
119 */
120 public function get_resource_link( $type, $object_id ) {
121
122 $base_url = $this->donation->get_test_mode() ? 'https://squareupsandbox.com/dashboard/' : 'https://squareup.com/t/cmtp_performance/pr_developers/d_partnerships/p_Charitable/?route=dashboard/';
123
124 $slug = $type . 's/'; // Pluralize the resource.
125
126 return $base_url . $slug . $object_id;
127 }
128 }
129
130 endif;
131