Permalink
Browse files

BUGFIX: Adding allowed actions to controller.

  • Loading branch information...
frankmullenger committed Dec 18, 2013
1 parent 2705900 commit 2cdcc2a0284552ac9f242acdf6998b7034803295
Showing with 55 additions and 50 deletions.
  1. +5 −5 code/PayPal.php
  2. +38 −38 code/PayPalGateway.php
  3. +12 −7 code/PayPalProcessor.php
View
@@ -1,9 +1,9 @@
<?php
class PayPal_Express extends Payment {
-
- static $db = array(
- 'Token' => 'Varchar',
- 'PayerID' => 'Varchar'
- );
+
+ static $db = array(
+ 'Token' => 'Varchar',
+ 'PayerID' => 'Varchar'
+ );
}
View
@@ -3,23 +3,23 @@
class PayPalGateway extends PaymentGateway_GatewayHosted {
protected $supportedCurrencies = array(
- 'NZD' => 'New Zealand Dollar',
- 'USD' => 'United States Dollar',
- 'GBP' => 'Great British Pound',
- 'AUD' => 'Australian Dollar',
- 'CAD' => 'Canadian Dollar',
- 'CZK' => 'Czech Koruna',
- 'DKK' => 'Danish Krone',
- 'EUR' => 'Euro',
- 'HKD' => 'Hong Kong Dollar',
- 'HUF' => 'Hungarian Forint',
- 'JPY' => 'Japanese Yen',
- 'NOK' => 'Norwegian Krone',
- 'PLN' => 'Polish Zloty',
- 'SGD' => 'Singapore Dollar',
- 'SEK' => 'Swedish Krona',
- 'CHF' => 'Swiss Franc',
- );
+ 'NZD' => 'New Zealand Dollar',
+ 'USD' => 'United States Dollar',
+ 'GBP' => 'Great British Pound',
+ 'AUD' => 'Australian Dollar',
+ 'CAD' => 'Canadian Dollar',
+ 'CZK' => 'Czech Koruna',
+ 'DKK' => 'Danish Krone',
+ 'EUR' => 'Euro',
+ 'HKD' => 'Hong Kong Dollar',
+ 'HUF' => 'Hungarian Forint',
+ 'JPY' => 'Japanese Yen',
+ 'NOK' => 'Norwegian Krone',
+ 'PLN' => 'Polish Zloty',
+ 'SGD' => 'Singapore Dollar',
+ 'SEK' => 'Swedish Krona',
+ 'CHF' => 'Swiss Franc',
+ );
}
@@ -30,8 +30,8 @@ class PayPalGateway_Express extends PayPalGateway {
private function callAPI($data) {
$config = $this->getConfig();
- $authentication = $config['authentication'];
- $endpoint = $config['endpoint'];
+ $authentication = $config['authentication'];
+ $endpoint = $config['endpoint'];
$auth = array(
'USER' => $authentication['username'],
@@ -51,7 +51,7 @@ private function callAPI($data) {
private function formatResponse($nvpstr){
$intial = 0;
- $nvpArray = array();
+ $nvpArray = array();
while(strlen($nvpstr)){
//postion of Key
@@ -67,8 +67,8 @@ private function formatResponse($nvpstr){
//decoding the respose
$nvpArray[urldecode($keyval)] =urldecode( $valval);
$nvpstr=substr($nvpstr,$valuepos+1,strlen($nvpstr));
- }
-
+ }
+
return $nvpArray;
}
@@ -115,33 +115,33 @@ public function authorise($data) {
public function process($data) {
$config = $this->getConfig();
- $url = $config['url'];
+ $url = $config['url'];
$paymentURL = $url . $this->tokenID . '&useraction=commit'; //useraction=commit ensures the payment is confirmed on PayPal not on a merchant confirm page
if (!$paymentURL) {
return new PaymentGateway_Failure(null, 'URL could not be generated from token.');
}
Controller::curr()->redirect($paymentURL);
- }
-
- /**
- * Confirm the payment by processing DoExpressCheckoutPayment
- * https://www.x.com/developers/paypal/documentation-tools/api/doexpresscheckoutpayment-api-operation-nvp
- */
- public function confirm($data) {
-
- $payload = array(
- 'VERSION' => '94.0',
- 'METHOD' => 'DoExpressCheckoutPayment',
- 'PAYERID' => $data['PayerID'],
+ }
+
+ /**
+ * Confirm the payment by processing DoExpressCheckoutPayment
+ * https://www.x.com/developers/paypal/documentation-tools/api/doexpresscheckoutpayment-api-operation-nvp
+ */
+ public function confirm($data) {
+
+ $payload = array(
+ 'VERSION' => '94.0',
+ 'METHOD' => 'DoExpressCheckoutPayment',
+ 'PAYERID' => $data['PayerID'],
'TOKEN' => $data['Token'],
'PAYMENTREQUEST_0_AMT' => $data['Amount'],
'PAYMENTREQUEST_0_CURRENCYCODE' => $data['Currency'],
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale'
- );
+ );
- $response = $this->callAPI($payload);
+ $response = $this->callAPI($payload);
$body = $this->formatResponse($response->getBody());
if(!isset($body['ACK']) || !(strtoupper($body['ACK']) == 'SUCCESS' || strtoupper($body['ACK']) == 'SUCCESSWITHWARNING')){
@@ -215,5 +215,5 @@ public function confirm($data) {
}
return $result;
- }
+ }
}
View
@@ -2,6 +2,11 @@
class PayPalProcessor_Express extends PaymentProcessor {
+ private static $allowed_actions = array(
+ 'capture',
+ 'complete'
+ );
+
public function capture($data) {
parent::capture($data);
@@ -15,17 +20,17 @@ public function capture($data) {
));
// Authorise the payment and get token
- $result = $this->gateway->authorise($this->paymentData);
-
- if ($result && !$result->isSuccess()) {
+ $result = $this->gateway->authorise($this->paymentData);
+
+ if ($result && !$result->isSuccess()) {
$this->payment->updateStatus($result);
$this->doRedirect();
return;
}
// Save the token for good measure
- $this->payment->Token = $this->gateway->tokenID;
- $this->payment->write();
+ $this->payment->Token = $this->gateway->tokenID;
+ $this->payment->write();
// Process payment
$result = $this->gateway->process($this->paymentData);
@@ -44,8 +49,8 @@ public function complete($request) {
$this->payment = Payment::get()->byID($request->param('OtherID'));
// Save the payer ID for good measure
- $this->payment->PayerID = $request->getVar('PayerID');
- $this->payment->write();
+ $this->payment->PayerID = $request->getVar('PayerID');
+ $this->payment->write();
// Reconstruct the gateway object
$methodName = $request->param('ID');

0 comments on commit 2cdcc2a

Please sign in to comment.