Source of file PaystationHostedPayment.php
Size: 4,426 Bytes - Last Modified: 2021-12-23T10:33:28+00:00
/var/www/docs.ssmods.com/process/src/code/PayStation/PaystationHostedPayment.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 | <?php class PaystationHostedPayment extends Payment { // Paystation Information protected static $privacy_link = 'http://paystation.co.nz/privacy-policy'; protected static $logo = 'payment/images/payments/paystation.jpg'; // URLs protected static $url = 'https://www.paystation.co.nz/dart/darthttp.dll?paystation&pi=%s&ms=%s&am=%s'; // Test Mode protected static $test_mode = false; public static function set_test_mode() { self::$test_mode = true; } // Payment Informations protected static $merchant_id; public static function set_merchant_id($merchant_id) { self::$merchant_id = $merchant_id; } protected static $merchant_ref; public static function set_merchant_ref($merchant_ref) { self::$merchant_ref = $merchant_ref; } public function getPaymentFormFields() { $logo = '<img src="' . self::$logo . '" alt="Credit card payments powered by Paystation"/>'; $privacyLink = '<a href="' . self::$privacy_link . '" target="_blank" title="Read Paystation\'s privacy policy">' . $logo . '</a><br/>'; return new FieldSet( new LiteralField('PaystationInfo', $privacyLink), new LiteralField( 'PaystationPaymentsList', '<img src="payment/images/payments/methods/visa.jpg" alt="Visa"/>' . '<img src="payment/images/payments/methods/mastercard.jpg" alt="MasterCard"/>' . '<img src="payment/images/payments/methods/american-express.gif" alt="American Express"/>' ) ); } public function getPaymentFormRequirements() { return null; } public function processPayment($data, $form) { $page = new Page(); $page->Title = 'Redirection to Paystation...'; $page->Logo = '<img src="' . self::$logo . '" alt="Payments powered by Paystation"/>'; $page->Form = $this->PaystationForm(); $controller = new Page_Controller($page); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); $form = $controller->renderWith('PaymentProcessingPage'); return new Payment_Processing($form); } public function PaystationForm() { // 1) Main Informations $order = $this->Order(); $member = $order->Member(); // 2) Main Settings $amount = $order->Total() * 100; $url = sprintf(self::$url, self::$merchant_id, $this->ID, $amount); if (self::$test_mode) { $url .= '&tm=t'; } if (self::$merchant_ref) { $url .= '&merchant_ref=' . self::$merchant_ref; } $url = Convert::raw2xml($url); // 3) Form Creation return<<<HTML <script type="text/javascript"> jQuery(document).ready(function() { location = "$url"; }); </script> HTML; } } /** * Handler for responses from the PayPal site */ class PaystationHostedPayment_Handler extends Controller { public static $URLSegment = 'paystation'; public static function complete_link() { return self::$URLSegment . '/complete'; } public function complete() { if (isset($_REQUEST['ec'])) { if (isset($_REQUEST['ms'])) { if ($payment = DataObject::get_by_id('PaystationHostedPayment', $_REQUEST['ms'])) { $payment->Status = $_REQUEST['ec'] == '0' ? 'Success' : 'Failure'; if ($_REQUEST['ti']) { $payment->TxnRef = $_REQUEST['ti']; } if ($_REQUEST['em']) { $payment->Message = $_REQUEST['em']; } $payment->write(); $payment->redirectToOrder(); } else { user_error('There is no any Paystation hosted payment which ID is #' . $_REQUEST['ms'], E_USER_ERROR); } } else { user_error('There is no any Paystation hosted payment ID specified', E_USER_ERROR); } } else { user_error('There is no any Paystation hosted payment error code specified', E_USER_ERROR); } } } |