You need to sign in or sign up before continuing.
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace Civi\Api4\Action\PaymentMJW;
use CRM_Mjwshared_ExtensionUtil as E;
use Civi\Api4\CustomField;
/**
* This API Action creates a payment. It is based on API3 Payment.create and API3 MJWPayment.create
*
*/
class Create extends \Civi\Api4\Generic\AbstractCreateAction {
public static function getCreateFields() {
// Basically a copy of _civicrm_api3_payment_create_spec;
$fields = [
[
'name' => 'contribution_id',
'required' => TRUE,
'description' => E::ts('Contribution ID'),
'data_type' => 'Integer',
'fk_entity' => 'Contribution',
'input_type' => 'EntityRef',
],
[
'name' => 'total_amount',
'required' => TRUE,
'description' => E::ts('Total Payment Amount'),
'data_type' => 'Float',
],
[
'name' => 'fee_amount',
'description' => E::ts('Fee Amount'),
'data_type' => 'Float',
],
[
'name' => 'payment_processor_id',
'data_type' => 'Integer',
'description' => E::ts('Payment Processor for this payment'),
'fk_entity' => 'PaymentProcessor',
'input_type' => 'EntityRef',
],
[
'name' => 'trxn_date',
'description' => E::ts('Payment Date'),
'data_type' => 'Datetime',
'default' => 'now',
'required' => TRUE,
],
[
'name' => 'is_send_contribution_notification',
'description' => E::ts('Send out notifications based on contribution status change?'),
'data_type' => 'Boolean',
'default' => TRUE,
],
[
'name' => 'payment_instrument_id',
'data_type' => 'Integer',
'description' => E::ts('Payment Method (FK to payment_instrument option group values)'),
'pseudoconstant' => [
'optionGroupName' => 'payment_instrument',
'optionEditPath' => 'civicrm/admin/options/payment_instrument',
],
],
[
'name' => 'card_type_id',
'data_type' => 'Integer',
'description' => E::ts('Card Type ID (FK to accept_creditcard option group values)'),
'pseudoconstant' => [
'optionGroupName' => 'accept_creditcard',
'optionEditPath' => 'civicrm/admin/options/accept_creditcard',
],
],
[
'name' => 'trxn_result_code',
'data_type' => 'String',
'description' => E::ts('Transaction Result Code'),
],
[
'name' => 'trxn_id',
'data_type' => 'String',
'description' => E::ts('Transaction ID supplied by external processor. This may not be unique.'),
],
[
'name' => 'order_reference',
'data_type' => 'String',
'description' => E::ts('Payment Processor external order reference'),
],
[
'name' => 'check_number',
'data_type' => 'String',
'description' => E::ts('Check Number'),
],
[
'name' => 'pan_truncation',
'type' => 'String',
'description' => E::ts('PAN Truncation (Last 4 digits of credit card)'),
],
];
$customFields = CustomField::get(FALSE)
->addSelect('custom_group_id:name', 'name', 'label', 'data_type')
->addWhere('custom_group_id.extends', '=', 'FinancialTrxn')
->execute();
foreach ($customFields as $customField) {
$customField['name'] = $customField['custom_group_id:name'] . '.' . $customField['name'];
unset($customField['id'], $customField['custom_group_id:name']);
$customField['description'] = $customField['label'];
$fields[] = $customField;
}
return $fields;
}
public function fields(): array {
return self::getCreateFields();
}
/**
*
* Note that the result class is that of the annotation below, not the h
* in the method (which must match the parent class)
*
* @var \Civi\Api4\Generic\Result $result
*/
public function _run(\Civi\Api4\Generic\Result $result) {
$trxn = \CRM_Financial_BAO_Payment::create($this->values);
$customFields = CustomField::get(FALSE)
->addSelect('id', 'custom_group_id:name', 'name', 'label', 'data_type')
->addWhere('custom_group_id.extends', '=', 'FinancialTrxn')
->execute();
foreach ($customFields as $customField) {
$key = $customField['custom_group_id:name'] . '.' . $customField['name'];
if (isset($this->values[$key])) {
$customParams['custom_' . $customField['id']] = $this->values[$key];
}
}
if (!empty($customParams)) {
$customParams['entity_id'] = $trxn->id;
civicrm_api3('CustomValue', 'create', $customParams);
}
$result->exchangeArray($trxn);
return $result;
}
}