20use SmashPig\Core\Logging\Logger;
21use SmashPig\Core\PaymentError;
22use SmashPig\PaymentData\FinalStatus;
70 $me = get_called_class();
71 parent::__construct( $me );
81 $language = $this->
getRequest()->getVal(
'language' );
82 $this->showError = $this->
getRequest()->getBool(
'showError' );
89 $donorData = WmfFramework::getSessionValue(
'Donor' );
90 if ( ( $donorData !==
null ) && isset( $donorData[
'language' ] ) ) {
91 $language = $donorData[
'language' ];
99 if ( $this->
getConfig()->
get(
'DonationInterfaceFundraiserMaintenance' ) ) {
100 $this->
getOutput()->redirect( Title::newFromText(
'Special:FundraiserMaintenance' )->getFullURL(),
'302'
111 $this->adapter =
new $className( [
'variant' => $variant ] );
115 Logger::getContext()->enterContext( $this->adapter->getLogMessagePrefix() );
124 $out->
addModules(
'donationInterface.skinOverride' );
129 'name' =>
'viewport',
130 'content' =>
'initial-scale=1.0, user-scalable=yes, minimum-scale=0.25, maximum-scale=5.0, width=device-width',
135 }
catch ( Exception $ex ) {
136 if ( !$this->logger ) {
142 $this->logger->error(
143 "Exception setting up GatewayPage with adapter class $className: " .
144 "{$ex->getMessage()}\n{$ex->getTraceAsString()}"
152 if ( $this->adapter->getGlobal(
'Enabled' ) !==
true ) {
153 $this->logger->info(
'Displaying fail page for disabled gateway' );
158 if ( $this->adapter->getFinalStatus() === FinalStatus::FAILED ) {
159 $this->logger->info(
'Displaying fail page for failed GatewayReady checks' );
166 }
catch ( Exception $ex ) {
167 $this->logger->error(
"Displaying fail page for exception: " . $ex->getMessage() );
188 if ( $this->showError ) {
193 $form->setGateway( $this->adapter );
194 $form->setGatewayPage( $this );
196 $formHtml = $form->getForm();
199 if ( !$this->showError ) {
207 'MakeGlobalVariablesScript', [ $this,
'setClientVariablesWithErrorHandling' ]
213 $output->addModules( $form->getResources() );
214 $output->addModuleStyles( $form->getStyleModules() );
215 $output->addHTML( $formHtml );
222 if ( $this->adapter ) {
223 $this->showError =
true;
227 $output->prepareErrorPage( $this->
msg(
'donate_interface-error-msg-general' ) );
228 $output->addHTML( $this->
msg(
229 'donate_interface-otherways',
230 [ $this->
getConfig()->
get(
'DonationInterfaceOtherWaysURL' ) ]
255 $results = empty( $results ) ? $this->adapter->getTransactionResponse() : $results;
257 if ( $this->adapter->getGlobal(
'DisplayDebug' ) !==
true ) {
263 $output->addHTML( Html::element(
'span',
null, $results->getMessage() ) );
265 $errors = $results->getErrors();
266 if ( !empty( $errors ) ) {
267 $output->addHTML( Html::openElement(
'ul' ) );
268 foreach ( $errors as $code => $value ) {
269 $output->addHTML( Html::element(
'li',
null,
"Error $code: " . print_r( $value,
true ) ) );
271 $output->addHTML( Html::closeElement(
'ul' ) );
274 $data = $results->getData();
275 if ( !empty( $data ) ) {
276 $output->addHTML( Html::openElement(
'ul' ) );
277 foreach ( $data as $key => $value ) {
278 if ( is_array( $value ) ) {
279 $output->addHTML( Html::openElement(
'li',
null ) . Html::openElement(
'ul' ) );
280 foreach ( $value as $key2 => $val2 ) {
281 $output->addHTML( Html::element(
'li',
null,
"$key2: $val2" ) );
283 $output->addHTML( Html::closeElement(
'ul' ) . Html::closeElement(
'li' ) );
285 $output->addHTML( Html::element(
'li',
null,
"$key: $value" ) );
288 $output->addHTML( Html::closeElement(
'ul' ) );
290 $output->addHTML(
"Empty Results" );
292 $donorData = $this->
getRequest()->getSessionData(
'Donor' );
293 if ( is_array( $donorData ) ) {
294 $output->addHTML(
"Session Donor Vars:" . Html::openElement(
'ul' ) );
295 foreach ( $donorData as $key => $val ) {
296 $output->addHTML( Html::element(
'li',
null,
"$key: $val" ) );
298 $output->addHTML( Html::closeElement(
'ul' ) );
300 $output->addHTML(
"No Session Donor Vars:" );
303 if ( is_array( $this->adapter->debugarray ) ) {
304 $output->addHTML(
"Debug Array:" . Html::openElement(
'ul' ) );
305 foreach ( $this->adapter->debugarray as $val ) {
306 $output->addHTML( Html::element(
'li',
null, $val ) );
308 $output->addHTML( Html::closeElement(
'ul' ) );
310 $output->addHTML(
"No Debug Array" );
324 if ( $this->adapter->checkTokens() ) {
327 $validated_ok = $this->adapter->validatedOK();
330 if ( $validated_ok ) {
339 $this->adapter->session_addDonorData();
343 $this->adapter->getErrorState()->addError(
new PaymentError(
345 'Failed CSRF token validation',
359 if ( $this->adapter->posted ) {
365 $redirect = $this->adapter->getData_Unstaged_Escaped(
'redirect' );
366 if ( $redirect !==
null ) {
367 return ( $redirect ===
'1' || $redirect ===
'true' );
389 $this->logger->info(
'Displaying fail page for failed PaymentResult' );
392 $this->adapter->logPending();
394 } elseif ( $url = $result->
getIframe() ) {
407 } elseif ( $this->adapter->showMonthlyConvert() ) {
408 $this->logger->info(
"Displaying monthly convert modal after successful one-time donation PaymentResult" );
413 $this->logger->info(
"Displaying thank you page $thankYouPage for successful PaymentResult." );
414 $this->
getOutput()->redirect( $thankYouPage );
427 'id' =>
'paymentiframe',
428 'name' =>
'paymentiframe',
433 $attrs[
'frameborder'] =
'0';
434 $attrs[
'style'] =
'display:block;';
435 $attrs[
'src'] = $url;
436 $paymentFrame = Xml::openElement(
'iframe', $attrs );
437 $paymentFrame .= Xml::closeElement(
'iframe' );
439 $this->
getOutput()->addHTML( $paymentFrame );
449 $donorData = $this->
getRequest()->getSessionData(
'Donor' );
450 if ( is_array( $donorData ) ) {
451 if ( isset( $donorData[
'contribution_tracking_id'] ) ) {
452 $info[] = $donorData[
'contribution_tracking_id'];
454 if ( isset( $donorData[
'order_id'] ) ) {
455 $info[] = $donorData[
'order_id'];
458 return implode(
':', $info ) .
' ';
462 parent::setHeaders();
466 $this->
getOutput()->setPageTitle( $this->
msg(
'donate_interface-make-your-donation' ) );
472 }
catch ( Exception $ex ) {
473 $this->logger->error(
474 "Redirecting to fail page for exception in setClientVariables: " . $ex->getMessage()
481 $vars[
'DonationInterfaceSetClientVariablesError'] =
true;
483 $hasParams = count( $request->getQueryValuesOnly() ) > 0;
484 $vars[
'DonationInterfaceFailUrl'] = $request->getFullRequestURL() .
485 ( $hasParams ?
'&' :
'?' ) .
'showError=true';
494 $language = $this->adapter->getData_Unstaged_Escaped(
'language' );
495 $country = $this->adapter->getData_Unstaged_Escaped(
'country' );
496 $vars[
'wgDonationInterfaceAmountRules'] = $this->adapter->getDonationRules();
497 $vars[
'wgDonationInterfaceLogDebug'] = $this->adapter->getGlobal(
'LogDebug' );
498 if ( $this->adapter->showMonthlyConvert() ) {
500 $vars[
'wgDonationInterfaceThankYouUrl'] = $thankYouUrl;
501 $vars[
'showMConStartup'] = $this->
getRequest()->getBool(
'debugMonthlyConvert' );
502 $vars[
'wgDonationInterfaceMonthlyConvertAmounts'] = $this->adapter->getMonthlyConvertAmounts();
506 $clientRules = $this->adapter->getClientSideValidationRules();
507 if ( !empty( $clientRules ) ) {
511 foreach ( $clientRules as &$fieldRules ) {
512 foreach ( $fieldRules as &$rule ) {
513 if ( !empty( $rule[
'messageKey'] ) ) {
522 $vars[
'wgDonationInterfaceValidationRules'] = $clientRules;
524 }
catch ( Exception $ex ) {
525 $this->logger->warning(
526 'Caught exception setting client-side validation rules: ' .
537 $variant = $this->
getRequest()->getVal(
'variant' );
539 $donorData = $this->
getRequest()->getSessionData(
'Donor' );
540 if ( $donorData && !empty( $donorData[
'variant'] ) ) {
541 $variant = $donorData[
'variant'];
573 $gatewayClasses = $mwConfig->get(
'DonationInterfaceGatewayAdapters' );
578 if ( str_starts_with( $gatewayClasses[ $gatewayId ],
'Testing' ) ) {
579 $specialPage =
'GatewayChooser';
583 $specialPage = str_replace(
586 $gatewayClasses[ $gatewayId ]
static setSmashPigProvider( $provider)
Initialize SmashPig context and return configuration object.
static getAdapterClassForGateway( $gateway)
static getLogger(GatewayType $adapter, $suffix='', LogPrefixProvider $prefixer=null)
static getLoggerForType( $adapterType, $prefix='')
Get a logger without an adapter instance.
GatewayPage This class is the generic unlisted special page in charge of actually displaying the form...
processPayment()
Ask the adapter to perform a payment.
handleDonationRequest()
Respond to a donation request.
addGatewaySpecificResources(OutputPage $out)
Override this to add any gateway-specific scripts or stylesheets that can't be loaded via ResourceLoa...
GatewayAdapter $adapter
The gateway adapter object.
showSubmethodButtons()
Integrations that do not show submethod buttons should override to return false.
static getGatewayPageName(string $gatewayId, Config $mwConfig)
Get the name of the special page for a gateway.
displayForm()
Build and display form to user.
renderIframe( $url)
Append iframe.
setClientVariablesWithErrorHandling(&$vars)
getLogPrefix()
Try to get donor information to tag log entries in case we don't have an adapter instance.
bool $supportsMonthlyConvert
flag for setting Monthly Convert modal on template
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
bool $showError
When true, display an error form rather than the standard payment form.
execute( $par)
Show the special page.
getGatewayIdentifier()
Get the current adapter class.
string $gatewayIdentifier
Derived classes must override this with the identifier of the gateway as set in GatewayAdapter::IDENT...
showContinueButton()
Integrations that never need a continue button should override to return false.
setClientVariables(&$vars)
MakeGlobalVariablesScript handler, sends settings to Javascript.
displayResultsForDebug(PaymentTransactionResponse $results=null)
displayResultsForDebug
__construct()
Constructor.
renderResponse(PaymentResult $result)
Take UI action suggested by the payment result.
handleRequest()
Handle the donation request.
displayFailPage()
Display a failure page.
isProcessImmediate()
Determine if we should attempt to process the payment now.
Psr Log LoggerInterface $logger
Gateway-specific logger.
static getCountrySpecificMessage( $key, $country, $language, $params=[])
Retrieves and translates a country-specific message, or the default if no country-specific version ex...
This is one of the Core classes and should be read at least once by any new developers.
preventClickjacking( $enable=true)
Set a flag which will cause an X-Frame-Options header appropriate for edit pages to be sent.
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.
addHeadItem( $name, $value)
Add or replace a head item to the output.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
Contains donation workflow UI hints.
Contains information parsed out of a payment processor's response to a transaction.
static getThankYouPage(GatewayType $adapter, $extraParams=[])
Get the URL for a page to show donors after a successful donation, with the country code appended as ...
getOutput()
Get the OutputPage being used for this instance.
getContext()
Gets the context this SpecialPage is executed in.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
Shortcut to construct a special page which is unlisted by default.
Interface for configuration instances.