Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/231801

Change subject: WIP authorize and capture Amazon payment
......................................................................

WIP authorize and capture Amazon payment

Should probably mock the payments client and add tests at this point

Bug: T108119

Change-Id: Ic154941f308d54a628781141d8fbe6093c0ac19f
---
M amazon_gateway/amazon.adapter.php
1 file changed, 50 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/01/231801/1

diff --git a/amazon_gateway/amazon.adapter.php 
b/amazon_gateway/amazon.adapter.php
index 5ded7fa..a0450d8 100644
--- a/amazon_gateway/amazon.adapter.php
+++ b/amazon_gateway/amazon.adapter.php
@@ -28,6 +28,13 @@
        const IDENTIFIER = 'amazon';
        const GLOBAL_PREFIX = 'wgAmazonGateway';
 
+       // FIXME: return_value_map should handle non-numeric return values
+       protected $capture_status_map = array(
+               'Completed' => FinalStatus::COMPLETE,
+               'Pending' => FinalStatus::PENDING,
+               'Declined' => FinalStatus::FAILED,
+       );
+
        function __construct( $options = array() ) {
                parent::__construct( $options );
 
@@ -123,6 +130,7 @@
 
                try {
                        $this->confirmOrderReference();
+                       $this->authorizeAndCapturePayment();
                } catch ( ResponseProcessingException $ex ) {
                        $resultData->addError(
                                $ex->getErrorCode(),
@@ -188,6 +196,48 @@
                ) );
        }
 
+       protected function authorizeAndCapturePayment() {
+               $client = $this->getPwaClient();
+               $orderReferenceId = $this->getData_Staged( 'order_reference_id' 
);
+
+               $authResponse = $client->authorize( array(
+                       'amazon_order_reference_id' => $orderReferenceId,
+                       'authorization_amount' => $this->getData_Staged( 
'amount' ),
+                       'currency_code' => $this->getData_Staged( 
'currency_code' ),
+                       'capture_now' => true,
+                       'authorization_reference_id' => $this->getData_Staged( 
'order_id' ),
+                       'transaction_timeout' => 0, // authorize synchronously
+                       // Could set 'SoftDescriptor' to control what appears 
on CC statement (16 char max, prepended with AMZ*)
+               ) )->toArray();
+               $this->checkErrors( $authResponse );
+
+               $this->logger->info( 'Authorization response: ' . print_r( 
$authResponse, true ) );
+               $authDetails = 
$authResponse['AuthorizeResult']['AuthorizationDetails'];
+               if ( $authDetails['AuthorizationStatus']['State'] === 
'Declined' ) {
+                       throw new ResponseProcessingException(
+                               WmfFramework::formatMessage( 
'php-response-declined' ), // php- ??
+                               
$authDetails['AuthorizationStatus']['ReasonCode']
+                       );
+               }
+               $captureId = $authDetails['IdList']['member']; // IdList 
generally contains the IDs for the next stages
+               $this->addResponseData( array( 'gateway_txn_id' => $captureId ) 
);
+
+               $captureResponse = $client->getCaptureDetails( array(
+                               'amazon_capture_id' => $captureId,
+               ) )->toArray();
+               $this->checkErrors( $captureResponse );
+
+               $this->logger->info( 'Capture details: ' . print_r( 
$captureResponse, true ) );
+               $captureDetails = 
$captureResponse['GetCaptureDetailsResult']['CaptureDetails'];
+               $captureState = $captureDetails['CaptureStatus']['State'];
+
+               $client->closeOrderReference( array(
+                               'amazon_order_reference_id' => 
$orderReferenceId,
+               ) );
+
+               $this->finalizeInternalStatus( 
$this->capture_status_map[$captureState] );
+       }
+
        /**
         * @throws ResponseProcessingException if response contains an error
         * @param array $response

-- 
To view, visit https://gerrit.wikimedia.org/r/231801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic154941f308d54a628781141d8fbe6093c0ac19f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: amazon
Gerrit-Owner: Ejegg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to