Browse files

Initial commit.

  • Loading branch information...
1 parent 5aa8cc1 commit 365d20528e90e13a190e2cface45393b13fc4d89 @frankmullenger committed Jun 6, 2012
Showing with 77 additions and 0 deletions.
  1. +1 −0 _config.php
  2. +64 −0 code/PaymentTestPage.php
  3. +12 −0 templates/Layout/PaymentTestPage.ss
View
1 _config.php
@@ -0,0 +1 @@
+<?php
View
64 code/PaymentTestPage.php
@@ -0,0 +1,64 @@
+<?php
+
+class PaymentTestPage extends Page {
+
+ /**
+ * TODO Could use to create default payment test page when /dev/build is run
+ */
+ function requireDefaultRecords() {
+ parent::requireDefaultRecords();
+ }
+}
+
+class PaymentTestPage_Controller extends Page_Controller {
+
+ /**
+ * Get the order form for processing a dummy payment
+ */
+ function OrderForm() {
+
+ $fields = new FieldList();
+
+ //$dummyPayment = singleton('Dummy_Payment');
+ //SS_Log::log(new Exception(print_r($dummyPayment, true)), SS_Log::NOTICE);
+
+ //TODO For each payment method that is enabled get the form fields
+ //old way was Payment::get_combined_form_fields() - is there a better way now?
+ //maybe we can use DI for this also?
+
+ $paymentFields = singleton('Dummy_Payment')->getFormFields();
+ //SS_Log::log(new Exception(print_r($paymentFields->map(), true)), SS_Log::NOTICE);
+
+ //TODO should we wrap payment fields in a CompositeField so we can just
+ //$fields->push($paymentFields);
+ //or is that too restrictive from a frontend perspective?
+
+ if ($paymentFields && $paymentFields->exists()) foreach ($paymentFields as $paymentField) {
+ $fields->push($paymentField);
+ }
+
+ $actions = new FieldList(
+ new FormAction('processOrder', 'Place order')
+ );
+
+ return new Form($this, 'OrderForm', $fields, $actions);
+ }
+
+ /**
+ * Process order
+ */
+ function processOrder($data, $form) {
+
+ $paymentMethod = $data['PaymentMethod'];
+ $paymentController = Payment_Factory::createController($paymentMethod);
+
+ $result = $paymentController->processRequest($data);
+
+ $customisedController = $this->customise(array(
+ "Content" => 'Payment #' . $result->ID . ' status:' . $result->Status,
+ "Form" => '',
+ ));
+ return $customisedController->renderWith("Page");
+ }
+
+}
View
12 templates/Layout/PaymentTestPage.ss
@@ -0,0 +1,12 @@
+<div class="content-container">
+ <article>
+ <h1>$Title</h1>
+ <div class="content">$Content</div>
+ </article>
+
+ $OrderForm
+
+ $Form
+ $PageComments
+</div>
+<% include SideBar %>

0 comments on commit 365d205

Please sign in to comment.