Permalink
Browse files

Library now functional. Added example controller which documents the …

…various parameters and options
  • Loading branch information...
1 parent 9a1538f commit 8978efa86c0e5188dc4030afa26840d9869ec64f Ollie Rattue committed Nov 18, 2010
Showing with 244 additions and 138 deletions.
  1. +2 −2 README
  2. +8 −8 config/sagepay_form_config.php
  3. +90 −0 controllers/sagepay_example.php
  4. +144 −128 libraries/sagepay_form.php
View
4 README
@@ -1,4 +1,4 @@
-SagePay Form library - ALPHA - *** non functional code ***
+SagePay Form library - Functional
==========================================================
This CodeIgniter library handles payments via SagePay's
@@ -7,7 +7,7 @@ Form e-commerce system.
TODO
-----
-Integrate product basket
+- Basket support
Extra
-----
@@ -16,26 +16,25 @@
/** IMPORTANT. Set the strYourSiteFQDN value to the Fully Qualified Domain Name of your server. **
** This should start http:// or https:// and should be the name by which our servers can call back to yours **
** i.e. it MUST be resolvable externally, and have access granted to the Sage Pay servers **
-** examples would be https://www.mysite.com or http://212.111.32.22/ **
-** NOTE: You should leave the final / in place. **/
-$config['your_site_fqdn'] = "http://example.com";
+** examples would be https://www.mysite.com or http://212.111.32.22/ **/
+$config['your_site_fqdn'] = "http://example.com/"; // IMPORTANT include final /
// Set this value to the Vendor Name assigned to you by Sage Pay or chosen when you applied
-$config['vendorname'] = "yourvendorname";
+$config['vendor_name'] = "yourvendorname";
/** Set this value to the XOR Encryption password assigned to you by Sage Pay **/
-$config['encryption_password'] = "";
+$config['encryption_password'] = "TPxgfK38BZGxS8Ho";
// Set this to indicate the currency in which you wish to trade. 3 characters Examples: GBP, EUR and USD
// The currency must be supported by one of your Sage Pay merchant accounts or the transaction will be rejected.
$config['currency'] = "GBP";
/** This can be DEFERRED or AUTHENTICATE if your Sage Pay account supports those payment types **/
-$config['transactiontype'] = "PAYMENT";
+$config['transaction_type'] = "PAYMENT";
/** Optional setting. If you are a Sage Pay Partner and wish to flag the transactions with your unique partner id set it here. **/
// Currently not supported by Library
-// $config['partner_id'] = "";
+$config['partner_id'] = "";
/* Optional setting.
** 0 = Do not send either customer or vendor e-mails,
@@ -65,4 +64,5 @@
$config['purchase_url'] = "https://test.sagepay.com/simulator/VSPFormGateway.asp";
}
-?>
+/* End of file sagepay_form_config.php */
+/* Location: ./application/config/sagepay_form_config.php */
@@ -0,0 +1,90 @@
+<?php
+
+/*
+| -------------------------------------------------------------------------
+| Sagepay library example
+| -------------------------------------------------------------------------
+*/
+
+class Sagepay_example extends Controller
+{
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->load->library('sagepay_form');
+ }
+
+ // --------------------------------------------------------------------
+
+ function payment()
+ {
+ $this->sagepay_form->add_data('total', '15.00'); // with 2 decimal places where relevant
+
+ // The domain name and protocol (http or https) is defined in sagepay_form_config
+ // Do not include here.
+ $this->sagepay_form->add_data('success_url', 'sagepay_example/payment_status/success');
+ $this->sagepay_form->add_data('failure_url', 'sagepay_example/payment_status/failure');
+
+ // Billing address
+ $this->sagepay_form->add_data('billing_first_names', "Jo"); // Max 20 characters
+ $this->sagepay_form->add_data('billing_surname', "Blogs"); // Max 20 characters
+ $this->sagepay_form->add_data('billing_address1', "Jo's place"); // Max 100 characters
+ $this->sagepay_form->add_data('billing_address2', ""); // Optional Max 100 characters
+ $this->sagepay_form->add_data('billing_city', "London"); // Max 40 characters
+ $this->sagepay_form->add_data('billing_postcode', "EC8 8RH"); // Max 10 characters
+ $this->sagepay_form->add_data('billing_country', "UK"); // 2 characters ISO 3166-1 country code
+ $this->sagepay_form->add_data('billing_state', ""); // US customers only Max 2 characters State code
+ $this->sagepay_form->add_data('billing_phone', "01205581818"); // Optional Max 20 characters
+
+ // Can be the same as billing
+ $this->sagepay_form->add_data('delivery_first_names', "Jo"); // Max 20 characters
+ $this->sagepay_form->add_data('delivery_surname', "Blogs"); // Max 20 characters
+ $this->sagepay_form->add_data('delivery_address1', "Jo's place"); // Max 100 characters
+ $this->sagepay_form->add_data('delivery_address2', ""); // Optional Max 100 characters
+ $this->sagepay_form->add_data('delivery_city', "London"); // Max 40 characters
+ $this->sagepay_form->add_data('delivery_postcode', "EC8 8RH"); // Max 10 characters
+ $this->sagepay_form->add_data('delivery_country', "UK"); // 2 characters ISO 3166-1 country code
+ $this->sagepay_form->add_data('delivery_state', ""); // US customers only Max 2 characters State code
+ $this->sagepay_form->add_data('delivery_phone', "077974899"); // Optional Max 20 characters
+
+ // Optional values
+ // $this->sagepay_form->add_data('send_email', ''); // Flag Consult the Form Protocol document
+ // $this->sagepay_form->add_data('currency', ''); // 3 characters
+ // $this->sagepay_form->add_data('customer_email', ''); // Max 255 characters
+ // $this->sagepay_form->add_data('vendor_email', ''); // Set in config. You can do a per transaction override Max 255 characters
+ // $this->sagepay_form->add_data('email_message', ''); // A message to the customer which is inserted into the successful transaction e-mails only Max 7500 characters
+
+ // Advanced fine control. Consult the Form Protocol document
+ $this->sagepay_form->add_data('allow_gift_aid', 0); // For charities registered for Gift Aid, set to 1 to display the Gift Aid check box on the payment pages
+ $this->sagepay_form->add_data('apply_avscv2', 0); // Allow fine control over AVS/CV2 checks and rules by changing this value
+ $this->sagepay_form->add_data('apply_3d_secure', 0); // Allow fine control over 3D-Secure checks and rules by changing this value
+ $this->sagepay_form->add_data('billing_agreement', 0); // For PAYPAL REFERENCE transactions
+
+ echo $this->sagepay_form->form();
+ }
+
+ // --------------------------------------------------------------------
+
+ // Redirected to from SagePay Form
+ function payment_status($type = NULL, $crypt = NULL)
+ {
+ switch ($type)
+ {
+ case 'success':
+ echo 'Payment successfully made';
+ break;
+
+ case('failure'):
+ echo 'Payment failed';
+ break;
+
+ default:
+ redirect();
+ break;
+ }
+ }
+
+ // --------------------------------------------------------------------
+}
+?>
Oops, something went wrong.

0 comments on commit 8978efa

Please sign in to comment.