PluginProbe
Stripe Payment Forms by WP Simple Pay – Accept Credit Card Payments + Subscriptions with Stripe / trunk
Stripe Payment Forms by WP Simple Pay – Accept Credit Card Payments + Subscriptions with Stripe vtrunk
4.17.3 trunk 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 4.10.0 4.11.1 4.12.2 4.14.1 4.14.2 4.14.3 4.15.0 4.16.0 All 59 releases
stripe / src / Transaction / TransactionRepository.php

TransactionRepository.php in Stripe Payment Forms by WP Simple Pay – Accept Credit Card Payments + Subscriptions with Stripe trunk, at src/Transaction/TransactionRepository.php

86 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Transactions: Transaction repository
4 *
5 * These records, while they may be used to generate simple reports, are not
6 * meant to be used for financial reporting or other purposes as it is possible
7 * the data is not fully updated if a webhook event is not received.
8 *
9 * The primary advantage of this table is that it can be used to store _some_
10 * sort of reference to transactions that were created with an application fee.
11 *
12 * When querying for items with an application fee the `object` column should
13 * be evaluated to find a relevant Subscription if the `subscription_id` column
14 * is null (this can occur with Stripe Checkout and no webhooks).
15 *
16 * @package SimplePay
17 * @subpackage Core
18 * @copyright Copyright (c) 2022, Sandhills Development, LLC
19 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
20 * @since 4.4.6
21 */
22
23 namespace SimplePay\Core\Transaction;
24
25 use SimplePay\Core\Repository\BerlinDbRepository;
26 use SimplePay\Core\Utils;
27
28 /**
29 * TransactionRepository class.
30 *
31 * @since 4.4.6
32 */
33 class TransactionRepository extends BerlinDbRepository {
34
35 /**
36 * TransactionRepository.
37 *
38 * @since 4.4.6
39 */
40 public function __construct() {
41 parent::__construct( Transaction::class, Database\Query::class );
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function add( $data ) {
48 // Prefix object_id to match column name.
49 if ( array_key_exists( 'object_id', $data ) ) {
50 $data['_object_id'] = $data['object_id'];
51 unset( $data['object_id'] );
52 }
53
54 // Always log IP address.
55 $data['ip_address'] = Utils\get_current_ip_address();
56
57 return parent::add( $data );
58 }
59
60 /**
61 * {@inheritdoc}
62 */
63 public function update( $id, $data ) {
64 // Prefix object_id to match column name.
65 if ( array_key_exists( 'object_id', $data ) ) {
66 $data['_object_id'] = $data['object_id'];
67 unset( $data['object_id'] );
68 }
69
70 return parent::update( $id, $data );
71 }
72
73 /**
74 * Retrieves a transaction by the Stripe object ID.
75 *
76 * @since 4.4.6
77 *
78 * @param string $object_id Stripe object ID.
79 * @return \SimplePay\Core\Model\ModelInterface|null
80 */
81 public function get_by_object_id( $object_id ) {
82 return $this->get_by( '_object_id', $object_id );
83 }
84
85 }
86