ima-claude 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +463 -0
  3. package/dist/cli.js +1064 -0
  4. package/package.json +49 -0
  5. package/platforms/claude/adapter.ts +115 -0
  6. package/platforms/junie/adapter.ts +254 -0
  7. package/platforms/junie/agents-template.md +113 -0
  8. package/platforms/junie/hook-translations.md +84 -0
  9. package/platforms/shared/detector.ts +27 -0
  10. package/platforms/shared/installer.ts +202 -0
  11. package/platforms/shared/types.ts +78 -0
  12. package/plugins/ima-claude/.claude-plugin/plugin.json +25 -0
  13. package/plugins/ima-claude/agents/explorer.md +30 -0
  14. package/plugins/ima-claude/agents/implementer.md +30 -0
  15. package/plugins/ima-claude/agents/memory.md +42 -0
  16. package/plugins/ima-claude/agents/reviewer.md +53 -0
  17. package/plugins/ima-claude/agents/tester.md +33 -0
  18. package/plugins/ima-claude/agents/wp-developer.md +46 -0
  19. package/plugins/ima-claude/hooks/README.md +145 -0
  20. package/plugins/ima-claude/hooks/atlassian_prereqs.py +112 -0
  21. package/plugins/ima-claude/hooks/block_sed_edits.py +59 -0
  22. package/plugins/ima-claude/hooks/bootstrap.sh +90 -0
  23. package/plugins/ima-claude/hooks/bootstrap_utility_check.py +94 -0
  24. package/plugins/ima-claude/hooks/composer_autoload_check.py +70 -0
  25. package/plugins/ima-claude/hooks/docs_organization.py +104 -0
  26. package/plugins/ima-claude/hooks/enforce_rg_over_grep.py +56 -0
  27. package/plugins/ima-claude/hooks/fp_utility_check.py +90 -0
  28. package/plugins/ima-claude/hooks/hook_logger.py +69 -0
  29. package/plugins/ima-claude/hooks/hooks.json +239 -0
  30. package/plugins/ima-claude/hooks/jira_issue_fetch.py +79 -0
  31. package/plugins/ima-claude/hooks/jquery_in_wordpress.py +92 -0
  32. package/plugins/ima-claude/hooks/memory_bootstrap.py +79 -0
  33. package/plugins/ima-claude/hooks/memory_store_reminder.py +75 -0
  34. package/plugins/ima-claude/hooks/prompt_coach.py +125 -0
  35. package/plugins/ima-claude/hooks/prompt_coach_digest.md +48 -0
  36. package/plugins/ima-claude/hooks/prompt_coach_system.md +30 -0
  37. package/plugins/ima-claude/hooks/sequential_thinking_check.py +81 -0
  38. package/plugins/ima-claude/hooks/serena_over_grep.py +96 -0
  39. package/plugins/ima-claude/hooks/serena_over_read.py +66 -0
  40. package/plugins/ima-claude/hooks/serena_project_check.py +133 -0
  41. package/plugins/ima-claude/hooks/sql_injection_check.py +73 -0
  42. package/plugins/ima-claude/hooks/task_master_after_plan.py +31 -0
  43. package/plugins/ima-claude/hooks/task_master_before_impl.py +93 -0
  44. package/plugins/ima-claude/hooks/tavily_extract_advanced.py +48 -0
  45. package/plugins/ima-claude/hooks/vestige_before_external.py +86 -0
  46. package/plugins/ima-claude/hooks/webfetch_to_tavily.py +42 -0
  47. package/plugins/ima-claude/hooks/websearch_to_tavily.py +41 -0
  48. package/plugins/ima-claude/hooks/wp_security_check.py +150 -0
  49. package/plugins/ima-claude/personalities/README.md +45 -0
  50. package/plugins/ima-claude/personalities/enable-40k.md +69 -0
  51. package/plugins/ima-claude/personalities/enable-templars.md +69 -0
  52. package/plugins/ima-claude/skills/.research-summary.md +340 -0
  53. package/plugins/ima-claude/skills/architect/SKILL.md +304 -0
  54. package/plugins/ima-claude/skills/compound-bridge/SKILL.md +200 -0
  55. package/plugins/ima-claude/skills/discourse/SKILL.md +440 -0
  56. package/plugins/ima-claude/skills/discourse-admin/SKILL.md +192 -0
  57. package/plugins/ima-claude/skills/discourse-admin/references/api-endpoints.md +441 -0
  58. package/plugins/ima-claude/skills/discourse-admin/references/gotchas.md +107 -0
  59. package/plugins/ima-claude/skills/discourse-admin/references/staging-defaults.md +98 -0
  60. package/plugins/ima-claude/skills/discourse-admin/scripts/discourse-admin.py +319 -0
  61. package/plugins/ima-claude/skills/docs-organize/SKILL.md +254 -0
  62. package/plugins/ima-claude/skills/docs-organize/templates/active-README.md +50 -0
  63. package/plugins/ima-claude/skills/docs-organize/templates/archive-README.md +57 -0
  64. package/plugins/ima-claude/skills/docs-organize/templates/docs-README.md +43 -0
  65. package/plugins/ima-claude/skills/docs-organize/templates/phase-archive-README.md +83 -0
  66. package/plugins/ima-claude/skills/docs-organize/templates/section-README.md +48 -0
  67. package/plugins/ima-claude/skills/docs-organize/templates/transient-README.md +79 -0
  68. package/plugins/ima-claude/skills/docs-organize/templates/transient-gitignore +9 -0
  69. package/plugins/ima-claude/skills/ember-discourse/SKILL.md +496 -0
  70. package/plugins/ima-claude/skills/functional-programmer/SKILL.md +258 -0
  71. package/plugins/ima-claude/skills/ima-bootstrap/SKILL.md +278 -0
  72. package/plugins/ima-claude/skills/ima-bootstrap/references/bootstrap-patterns.md +356 -0
  73. package/plugins/ima-claude/skills/ima-bootstrap/references/ima-brand.md +273 -0
  74. package/plugins/ima-claude/skills/ima-bootstrap/references/theme-integration.md +212 -0
  75. package/plugins/ima-claude/skills/ima-brand/SKILL.md +108 -0
  76. package/plugins/ima-claude/skills/ima-brand/references/brand-identity.md +140 -0
  77. package/plugins/ima-claude/skills/ima-brand/references/digital-standards.md +180 -0
  78. package/plugins/ima-claude/skills/ima-brand/references/visual-system.md +173 -0
  79. package/plugins/ima-claude/skills/ima-forms-expert/SKILL.md +175 -0
  80. package/plugins/ima-claude/skills/ima-forms-expert/references/container-components.md +154 -0
  81. package/plugins/ima-claude/skills/ima-forms-expert/references/examples.md +328 -0
  82. package/plugins/ima-claude/skills/ima-forms-expert/references/field-components.md +298 -0
  83. package/plugins/ima-claude/skills/ima-forms-expert/references/form-factory.md +193 -0
  84. package/plugins/ima-claude/skills/ima-forms-expert/references/quick-reference.md +153 -0
  85. package/plugins/ima-claude/skills/ima-forms-expert/references/validation-engine.md +336 -0
  86. package/plugins/ima-claude/skills/jira-checkpoint/SKILL.md +178 -0
  87. package/plugins/ima-claude/skills/jquery/SKILL.md +413 -0
  88. package/plugins/ima-claude/skills/js-fp/SKILL.md +463 -0
  89. package/plugins/ima-claude/skills/js-fp/core-principles.md +487 -0
  90. package/plugins/ima-claude/skills/js-fp/examples/pure-functions.js +260 -0
  91. package/plugins/ima-claude/skills/js-fp/examples/tests/pure-functions.test.js +262 -0
  92. package/plugins/ima-claude/skills/js-fp/references/anti-patterns.md +120 -0
  93. package/plugins/ima-claude/skills/js-fp/references/performance-patterns.md +116 -0
  94. package/plugins/ima-claude/skills/js-fp/references/testing-patterns.md +134 -0
  95. package/plugins/ima-claude/skills/js-fp-api/SKILL.md +280 -0
  96. package/plugins/ima-claude/skills/js-fp-api/examples/crud-endpoint.js +258 -0
  97. package/plugins/ima-claude/skills/js-fp-api/references/middleware-patterns.md +134 -0
  98. package/plugins/ima-claude/skills/js-fp-api/references/security-sql.md +110 -0
  99. package/plugins/ima-claude/skills/js-fp-api/references/validation-patterns.md +165 -0
  100. package/plugins/ima-claude/skills/js-fp-react/SKILL.md +447 -0
  101. package/plugins/ima-claude/skills/js-fp-react/examples/ProductCard.tsx +65 -0
  102. package/plugins/ima-claude/skills/js-fp-react/references/hooks-advanced.md +136 -0
  103. package/plugins/ima-claude/skills/js-fp-react/references/performance-patterns.md +175 -0
  104. package/plugins/ima-claude/skills/js-fp-vue/SKILL.md +322 -0
  105. package/plugins/ima-claude/skills/js-fp-vue/references/complete-examples.md +397 -0
  106. package/plugins/ima-claude/skills/js-fp-vue/references/composables-advanced.md +282 -0
  107. package/plugins/ima-claude/skills/js-fp-vue/references/reactivity-patterns.md +348 -0
  108. package/plugins/ima-claude/skills/js-fp-vue/references/testing.md +314 -0
  109. package/plugins/ima-claude/skills/js-fp-wordpress/SKILL.md +301 -0
  110. package/plugins/ima-claude/skills/js-fp-wordpress/references/ajax-patterns.md +192 -0
  111. package/plugins/ima-claude/skills/js-fp-wordpress/references/event-patterns.md +136 -0
  112. package/plugins/ima-claude/skills/js-fp-wordpress/references/wp-integration.md +248 -0
  113. package/plugins/ima-claude/skills/livecanvas/SKILL.md +209 -0
  114. package/plugins/ima-claude/skills/livecanvas/references/livecanvas-features.md +311 -0
  115. package/plugins/ima-claude/skills/livecanvas/references/loops-and-logic.md +730 -0
  116. package/plugins/ima-claude/skills/livecanvas/references/picostrap.md +227 -0
  117. package/plugins/ima-claude/skills/mcp-atlassian/SKILL.md +339 -0
  118. package/plugins/ima-claude/skills/mcp-context7/SKILL.md +109 -0
  119. package/plugins/ima-claude/skills/mcp-memory/SKILL.md +182 -0
  120. package/plugins/ima-claude/skills/mcp-qdrant/SKILL.md +233 -0
  121. package/plugins/ima-claude/skills/mcp-sequential/SKILL.md +149 -0
  122. package/plugins/ima-claude/skills/mcp-serena/SKILL.md +174 -0
  123. package/plugins/ima-claude/skills/mcp-tavily/SKILL.md +118 -0
  124. package/plugins/ima-claude/skills/mcp-vestige/SKILL.md +259 -0
  125. package/plugins/ima-claude/skills/php-authnet/SKILL.md +275 -0
  126. package/plugins/ima-claude/skills/php-authnet/references/api-reference.md +624 -0
  127. package/plugins/ima-claude/skills/php-authnet/references/sandbox-testing.md +424 -0
  128. package/plugins/ima-claude/skills/php-fp/SKILL.md +333 -0
  129. package/plugins/ima-claude/skills/php-fp/examples/pure-functions.php +403 -0
  130. package/plugins/ima-claude/skills/php-fp/examples/tests/PureFunctionsTest.php +515 -0
  131. package/plugins/ima-claude/skills/php-fp/references/core-principles.md +277 -0
  132. package/plugins/ima-claude/skills/php-fp/references/testing-patterns.md +374 -0
  133. package/plugins/ima-claude/skills/php-fp-wordpress/SKILL.md +216 -0
  134. package/plugins/ima-claude/skills/php-fp-wordpress/references/fp-patterns.md +275 -0
  135. package/plugins/ima-claude/skills/php-fp-wordpress/references/plugin-architecture.md +295 -0
  136. package/plugins/ima-claude/skills/php-fp-wordpress/references/security-examples.md +203 -0
  137. package/plugins/ima-claude/skills/php-fp-wordpress/references/testing-strategy.md +259 -0
  138. package/plugins/ima-claude/skills/phpunit-wp/SKILL.md +716 -0
  139. package/plugins/ima-claude/skills/playwright/SKILL.md +434 -0
  140. package/plugins/ima-claude/skills/playwright/references/accessibility-testing.md +153 -0
  141. package/plugins/ima-claude/skills/playwright/references/ci-cd.md +268 -0
  142. package/plugins/ima-claude/skills/playwright/references/network-mocking.md +270 -0
  143. package/plugins/ima-claude/skills/playwright/references/visual-regression.md +215 -0
  144. package/plugins/ima-claude/skills/py-fp/SKILL.md +663 -0
  145. package/plugins/ima-claude/skills/py-fp/examples/pure-functions.py +185 -0
  146. package/plugins/ima-claude/skills/py-fp/examples/tests/test_pure_functions.py +244 -0
  147. package/plugins/ima-claude/skills/py-fp/references/core-principles.md +381 -0
  148. package/plugins/ima-claude/skills/py-fp/references/testing-patterns.md +283 -0
  149. package/plugins/ima-claude/skills/quasar-fp/SKILL.md +327 -0
  150. package/plugins/ima-claude/skills/quasar-fp/metadata.json +85 -0
  151. package/plugins/ima-claude/skills/quasar-fp/references/component-patterns.md +257 -0
  152. package/plugins/ima-claude/skills/quasar-fp/references/theme-integration.md +233 -0
  153. package/plugins/ima-claude/skills/quasar-fp/references/utility-classes.md +237 -0
  154. package/plugins/ima-claude/skills/quickstart/SKILL.md +129 -0
  155. package/plugins/ima-claude/skills/rails/SKILL.md +359 -0
  156. package/plugins/ima-claude/skills/resume-session/SKILL.md +68 -0
  157. package/plugins/ima-claude/skills/rg/SKILL.md +205 -0
  158. package/plugins/ima-claude/skills/ruby-fp/SKILL.md +336 -0
  159. package/plugins/ima-claude/skills/save-session/SKILL.md +81 -0
  160. package/plugins/ima-claude/skills/scorecard/SKILL.md +96 -0
  161. package/plugins/ima-claude/skills/skill-analyzer/SKILL.md +127 -0
  162. package/plugins/ima-claude/skills/skill-analyzer/references/advanced-checklist.md +44 -0
  163. package/plugins/ima-claude/skills/skill-analyzer/references/core-checklist.md +60 -0
  164. package/plugins/ima-claude/skills/skill-analyzer/scripts/analyze_skill.py +418 -0
  165. package/plugins/ima-claude/skills/skill-creator/LICENSE.txt +202 -0
  166. package/plugins/ima-claude/skills/skill-creator/SKILL.md +343 -0
  167. package/plugins/ima-claude/skills/skill-creator/references/output-patterns.md +82 -0
  168. package/plugins/ima-claude/skills/skill-creator/references/workflows.md +28 -0
  169. package/plugins/ima-claude/skills/skill-creator/scripts/init_skill.py +303 -0
  170. package/plugins/ima-claude/skills/skill-creator/scripts/package_skill.py +110 -0
  171. package/plugins/ima-claude/skills/skill-creator/scripts/quick_validate.py +103 -0
  172. package/plugins/ima-claude/skills/task-master/SKILL.md +51 -0
  173. package/plugins/ima-claude/skills/task-planner/SKILL.md +228 -0
  174. package/plugins/ima-claude/skills/task-runner/SKILL.md +192 -0
  175. package/plugins/ima-claude/skills/unit-testing/SKILL.md +198 -0
  176. package/plugins/ima-claude/skills/unit-testing/references/mock-patterns.md +181 -0
  177. package/plugins/ima-claude/skills/unit-testing/references/tdd-workflow.md +177 -0
  178. package/plugins/ima-claude/skills/unit-testing/references/test-strategy.md +126 -0
  179. package/plugins/ima-claude/skills/wp-local/SKILL.md +246 -0
  180. package/plugins/ima-claude/skills/wp-local/references/configuration.md +198 -0
  181. package/plugins/ima-claude/skills/wp-local/references/wp-cli-reference.md +406 -0
  182. package/plugins/ima-claude/skills/wp-local/scripts/wp-local.sh +61 -0
@@ -0,0 +1,275 @@
1
+ ---
2
+ name: "php-authnet"
3
+ description: "Authorize.Net PHP SDK patterns for payment processing, CIM profiles, ARB subscriptions, Accept.js integration, and webhooks. Use when working with authorizenet/authorizenet Composer package, building payment forms, processing transactions, managing customer profiles, recurring billing, refunds, voids, or webhook handlers in PHP. Complements php-fp and php-fp-wordpress skills."
4
+ ---
5
+
6
+ # Authorize.Net PHP SDK
7
+
8
+ Patterns and reference for the `authorizenet/authorizenet` PHP SDK (^2.0). PHP-only — no JavaScript, Python, Ruby, or Node patterns.
9
+
10
+ **Companion skills**: `php-fp` (core FP patterns), `php-fp-wordpress` (WordPress integration)
11
+
12
+ ## Architecture: Three-Layer FP Pattern
13
+
14
+ Authorize.Net integration follows a strict three-layer separation:
15
+
16
+ ```
17
+ [Pure Builders] → [SDK Adapter (Impure)] → [Pure Parsers]
18
+ plain arrays SDK objects + I/O result arrays
19
+ ```
20
+
21
+ ### Layer 1: Pure Request Builders
22
+
23
+ Normalize input into plain arrays. No SDK imports, no `date()`, no side effects.
24
+
25
+ ```php
26
+ <?php declare(strict_types=1);
27
+
28
+ function build_charge_request(array $payment_data): array {
29
+ return [
30
+ 'amount' => $payment_data['amount'],
31
+ 'payment_token' => $payment_data['payment_token'],
32
+ 'billing' => !empty($payment_data['billing']) ? $payment_data['billing'] : null,
33
+ 'description' => $payment_data['description'] ?? null,
34
+ ];
35
+ }
36
+ ```
37
+
38
+ ### Layer 2: SDK Adapter (Impure)
39
+
40
+ All `use net\authorize\api\...` imports confined here. Builds SDK objects, executes requests, normalizes responses to plain arrays. Never throws — catches exceptions and returns error arrays.
41
+
42
+ ```php
43
+ <?php declare(strict_types=1);
44
+
45
+ use net\authorize\api\contract\v1 as AnetAPI;
46
+ use net\authorize\api\controller as AnetController;
47
+
48
+ function sdk_charge_customer(array $payment_data, array $credentials): array {
49
+ $null_response = [
50
+ 'result_code' => null, 'transaction_id' => null,
51
+ 'error_text' => null, 'error_code' => null,
52
+ 'has_transaction_messages' => false,
53
+ ];
54
+
55
+ try {
56
+ $merchant_auth = new AnetAPI\MerchantAuthenticationType();
57
+ $merchant_auth->setName($credentials['api_login_id']);
58
+ $merchant_auth->setTransactionKey($credentials['transaction_key']);
59
+
60
+ // ... build SDK objects from plain array ...
61
+
62
+ $controller = new AnetController\CreateTransactionController($request);
63
+ $response = $controller->executeWithApiResponse($credentials['api_url']);
64
+
65
+ if ($response === null) return $null_response;
66
+
67
+ return [
68
+ 'result_code' => $response->getMessages()->getResultCode(),
69
+ 'transaction_id' => $response->getTransactionResponse()?->getTransId(),
70
+ // ... normalize all fields to plain values ...
71
+ ];
72
+ } catch (\Exception $e) {
73
+ return array_merge($null_response, [
74
+ 'result_code' => 'Error',
75
+ 'error_text' => sprintf('%s: %s', get_class($e), $e->getMessage()),
76
+ ]);
77
+ }
78
+ }
79
+ ```
80
+
81
+ ### Layer 3: Pure Response Parsers
82
+
83
+ Interpret normalized arrays into standard `['success' => bool, ...]` results. No SDK dependencies.
84
+
85
+ ```php
86
+ <?php declare(strict_types=1);
87
+
88
+ function parse_charge_response(array $response): array {
89
+ if ($response['result_code'] === 'Ok' && $response['has_transaction_messages']) {
90
+ return ['success' => true, 'transaction_id' => $response['transaction_id']];
91
+ }
92
+ if ($response['result_code'] === null) {
93
+ return ['success' => false, 'error' => 'No response from payment gateway'];
94
+ }
95
+ return ['success' => false, 'error' => $response['error_text'] ?? 'Unknown error'];
96
+ }
97
+ ```
98
+
99
+ ### SDK Orchestrator Pattern
100
+
101
+ Thin glue connecting adapter to parser — no business logic:
102
+
103
+ ```php
104
+ function charge_customer_via_sdk(array $payment_data, array $credentials): array {
105
+ $normalized = sdk_charge_customer($payment_data, $credentials);
106
+ return parse_charge_response($normalized);
107
+ }
108
+ ```
109
+
110
+ ## SDK Namespace Reference
111
+
112
+ ```php
113
+ use net\authorize\api\contract\v1 as AnetAPI; // Data types (request/response objects)
114
+ use net\authorize\api\controller as AnetController; // Controllers (execute requests)
115
+ use net\authorize\api\constants\ANetEnvironment; // SANDBOX / PRODUCTION URLs
116
+ ```
117
+
118
+ ## Authentication
119
+
120
+ ```php
121
+ $merchant_auth = new AnetAPI\MerchantAuthenticationType();
122
+ $merchant_auth->setName($credentials['api_login_id']);
123
+ $merchant_auth->setTransactionKey($credentials['transaction_key']);
124
+ ```
125
+
126
+ **Credential storage**: Use `wp-config.php` constants first, options table as fallback.
127
+
128
+ ```php
129
+ // Constants-first pattern
130
+ $api_login = defined('IMA_PAYMENTS_API_LOGIN_ID')
131
+ ? IMA_PAYMENTS_API_LOGIN_ID
132
+ : get_option('ima_payments_api_login_id', '');
133
+ ```
134
+
135
+ **Environment switching**:
136
+
137
+ ```php
138
+ // Sandbox
139
+ $controller->executeWithApiResponse(ANetEnvironment::SANDBOX);
140
+ // Production
141
+ $controller->executeWithApiResponse(ANetEnvironment::PRODUCTION);
142
+ ```
143
+
144
+ ## Transaction Types
145
+
146
+ | Type | `transactionType` value | Use case |
147
+ |------|------------------------|----------|
148
+ | Auth & Capture | `authCaptureTransaction` | One-step charge (most common) |
149
+ | Auth Only | `authOnlyTransaction` | Reserve funds, capture later |
150
+ | Capture Prior Auth | `priorAuthCaptureTransaction` | Capture a prior auth |
151
+ | Refund | `refundTransaction` | Refund settled transaction |
152
+ | Void | `voidTransaction` | Cancel unsettled transaction |
153
+
154
+ ## Accept.js Integration (PCI Compliance)
155
+
156
+ Accept.js tokenizes card data client-side. The server never sees raw card numbers — only opaque payment nonces (valid 15 minutes).
157
+
158
+ **Server-side token consumption**:
159
+
160
+ ```php
161
+ $opaque_data = new AnetAPI\OpaqueDataType();
162
+ $opaque_data->setDataDescriptor('COMMON.ACCEPT.INAPP.PAYMENT');
163
+ $opaque_data->setDataValue($payment_nonce);
164
+
165
+ $payment_type = new AnetAPI\PaymentType();
166
+ $payment_type->setOpaqueData($opaque_data);
167
+ ```
168
+
169
+ **Data descriptor** is always `'COMMON.ACCEPT.INAPP.PAYMENT'` for Accept.js tokens.
170
+
171
+ ## Quick Reference: Common Operations
172
+
173
+ ### Charge with Accept.js Token
174
+
175
+ ```php
176
+ $transaction_request = new AnetAPI\TransactionRequestType();
177
+ $transaction_request->setTransactionType('authCaptureTransaction');
178
+ $transaction_request->setAmount($amount);
179
+ $transaction_request->setPayment($payment_type); // from Accept.js opaque data
180
+ ```
181
+
182
+ ### Charge Stored CIM Profile
183
+
184
+ ```php
185
+ $profile_to_charge = new AnetAPI\CustomerProfilePaymentType();
186
+ $profile_to_charge->setCustomerProfileId($customer_profile_id);
187
+
188
+ $pp = new AnetAPI\PaymentProfileType();
189
+ $pp->setPaymentProfileId($payment_profile_id);
190
+ $profile_to_charge->setPaymentProfile($pp);
191
+
192
+ $transaction_request = new AnetAPI\TransactionRequestType();
193
+ $transaction_request->setTransactionType('authCaptureTransaction');
194
+ $transaction_request->setAmount($amount);
195
+ $transaction_request->setProfile($profile_to_charge);
196
+ ```
197
+
198
+ ### Refund a Settled Transaction
199
+
200
+ ```php
201
+ $credit_card = new AnetAPI\CreditCardType();
202
+ $credit_card->setCardNumber('XXXX1234'); // last 4 digits
203
+ $credit_card->setExpirationDate('XXXX'); // literal 'XXXX'
204
+
205
+ $payment = new AnetAPI\PaymentType();
206
+ $payment->setCreditCard($credit_card);
207
+
208
+ $tx = new AnetAPI\TransactionRequestType();
209
+ $tx->setTransactionType('refundTransaction');
210
+ $tx->setAmount($refund_amount);
211
+ $tx->setRefTransId($original_transaction_id);
212
+ $tx->setPayment($payment);
213
+ ```
214
+
215
+ ### Void an Unsettled Transaction
216
+
217
+ ```php
218
+ $tx = new AnetAPI\TransactionRequestType();
219
+ $tx->setTransactionType('voidTransaction');
220
+ $tx->setRefTransId($transaction_id);
221
+ ```
222
+
223
+ ## Error Handling
224
+
225
+ ### Response Structure
226
+
227
+ AuthNet responses have two levels of messages:
228
+
229
+ 1. **Top-level**: `$response->getMessages()` — API-level success/failure
230
+ 2. **Transaction-level**: `$tresponse->getErrors()` / `$tresponse->getMessages()` — transaction result
231
+
232
+ Always check both. A transaction can fail (`tresponse->getErrors()`) even when the API call succeeds (`result_code === 'Ok'`).
233
+
234
+ ### Common Error Codes
235
+
236
+ | Code | Meaning | Action |
237
+ |------|---------|--------|
238
+ | `E00039` | Duplicate record (CIM profile exists) | Extract existing profile ID from error text |
239
+ | `E00040` | Record not found | Profile was deleted or never existed |
240
+ | `E00027` | Transaction declined | Show user-friendly decline message |
241
+ | `E00003` | Invalid login/transaction key | Check credentials configuration |
242
+ | `E00007` | Permission denied | Check account settings |
243
+ | `E00012` | Duplicate subscription (ARB) | Check for existing subscription |
244
+
245
+ ### E00039 Duplicate Profile Recovery
246
+
247
+ AuthNet includes the existing profile ID in the error text:
248
+
249
+ ```php
250
+ function extract_profile_id_from_error(string $error_text): string|false {
251
+ return preg_match('/ID\s+(\d+)/', $error_text, $m) ? $m[1] : false;
252
+ }
253
+ ```
254
+
255
+ ## When to Load Reference Files
256
+
257
+ ### Full API Reference
258
+ **File**: `references/api-reference.md`
259
+ **Load when**:
260
+ - Need complete SDK class/method listings
261
+ - Working with CIM customer profiles (create, update, delete, payment profiles)
262
+ - Working with ARB recurring billing (subscriptions, schedules, trials)
263
+ - Need webhook event types and HMAC-SHA512 signature validation
264
+ - Working with transaction reporting API
265
+ - Need response code tables or field constraints
266
+ - Implementing refunds, voids, or auth-only flows
267
+
268
+ ### Sandbox & Testing Guide
269
+ **File**: `references/sandbox-testing.md`
270
+ **Load when**:
271
+ - Setting up sandbox environment or test credentials
272
+ - Need test card numbers and expected responses
273
+ - Debugging sandbox-specific issues (CIM→ARB propagation delay)
274
+ - Writing PHPUnit tests for payment functions
275
+ - Need sandbox vs production behavioral differences