-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDonationInterface.class.php
113 lines (99 loc) · 4.19 KB
/
DonationInterface.class.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
<?php
use SmashPig\Core\Context;
use SmashPig\Core\GlobalConfiguration;
use SmashPig\Core\ProviderConfiguration;
class DonationInterface {
/**
* Executed after processing extension.json
*/
public static function registerExtension() {
global $wgDonationInterfaceTest,
$wgDonationInterfaceTemplate,
$wgDonationInterfaceErrorTemplate,
$wgDonationInterfaceMessageSourceType,
$IP;
// Test mode (not for production!)
// Set it if not defined
if ( !isset( $wgDonationInterfaceTest ) || $wgDonationInterfaceTest !== true ) {
$wgDonationInterfaceTest = false;
}
/**
* Default top-level template file.
*/
$wgDonationInterfaceTemplate = __DIR__ . '/gateway_forms/mustache/index.html.mustache';
/**
* Default top-level error template file.
*/
$wgDonationInterfaceErrorTemplate = __DIR__ . '/gateway_forms/mustache/error_form.html.mustache';
// Initialize the SmashPig context
$spConfig = GlobalConfiguration::create();
Context::init( $spConfig );
$context = Context::get();
$context->setSourceName( 'DonationInterface' );
$context->setSourceType( $wgDonationInterfaceMessageSourceType );
$context->setVersionFromFile( "$IP/.version-stamp" );
}
public static function onDonationInterfaceUnitTests( &$files ) {
global $wgAutoloadClasses;
$testDir = __DIR__ . '/tests/phpunit/';
// Set up globaltown
if ( file_exists( $testDir . 'TestConfiguration.php' ) ) {
require_once $testDir . 'TestConfiguration.php';
} else {
return true;
}
$wgAutoloadClasses['DonationInterfaceTestCase'] = $testDir . 'DonationInterfaceTestCase.php';
$wgAutoloadClasses['DonationInterfaceApiTestCase'] = $testDir . 'DonationInterfaceApiTestCase.php';
$wgAutoloadClasses['BaseAdyenCheckoutTestCase'] = $testDir . 'BaseAdyenCheckoutTestCase.php';
$wgAutoloadClasses['BaseGravyTestCase'] = $testDir . 'BaseGravyTestCase.php';
$wgAutoloadClasses['BaseIngenicoTestCase'] = $testDir . 'BaseIngenicoTestCase.php';
$wgAutoloadClasses['BaseBraintreeTestCase'] = $testDir . 'BaseBraintreeTestCase.php';
$wgAutoloadClasses['TestingDlocalAdapter'] = $testDir . 'includes/test_gateway/TestingDlocalAdapter.php';
$wgAutoloadClasses['TestingDonationLogger'] = $testDir . 'includes/TestingDonationLogger.php';
$wgAutoloadClasses['TestingGatewayPage'] = $testDir . 'includes/TestingGatewayPage.php';
$wgAutoloadClasses['BaseDlocalTestCase'] = $testDir . 'BaseDlocalTestCase.php';
$wgAutoloadClasses['TestingGenericAdapter'] = $testDir . 'includes/test_gateway/TestingGenericAdapter.php';
$wgAutoloadClasses['TestingPaypalExpressAdapter'] = $testDir . 'includes/test_gateway/TestingPaypalExpressAdapter.php';
$wgAutoloadClasses['TestingRequest'] = $testDir . 'includes/test_request/test.request.php';
$wgAutoloadClasses['TTestingAdapter'] = $testDir . 'includes/test_gateway/test.adapter.php';
return true;
}
public static function getAdapterClassForGateway( $gateway ) {
global $wgDonationInterfaceGatewayAdapters;
if ( !array_key_exists( $gateway, $wgDonationInterfaceGatewayAdapters ) ) {
throw new OutOfRangeException( "No adapter configured for $gateway" );
}
return $wgDonationInterfaceGatewayAdapters[$gateway];
}
/**
* Initialize SmashPig context and return configuration object
*
* @param string $provider
* @return ProviderConfiguration
*/
public static function setSmashPigProvider( $provider ) {
$ctx = Context::get();
$spConfig = ProviderConfiguration::createForProvider(
$provider,
$ctx->getGlobalConfiguration()
);
// FIXME: should set a logger prefix here, but we've got a chicken
// and egg problem with the Gateway constructor
$ctx->setProviderConfiguration( $spConfig );
return $spConfig;
}
/**
* Register es-419 as a language supported by this extension but not by
* MediaWiki core. Handles Language::onGetMessagesFileName hook called in
* LanguageNameUtils::getMessagesFileName
*
* @param string $code language code
* @param string &$file path of Messages file as found by MediaWiki core
*/
public static function onGetMessagesFileName( $code, &$file ) {
if ( $code === 'es-419' ) {
$file = __DIR__ . DIRECTORY_SEPARATOR . 'gateway_common' . DIRECTORY_SEPARATOR .
'messages' . DIRECTORY_SEPARATOR . 'MessagesEs_419.php';
}
}
}