Source of file CommercePaymentMethod.php
Size: 4,780 Bytes - Last Modified: 2021-12-24T05:16:32+00:00
/var/www/docs.ssmods.com/process/src/code/model/payment/CommercePaymentMethod.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | <?php /** * 'Abstract' class that you will extend to add payment providers * These will automatically be added under the "Payments" tab in * Settings, inside the CMS * * */ class CommercePaymentMethod extends DataObject { /** * Shall this class appear in the list of payment providers. Use this to * hide "high level" classes that you intend to extend */ public static $hidden = false; /** * The controller this is mapped to */ public static $handler; /** * Title of this payment method (eg: PayPal, WorldPay, etc) */ public $Title; /** * Route to icon that is associated with this provider */ public $Icon; private static $db = array( // Payment Gateway config "Summary" => "Text", "URL" => "Varchar(200)", "Default" => "Boolean", "GatewayMessage" => "Text", "PaymentInfo" => "HTMLText" ); private static $has_one = array( 'ParentConfig' => 'SiteConfig' ); private static $casting = array( 'Label' => 'Text' ); private static $summary_fields = array( 'Title', 'Summary', 'Default' ); /* * Combine this objects summary and it's icon, if it has one. * * @return String */ public function getLabel() { return ($this->Icon) ? '<img class="payment-icon" src="'. $this->Icon .'" /> <span>' . $this->Summary . '</span>' : "<span>{$this->Summary}</span>"; } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('ParentConfigID'); // Setup Payment Gateway type $payments = ClassInfo::subclassesFor('CommercePaymentMethod'); // Remove parent class from list unset($payments['CommercePaymentMethod']); // Check if any payment types have been hidden and unset foreach($payments as $payment_type) { if($payment_type::$hidden) unset($payments[$payment_type]); } $classname_field = DropdownField::create('ClassName','Type of Payment',$payments) ->setHasEmptyDefault(true) ->setEmptyString('Select Gateway'); $fields->addFieldToTab('Root.Main', $classname_field); if($this->ID) { $fields->addFieldToTab("Root.Main", TextField::create('Summary', 'Summary message to appear on website')); $fields->addFieldToTab("Root.Main", TextField::create('URL', 'Payment gateway URL')); $fields->addFieldToTab("Root.Main", CheckboxField::create('Default', 'Default payment method?')); $fields->addFieldToTab("Root.Main", TextareaField::create('GatewayMessage','Message to appear when user user is directed to payment provider')); $fields->addFieldToTab("Root.Main", HTMLEditorField::create("PaymentInfo", "Message to appear on payment summary page")); // Setup response URL field $callback_url = Controller::join_links( Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "callback", $this->ID ); // Setup completed URL $complete_url = Controller::join_links( Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "complete" ); // Setup error URL $error_url = Controller::join_links( Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "complete", "error" ); $url_field = ToggleCompositeField::create( "PaymentURLS", "Payment integration URLs", FieldList::create( ReadonlyField::create('ResponseURL', 'Response URL') ->setValue($callback_url), ReadonlyField::create('CompletedURL', 'Completed URL') ->setValue($complete_url), ReadonlyField::create('ErrorURL', 'Error URL') ->setValue($error_url) ) ); $fields->addFieldToTab("Root.Main", $url_field); } else { $fields->removeByName('URL'); $fields->removeByName('Summary'); $fields->removeByName('Default'); $fields->removeByName('GatewayMessage'); $fields->removeByName('PaymentInfo'); } return $fields; } // Get relevent payment gateway URL to use in HTML form public function GatewayURL() { return $this->URL; } } |