-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.driver.php
725 lines (639 loc) · 28 KB
/
extension.driver.php
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
<?php
require_once EXTENSIONS . '/balanced/data-sources/datasource.balanced.php';
require_once(EXTENSIONS . '/balanced/lib/class.balancedgeneral.php');
class Extension_Balanced extends Extension {
private static $provides = array();
public static function registerProviders() {
self::$provides = array(
'data-sources' => array(
'BalancedDatasource' => BalancedDatasource::getName()
)
);
return true;
}
public static function providerOf($type = null) {
self::registerProviders();
if(is_null($type)) return self::$provides;
if(!isset(self::$provides[$type])) return array();
return self::$provides[$type];
}
/*-------------------------------------------------------------------------
Delegates:
-------------------------------------------------------------------------*/
public function getSubscribedDelegates() {
return array(
array(
'page' => '/blueprints/events/',
'delegate' => 'EventPreEdit',
'callback' => 'actionEventPreEdit'
),
array(
'page' => '/blueprints/events/new/',
'delegate' => 'AppendEventFilter',
'callback' => 'actionAppendEventFilter'
),
array(
'page' => '/blueprints/events/edit/',
'delegate' => 'AppendEventFilter',
'callback' => 'actionAppendEventFilter'
),
array(
'page' => '/blueprints/events/',
'delegate' => 'AppendEventFilterDocumentation',
'callback' => 'actionAppendEventFilterDocumentation'
),
array(
'page' => '/frontend/',
'delegate' => 'EventPreSaveFilter',
'callback' => 'actionEventPreSaveFilter'
),
array(
'page' => '/frontend/',
'delegate' => 'EventPostSaveFilter',
'callback' => 'actionEventPostSaveFilter'
),
array(
'page' => '*',
'delegate' => 'SE_PrepareFilter',
'callback' => 'actionEventPreSaveFilter'
),
array(
'page' => '*',
'delegate' => 'SE_CommitFilter',
'callback' => 'actionEventPostSaveFilter'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'actionAddCustomPreferenceFieldsets'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'actionSave'
),
array(
'page' => '/frontend/',
'delegate' => 'FrontendParamsResolve',
'callback' => 'actionAppendAppParams'
)
);
}
/*-------------------------------------------------------------------------
Definition:
-------------------------------------------------------------------------*/
public function actionEventPreEdit($context) {
// Your code goes here...
}
public function actionAppendEventFilter($context) {
$filters = Balanced_General::getAllFilters();
foreach ($filters as $key => $val) {
if (is_array($context['selected'])) {
$selected = in_array($key, $context['selected']);
$context['options'][] = array($key, $selected, $val);
}
}
}
public function actionAppendEventFilterDocumentation($context) {
// Todo not firing
var_dump($context);
}
public function actionEventPreSaveFilter($context) {
$filters = $context['event']->eParamFILTERS;
if(!isset($filters)) {
$filters = $context['filters'];
}
$proceed = false;
foreach ($filters as $key => $val) {
if (in_array($val, array_keys(Balanced_General::getAllFilters()))) {
$proceed = true;
}
}
if(!$proceed) return true;
//print_r($_POST); die();
//if(!isset($_SESSION['symphony-balanced'])) {
$fields = $_POST['balanced'];
if(!isset($fields)) {
$fields = $context['fields']['balanced'];
}
if (isset($fields)) {
// Convert handles if Symphony standard
foreach ($fields as $key => $val) {
$key = str_replace('-', '_', $key);
$fields[$key] = $val;
}
}
$debitFeeVariable = Symphony::Configuration()->get('debit-fee-variable', 'balanced');
$debitFeeFixed = Symphony::Configuration()->get('debit-fee-fixed', 'balanced');
$creditFeeVariable = Symphony::Configuration()->get('credit-fee-variable', 'balanced');
$creditFeeFixed = Symphony::Configuration()->get('credit-fee-fixed', 'balanced');
// Convert dollars into cents
if (isset($fields['subamount'])) {
$fields['subamount'] = Balanced_General::dollarsToCents($fields['subamount']);
$subamount = $fields['subamount'];
}
if (isset($fields['fees'])) {
$fields['fees'] = Balanced_General::dollarsToCents($fields['fees']);
$fees = $fields['fees'];
}
if (isset($fields['amount'])) {
$fields['amount'] = Balanced_General::dollarsToCents($fields['amount']);
}
if (isset($fields['amount_1'])) {
$fields['amount_1'] = Balanced_General::dollarsToCents($fields['amount_1']);
}
if (isset($fields['amount_1'])) {
$fields['amount_1'] = Balanced_General::dollarsToCents($fields['amount_1']);
}
foreach ($filters as $key => $val) {
if (in_array($val, array_keys(Balanced_General::getAllFilters()))) {
try {
switch($val) {
case 'Balanced_Customer-create':
$balancedCustomer = new Balanced\Customer($fields);
$balanced = $balancedCustomer->save();
break;
case 'Balanced_Customer-create-addCard':
if( isset($fields['customer_uri']) ) {
$balancedCustomer = Balanced\Customer::get($fields['customer_uri']);
}
else {
$balancedCustomer = new Balanced\Customer($fields);
}
// card_uri generated by balanced.js
$balancedCustomer->addCard($fields['card_uri']);
$balanced = $balancedCustomer->save();
break;
case 'Balanced_Customer-create-addBankAccount':
if( isset($fields['customer_uri']) ) {
$balancedCustomer = Balanced\Customer::get($fields['customer_uri']);
}
else {
$balancedCustomer = new Balanced\Customer($fields);
}
// bank_account_uri generated by balanced.js
$balancedCustomer->addBankAccount($fields['bank_account_uri']);
$balanced = $balancedCustomer->save();
break;
case 'Balanced_Customer-update':
$balancedCustomer = Balanced\Customer::get($fields['customer_uri']);
$balancedCustomer = Balanced_General::setBalancedFieldsToUpdate($balancedCustomer, $fields);
$balanced = $balancedCustomer->save();
break;
case 'Balanced_Customer-delete':
$balancedCustomer = Balanced\Customer::get($fields['customer_uri']);
$balanced = $balancedCustomer->unstore();
break;
case 'Balanced_Customer-addCard':
$balancedCustomer = Balanced\Customer::get($fields['customer_uri']);
$balanced = $balancedCustomer->addCard($fields['card_uri']);
break;
case 'Balanced_Customer-addBankAccount':
$balancedCustomer = Balanced\Customer::get($fields['customer_uri']);
$balanced = $balancedCustomer->addBankAccount($fields['bank_account_uri']);
$balancedClearBankAccountVerification = true;
break;
/*case 'Balanced_Customer-bankAccount-verification-create':
$balanced = Balanced\Customer::get($fields['customer_uri']);
$balanced = Balanced\BankAccount::get($balanced['bank_account_uri']);
$balanced = $balanced->verify();
break;*/
case 'Balanced_BankAccount-verification-create':
$balancedBankAccount = Balanced\BankAccount::get($fields['bank_account_uri']);
$balanced = $balancedBankAccount->verify();
$prefix = 'bank_account_verification_';
break;
case 'Balanced_BankAccountVerification-update':
$balancedBankAccountVerification = Balanced\BankAccountVerification::get($fields['bank_account_verification_uri']);
$balancedBankAccountVerification->amount_1 = $fields['amount_1'];
$balancedBankAccountVerification->amount_2 = $fields['amount_2'];
$balanced = $balancedBankAccountVerification->save();
$prefix = 'bank_account_verification_';
break;
case 'Balanced_Debit-create':
$customerURI = $fields['customer_uri'];
$onBehalfOfURI = $fields['on_behalf_of_uri'];
$sourceURI = $fields['source_uri'];
$balancedCustomer = Balanced\Customer::get($customerURI);
$appearsText = Symphony::Configuration()->get('appears-on-statement-as', 'balanced');
if (isset($fields['appears_on_statement_as'])) {
$appearsText = $fields['appears_on_statement_as'];
}
// Add fees if subamount is specified
if (isset($fields['subamount'])) {
if (!isset($fields['fees']) || ($fields['fees'] == '')) {
$fees = Balanced_General::calculateFees($subamount, $debitFeeVariable, $debitFeeFixed);
}
$fields['amount'] = $subamount + $fees;
}
$balanced = $balancedCustomer->debit(
$amount = $fields['amount'],
$appears_on_statement_as = $appearsText,
$meta = $fields['meta'],
$description = $fields['description'],
$source = $sourceURI,
$on_behalf_of = $onBehalfOfURI
);
$prefix = 'debit_';
$prefixDebit = true;
break;
case 'Balanced_Debit-refund':
$balancedDebit = Balanced\Debit::get($fields['debit_uri']);
$balanced = $balancedDebit->refund();
$prefix = 'refund_';
break;
case 'Balanced_Credit-create':
$balancedBankAccount = Balanced\BankAccount::get($fields['bank_account_uri']);
$appearsText = Symphony::Configuration()->get('appears-on-statement-as', 'balanced');
if (isset($fields['appears_on_statement_as'])) {
$appearsText = $fields['appears_on_statement_as'];
}
// Add fees if subamount is specified
if (isset($fields['subamount'])) {
if (!isset($fields['fees']) || ($fields['fees'] == '')) {
$fees = Balanced_General::calculateFees($subamount, $creditFeeVariable, $creditFeeFixed);
}
$fields['amount'] = $subamount - $fees;
}
$balanced = $balancedBankAccount->credit(
$amount = $fields['amount'],
$appears_on_statement_as = $appearsText,
$meta = $fields['meta'],
$description = $fields['description']
);
break;
}
} catch (Balanced\Errors\DuplicateAccountEmailAddress $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\InvalidAmount $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\InvalidRoutingNumber $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\InvalidBankAccountNumber $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\Declined $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CannotAssociateMerchantWithAccount $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\AccountIsAlreadyAMerchant $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\NoFundingSource $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\NoFundingDestination $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CardAlreadyAssociated $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CannotAssociateCard $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\BankAccountAlreadyAssociated $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\AddressVerificationFailed $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\MarketplaceAlreadyCreated $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\IdentityVerificationFailed $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\InsufficientFunds $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CannotHold $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CannotCredit $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CannotDebit $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\CannotRefund $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Balanced\Errors\BankAccountVerificationFailure $e) {
$context['messages'][] = array('balanced', false, $e->response->body->description);
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
return $context;
} catch (Exception $e) {
//print_r(Balanced_General::convertObjectToArray($e->response)); die();
//print_r($e); die();
$errorMessage = $e->getMessage();
if(isset($e->response)) {
$errorMessage = $e->response->body->description;
$errorType = 'balanced';
}
$context['messages'][] = array('balanced', false, $errorMessage);
$errorMessage = $errorMessage . "\n\n" . json_encode($filters);
if (!isset($errorType)) {
Balanced_General::emailPrimaryDeveloper($errorMessage);
}
else {
Balanced_General::emailPrimaryDeveloper($e->response->raw_body);
}
return $context;
}
}
}
/*} else {
$balanced = unserialize($_SESSION['symphony-balanced']);
// Ensure updated balanced[...] fields replace empty fields
foreach($balanced as $key => $val) {
if(empty($val) && isset($_POST['balanced'][$key])) {
$balanced[$key] = $_POST['balanced'][$key];
}
}
}*/
if (!empty($balanced)) {
// Convert balanced object to array so that it can be looped
if(is_object($balanced)) {
$balanced = Balanced_General::convertObjectToArray($balanced);
foreach($balanced as $key => $val){
if(is_object($val)) {
$balanced[$key] = Balanced_General::convertObjectToArray($val);
}
// rename the underscore-first keys
if ($key[0] === '_') {
$newKey = substr($key, 1);
$balanced[$newKey] = $val;
unset($balanced[$key]);
}
}
}
// Convert cents back to dollars
$balanced['amount'] = Balanced_General::centsToDollars($balanced['amount']);
$balanced['amount_1'] = Balanced_General::centsToDollars($balanced['amount_1']);
$balanced['amount_2'] = Balanced_General::centsToDollars($balanced['amount_2']);
// Convert cents back to dollars and add back to array
if (isset($subamount)) {
$balanced['subamount'] = Balanced_General::centsToDollars($subamount);
}
else {
$balanced['subamount'] = $balanced['amount'];
}
if (isset($fees)) {
$balanced['fees'] = Balanced_General::centsToDollars($fees);
}
else {
if (isset($fields['amount'])) {
$balanced['fees'] = '0.0';
}
}
// Remove the Balanced ID
if (isset($balanced['id'])) {
unset($balanced['id']);
}
// Prefix response, e.g., bank_verification
if (isset($prefix)) {
foreach ($balanced as $key => $value) {
$balanced[$prefix . $key] = $value;
unset($balanced[$key]);
}
}
if (isset($prefixDebit) && ($prefixDebit === true)) {
$balanced['customer_uri'] = $customerURI;
//$balanced['source_uri'] = $balanced['source']['uri'];
// Workaround to provide current on_behalf_of_uri
$balanced['on_behalf_of_uri'] = $onBehalfOfURI;
$balanced['source_uri'] = $sourceURI;
}
// Add values of response for Symphony event to process
if(is_array($context['fields'])) {
$context['fields'] = array_merge(Balanced_General::prepareFieldsForSymphony($balanced), $context['fields']);
} else {
$context['fields'] = Balanced_General::prepareFieldsForSymphony($balanced);
}
// Reset the Bank Account Verification fields if cleared by new Bank Account
if (isset($balancedClearBankAccountVerification) && ($balancedClearBankAccountVerification === true)) {
$context['fields']['bank-account-verification-type'] = '';
$context['fields']['bank-account-verification-created-at'] = '';
$context['fields']['bank-account-verification-uri'] = '';
$context['fields']['bank-account-verification-updated-at'] = '';
$context['fields']['bank-account-verification-state'] = '';
$context['fields']['bank-account-verification-id'] = '';
$context['fields']['bank-account-verification-attempts'] = '';
$context['fields']['bank-account-verification-remaining-attempts'] = '';
}
// Create the post data cookie element
if ( isset($context['post_values']) ) {
General::array_to_xml($context['post_values'], $balanced, true);
}
else {
$context['post_values'] = new XMLElement('post-values');
General::array_to_xml($context['post_values'], $balanced, true);
}
// Add balanced response to session in case event fails
$_SESSION['symphony-balanced'] = serialize($balanced);
}
return $context;
}
public function actionEventPostSaveFilter($context) {
// Clear session saved response
unset($_SESSION['symphony-balanced']);
}
public function actionAddCustomPreferenceFieldsets($context) {
// If the Payment Gateway Interface extension is installed, don't
// double display the preference, unless this function is called from
// the `pgi-loader` context.
if (in_array('pgi_loader', Symphony::ExtensionManager()->listInstalledHandles()) xor isset($context['pgi-loader'])) return;
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', __('Balanced')));
$div = new XMLElement('div', null);
// Build the Gateway Mode
$label = new XMLElement('label', __('Balanced Mode'));
$options = array(
array('test', Balanced_General::isTestMode(), __('Test')),
array('live', !Balanced_General::isTestMode(), __('Live'))
);
$label->appendChild(Widget::Select('settings[balanced][gateway-mode]', $options));
$div->appendChild($label);
$fieldset->appendChild($div);
// API Keys group div
$group = new XMLElement('div', null, array('class' => 'group'));
// Live Public API Key
$label = new XMLElement('label', __('Live API key secret'));
$label->appendChild(
Widget::Input('settings[balanced][live-api-key]', Symphony::Configuration()->get('live-api-key', 'balanced'))
);
$group->appendChild($label);
// Test Public API Key
$label = new XMLElement('label', __('Test API key secret'));
$label->appendChild(
Widget::Input('settings[balanced][test-api-key]', Symphony::Configuration()->get('test-api-key', 'balanced'))
);
$group->appendChild($label);
$fieldset->appendChild($group);
// Marketplace URIs group div
$group = new XMLElement('div', null, array('class' => 'group'));
// Live Marketplace URI
$label = new XMLElement('label', __('Live Marketplace URI'));
$label->appendChild(
Widget::Input('settings[balanced][live-marketplace-uri]', Symphony::Configuration()->get('live-marketplace-uri', 'balanced'))
);
$group->appendChild($label);
// Test Marketplace URI
$label = new XMLElement('label', __('Test Marketplace URI'));
$label->appendChild(
Widget::Input('settings[balanced][test-marketplace-uri]', Symphony::Configuration()->get('test-marketplace-uri', 'balanced'))
);
$group->appendChild($label);
$fieldset->appendChild($group);
// Appears On Statement As
$div = new XMLElement('div', null);
$label = new XMLElement('label', __('Appears On Statement As (18 characters max)'));
$label->appendChild(
Widget::Input('settings[balanced][appears-on-statement-as]', Symphony::Configuration()->get('appears-on-statement-as', 'balanced'))
);
$div->appendChild($label);
$fieldset->appendChild($div);
// Debit fees group div
$group = new XMLElement('div', null, array('class' => 'group'));
// Debit variable fee
$label = new XMLElement('label', __('Debit variable fee (in percent, e.g., 5%)'));
$label->appendChild(
Widget::Input('settings[balanced][debit-fee-variable]', Symphony::Configuration()->get('debit-fee-variable', 'balanced'))
);
$group->appendChild($label);
// Debit fixed fee
$label = new XMLElement('label', __('Debit fixed fee (in dollars, e.g., 1.50)'));
$label->appendChild(
Widget::Input('settings[balanced][debit-fee-fixed]', Symphony::Configuration()->get('debit-fee-fixed', 'balanced'))
);
$group->appendChild($label);
$fieldset->appendChild($group);
// Credit fees group div
$group = new XMLElement('div', null, array('class' => 'group'));
// Credit variable fee
$label = new XMLElement('label', __('Credit variable fee (in percent, e.g., 5%)'));
$label->appendChild(
Widget::Input('settings[balanced][credit-fee-variable]', Symphony::Configuration()->get('credit-fee-variable', 'balanced'))
);
$group->appendChild($label);
// Credit fixed fee
$label = new XMLElement('label', __('Credit fixed fee (in dollars, e.g., 1.50)'));
$label->appendChild(
Widget::Input('settings[balanced][credit-fee-fixed]', Symphony::Configuration()->get('credit-fee-fixed', 'balanced'))
);
$group->appendChild($label);
$fieldset->appendChild($group);
$context['wrapper']->appendChild($fieldset);
}
public function actionSave($context) {
$settings = $context['settings'];
Symphony::Configuration()->set('gateway-mode', $settings['balanced']['gateway-mode'], 'balanced');
Symphony::Configuration()->set('live-api-key', $settings['balanced']['live-api-key'], 'balanced');
Symphony::Configuration()->set('test-api-key', $settings['balanced']['test-api-key'], 'balanced');
Symphony::Configuration()->set('live-marketplace-uri', $settings['balanced']['live-marketplace-uri'], 'balanced');
Symphony::Configuration()->set('test-marketplace-uri', $settings['balanced']['test-marketplace-uri'], 'balanced');
Symphony::Configuration()->set('appears-on-statement-as', $settings['balanced']['appears-on-statement-as'], 'balanced');
Symphony::Configuration()->set('debit-fee-variable', $settings['balanced']['debit-ee-variable'], 'balanced');
Symphony::Configuration()->set('debit-fee-fixed', $settings['balanced']['debit-fee-fixed'], 'balanced');
Symphony::Configuration()->set('credit-fee-variable', $settings['balanced']['credit-ee-variable'], 'balanced');
Symphony::Configuration()->set('credit-fee-fixed', $settings['balanced']['credit-fee-fixed'], 'balanced');
return Symphony::Configuration()->write();
}
public function install() {
// Create balanced_customer_uri field database:
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_fields_balanced_customer_uri` (
`id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
`field_id` INT(11) unsigned NOT NULL,
`validator` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`disabled` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
// Create balanced_customer_link field database:
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_fields_balanced_customer_link` (
`id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
`field_id` INT(11) unsigned NOT NULL,
`related_field_id` VARCHAR(255) NOT NULL,
`show_association` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
`disabled` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
// Create balanced_resource_uri
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_fields_balanced_resource_uri` (
`id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
`field_id` INT(11) unsigned NOT NULL,
`validator` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`disabled` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
// Create balanced_resource_link field database:
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_fields_balanced_resource_link` (
`id` INT(11) unsigned NOT NULL AUTO_INCREMENT,
`field_id` INT(11) unsigned NOT NULL,
`related_field_id` VARCHAR(255) NOT NULL,
`show_association` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
`disabled` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
}
public function uninstall() {
// Drop field tables:
Symphony::Database()->query("DROP TABLE `tbl_fields_balanced_customer_uri`");
Symphony::Database()->query("DROP TABLE `tbl_fields_balanced_customer_link`");
Symphony::Database()->query("DROP TABLE `tbl_fields_balanced_resource_uri`");
Symphony::Database()->query("DROP TABLE `tbl_fields_balanced_resource_link`");
// Clean configuration
Symphony::Configuration()->remove('gateway-mode', 'balanced');
Symphony::Configuration()->remove('live-api-key', 'balanced');
Symphony::Configuration()->remove('test-api-key', 'balanced');
Symphony::Configuration()->remove('live-marketplace-uri', 'balanced');
Symphony::Configuration()->remove('test-marketplace-uri', 'balanced');
Symphony::Configuration()->remove('appears-on-statement-as', 'balanced');
Symphony::Configuration()->remove('debit-fee-variable', 'balanced');
Symphony::Configuration()->remove('debit-fee-fixed', 'balanced');
Symphony::Configuration()->remove('credit-fee-variable', 'balanced');
Symphony::Configuration()->remove('credit-fee-fixed', 'balanced');
return Symphony::Configuration()->write();
}
public function actionAppendAppParams($context) {
// Add marketplace URI to Symphony page params.
$context['params']['balanced-marketplace-uri'] = Balanced_General::getMarketplaceUri();
}
}