Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/334475 )

Change subject: WIP PayPal verification uses OutboundRequest
......................................................................

WIP PayPal verification uses OutboundRequest

Change-Id: I6cc8c5ba38c8802805984516eee71f842d70714a
TODO: figure our exactly how we want to mock the thing.
---
M PaymentProviders/PayPal/PayPalPaymentsAPI.php
1 file changed, 14 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/SmashPig 
refs/changes/75/334475/1

diff --git a/PaymentProviders/PayPal/PayPalPaymentsAPI.php 
b/PaymentProviders/PayPal/PayPalPaymentsAPI.php
index f46939c..cea1b9a 100644
--- a/PaymentProviders/PayPal/PayPalPaymentsAPI.php
+++ b/PaymentProviders/PayPal/PayPalPaymentsAPI.php
@@ -1,17 +1,12 @@
 <?php namespace SmashPig\PaymentProviders\PayPal;
 
+use HttpRuntimeException;
 use RuntimeException;
 use SmashPig\Core\Configuration;
+use SmashPig\Core\Http\OutboundRequest;
 use SmashPig\Core\Logging\Logger;
 
 class PayPalPaymentsAPI {
-
-       // Simply a function to override in testing.
-       protected function curl( $ch, $post_fields ) {
-               $post_fields['cmd'] = '_notify-validate';
-               curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_fields );
-               return curl_exec( $ch );
-       }
 
        /**
         * @param array $post_fields Associative array of fields posted to 
listener
@@ -22,36 +17,24 @@
                // 
https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1336&actp=LIST
                // PayPal randomly fails to validate messages, so try a few 
times.
                $max_attempts = 7;
+               $post_fields['cmd'] = '_notify-validate';
 
                for ( $i = 0; $i < $max_attempts; $i++ ) {
                        $url = Configuration::getDefaultConfig()->val( 
'postback-url' );
-                       $ch = curl_init();
-                       curl_setopt( $ch, CURLOPT_URL, $url );
-                       curl_setopt( $ch, CURLOPT_HEADER, 0 );
-                       curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 );
-                       curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
-                       curl_setopt( $ch, CURLOPT_POST, 1 );
-                       // TODO we can put VERIFIED in config and generalize 
this
+                       $request = new OutboundRequest( $url, 'POST' );
 
-                       // Always capture the cURL output
-                       $curlDebugLog = fopen( 'php://temp', 'r+' );
-                       curl_setopt( $ch, CURLOPT_VERBOSE, true );
-                       curl_setopt( $ch, CURLOPT_STDERR, $curlDebugLog );
+                       try {
+                               $response = $request->execute( $post_fields );
 
-                       $response = $this->curl( $ch, $post_fields );
-
-                       // Read the logging output
-                       rewind( $curlDebugLog );
-                       $logged = fread( $curlDebugLog, 8192 );
-                       fclose( $curlDebugLog );
-                       Logger::debug( "cURL verbose logging: $logged" );
-
-                       if ( $response === 'VERIFIED' ) {
-                               return true;
-                       } elseif ( $response === 'INVALID' ) {
-                               return false;
+                               if ( $response['body'] === 'VERIFIED' ) {
+                                       return true;
+                               } elseif ( $response['body'] === 'INVALID' ) {
+                                       return false;
+                               }
+                               // Must be an HTML page, keep trying.
+                       } catch( HttpRuntimeException $ex ) {
+                               Logger::debug( "Validation POST trouble on 
attempt $i" );
                        }
-                       // Must be an HTML page, keep trying.
                }
 
                throw new RuntimeException( 'Failed to validate message after ' 
.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6cc8c5ba38c8802805984516eee71f842d70714a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to