Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/344454 )
Change subject: Update SmashPig lib ...................................................................... Update SmashPig lib Change-Id: I5c8ffb254fa143c52f760fcbafa64840bac45757 --- M composer/installed.json M wikimedia/smash-pig/Core/Http/OutboundRequest.php M wikimedia/smash-pig/PaymentProviders/Ingenico/BankPaymentProvider.php A wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/Data/availability.response M wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php M wikimedia/smash-pig/PaymentProviders/PayPal/Job.php M wikimedia/smash-pig/PaymentProviders/PayPal/PaymentMessage.php M wikimedia/smash-pig/PaymentProviders/PayPal/RecurringMessage.php M wikimedia/smash-pig/PaymentProviders/PayPal/RefundMessage.php A wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment.json A wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment_transformed.json M wikimedia/smash-pig/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php M wikimedia/smash-pig/SmashPig.yaml 13 files changed, 215 insertions(+), 14 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface/vendor refs/changes/54/344454/1 diff --git a/composer/installed.json b/composer/installed.json index 8e57f31..359c136 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -1014,7 +1014,7 @@ "source": { "type": "git", "url": "https://gerrit.wikimedia.org/r/wikimedia/fundraising/SmashPig.git", - "reference": "d1a135b94870ff263154c5dab084416eb318e05f" + "reference": "5abbd06ab629e218d7c1842443c0a0627c31d0c3" }, "require": { "amzn/login-and-pay-with-amazon-sdk-php": "dev-master", @@ -1031,7 +1031,7 @@ "jakub-onderka/php-parallel-lint": "^0.9", "phpunit/phpunit": "^4.8" }, - "time": "2017-03-20 17:58:32", + "time": "2017-03-23 17:11:20", "type": "library", "installation-source": "source", "autoload": { diff --git a/wikimedia/smash-pig/Core/Http/OutboundRequest.php b/wikimedia/smash-pig/Core/Http/OutboundRequest.php index 92e6cae..8eeb187 100644 --- a/wikimedia/smash-pig/Core/Http/OutboundRequest.php +++ b/wikimedia/smash-pig/Core/Http/OutboundRequest.php @@ -12,15 +12,18 @@ /** * @var array */ - protected $headers; + protected $headers = array(); + /** * @var Configuration */ protected $config; + /** * @var string HTTP method */ protected $method; + /** * @var string Request body */ diff --git a/wikimedia/smash-pig/PaymentProviders/Ingenico/BankPaymentProvider.php b/wikimedia/smash-pig/PaymentProviders/Ingenico/BankPaymentProvider.php index 87c034d..4844bbc 100644 --- a/wikimedia/smash-pig/PaymentProviders/Ingenico/BankPaymentProvider.php +++ b/wikimedia/smash-pig/PaymentProviders/Ingenico/BankPaymentProvider.php @@ -4,6 +4,7 @@ use SmashPig\Core\Context; use Psr\Cache\CacheItemPoolInterface; +use SmashPig\Core\Http\OutboundRequest; /** * Handle bank payments via Ingenico @@ -23,9 +24,15 @@ */ protected $cache; + /** + * @var array() + */ + protected $availabilityParameters; + public function __construct( array $options = array() ) { parent::__construct( $options ); $this->cacheParameters = $options['cache-parameters']; + $this->availabilityParameters = $options['availability-parameters']; // FIXME: provide objects in constructor $config = Context::get()->getConfiguration(); $this->cache = $config->object( 'cache' ); @@ -45,7 +52,7 @@ $cacheItem = $this->cache->getItem( $cacheKey ); if ( !$cacheItem->isHit() || $this->shouldBeExpired( $cacheItem ) ) { - $query = array( + /*$query = array( 'countryCode' => $country, 'currencyCode' => $currency ); @@ -56,7 +63,28 @@ foreach ( $response['entries'] as $entry ) { $banks[$entry['issuerId']] = $entry['issuerName']; + }*/ + + $banks = array(); + + // HAAACK! + // Use undocumented API to get availability straight from iDEAL, + // until Ingenico can incorporate this into their directory + if ( $country === 'NL' && $currency === 'EUR' ) { + $url = $this->availabilityParameters['url']; + $threshold = $this->availabilityParameters['threshold']; + + $request = new OutboundRequest( $url ); + $rawResponse = $request->execute(); + $response = json_decode( $rawResponse['body'], true ); + + foreach ( $response['Issuers'] as $issuer ) { + if ( $issuer['Percent'] >= $threshold ) { + $banks[$issuer['BankId']] = $issuer['BankName']; + } + } } + $duration = $this->cacheParameters['duration']; $cacheItem->set( array( 'value' => $banks, diff --git a/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/Data/availability.response b/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/Data/availability.response new file mode 100644 index 0000000..74f0def --- /dev/null +++ b/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/Data/availability.response @@ -0,0 +1,14 @@ +HTTP/1.1 200 OK +Cache-Control: no-cache +Pragma: no-cache +Content-Length: 656 +Content-Type: application/json; charset=utf-8 +Content-Encoding: gzip +Expires: -1 +Vary: Accept-Encoding +Server: Microsoft-IIS/8.0 +X-AspNet-Version: 4.0.30319 +X-Powered-By: ASP.NET +Date: Wed, 22 Mar 2017 22:42:05 GMT + +{"Issuers":[{"BankId":"ABNANL2A","BankName":"ABN AMRO","LogoPath":"/Content/icons/banks/abn.png","Status":"Green","Percent":"40","Details":"","MoreDetails":"","LogoStatus":"/Content/icons/green.png","URL":"/History?bank=ABN_AMRO"},{"BankId":"INGBNL2A","BankName":"Issuer Simulation V3 - ING","LogoPath":"/Content/icons/banks/sim.png","Status":"Green","Percent":"100","Details":"","MoreDetails":"","LogoStatus":"/Content/icons/green.png","URL":"/History?bank=Simulated_Bank"}],"Message":"","IssuerMessageCalculationFailed":false,"LastUpdate":"22-3-2017, 23:40","AllGreen":true} diff --git a/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php b/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php index d9a2e3e..18ef9e7 100644 --- a/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php +++ b/wikimedia/smash-pig/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php @@ -38,13 +38,18 @@ 'cache-parameters' => array( 'duration' => 10, 'key-base' => 'BLAH_BLAH' + ), + 'availability-parameters' => array( + 'url' => 'http://example.org/undocumented/api/GetIssuers', + 'threshold' => 60 ) ) ); parent::setUp(); } public function testGetBankList() { - $this->setUpResponse( 'productDirectory', 200 ); + //$this->setUpResponse( 'productDirectory', 200 ); + $this->setUpResponse( 'availability', 200 ); $results = $this->provider->getBankList( 'NL', 'EUR' ); $this->assertEquals( array( @@ -55,7 +60,8 @@ } public function testCacheBankList() { - $this->setUpResponse( 'productDirectory', 200 ); + //$this->setUpResponse( 'productDirectory', 200 ); + $this->setUpResponse( 'availability', 200 ); $this->curlWrapper->expects( $this->once() ) ->method( 'execute' ); $results = $this->provider->getBankList( 'NL', 'EUR' ); @@ -79,7 +85,8 @@ true ); $this->cache->save( $cacheItem ); - $this->setUpResponse( 'productDirectory', 200 ); + //$this->setUpResponse( 'productDirectory', 200 ); + $this->setUpResponse( 'availability', 200 ); $this->curlWrapper->expects( $this->once() ) ->method( 'execute' ); $results = $this->provider->getBankList( 'NL', 'EUR' ); diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/Job.php b/wikimedia/smash-pig/PaymentProviders/PayPal/Job.php index b76727f..6e8816f 100644 --- a/wikimedia/smash-pig/PaymentProviders/PayPal/Job.php +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/Job.php @@ -69,11 +69,6 @@ $creator = array( $msgClass, 'fromIpnMessage' ); $normalized = call_user_func( $creator, $request ); - if ( $txn_type == 'express_checkout' ) { - $normalized['gateway'] = 'paypal_ec'; - } else { - $normalized['gateway'] = 'paypal'; - } SourceFields::addToMessage( $normalized ); // Save to appropriate queue. diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/PaymentMessage.php b/wikimedia/smash-pig/PaymentProviders/PayPal/PaymentMessage.php index ce6ab7b..f0416a8 100644 --- a/wikimedia/smash-pig/PaymentProviders/PayPal/PaymentMessage.php +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/PaymentMessage.php @@ -5,6 +5,13 @@ class PaymentMessage extends Message { public static function normalizeMessage( &$message, $ipnMessage ) { + if ( $ipnMessage['txn_type'] === 'express_checkout' ) { + $message['gateway'] = 'paypal_ec'; + } else { + $message['gateway'] = 'paypal'; + } + // TODO: Implement normalizeMessage() method. + } } diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/RecurringMessage.php b/wikimedia/smash-pig/PaymentProviders/PayPal/RecurringMessage.php index d19c778..b80458b 100644 --- a/wikimedia/smash-pig/PaymentProviders/PayPal/RecurringMessage.php +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/RecurringMessage.php @@ -5,6 +5,75 @@ class RecurringMessage extends Message { public static function normalizeMessage( &$message, $ipnMessage ) { - // TODO: Implement normalizeMessage() method. + $message['recurring'] = "1"; + + // Contact info + if ( $ipnMessage['txn_type'] === 'recurring_payment_profile_created' || $ipnMessage['txn_type'] === 'recurring_payment' ) { + + + $message['middle_name'] = ''; + + if ( isset( $ipnMessage['address_street'] ) ) { + $split = explode("\n", str_replace("\r", '', $ipnMessage['address_street'])); + $message['street_address'] = $split[0]; + if ( count( $split ) > 1 ) { + $message['supplemental_address_1'] = $split[1]; + } + + } + } + + switch ( $ipnMessage['txn_type'] ) { + + case 'recurring_payment': + $message['txn_type'] = 'subscr_payment'; + break; + + case 'recurring_payment_profile_created': + $message['txn_type'] = 'subscr_signup'; + // break the period out for civicrm + if( $ipnMessage['payment_cycle'] == 'Monthly' ) { + + $message['frequency_interval'] = '1'; + $message['frequency_unit'] = 'month'; + } + + $message['installments'] = 0; + + if ( isset( $ipnMessage['time_created'] ) ) { + if ( $ipnMessage['txn_type'] == 'recurring_payment_profile_created' ) { + $message['create_date'] = strtotime( $ipnMessage['time_created'] ); + $message['start_date'] = strtotime( $ipnMessage['time_created'] ); + } + if ( !isset( $message['date'] ) ) { + $message['date'] = strtotime( $ipnMessage['time_created'] ); + } + } + break; + + case 'recurring_payment_profile_cancel': + $message['txn_type'] = 'subscr_cancel'; + $message['cancel_date'] = time(); + break; + + + case 'recurring_payment_failed': + case 'recurring_payment_skipped': + case 'recurring_payment_suspended': + $message['txn_type'] = 'subscr_failed'; + break; + + case 'recurring_payment_expired': + $message['txn_type'] = 'subscr_eot'; + break; + + } + + $message['gateway'] = 'paypal_ec'; + + if ( !isset( $message['date'] ) ) { + $message['date'] = time(); + } + } } diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/RefundMessage.php b/wikimedia/smash-pig/PaymentProviders/PayPal/RefundMessage.php index 4342b62..cbac123 100644 --- a/wikimedia/smash-pig/PaymentProviders/PayPal/RefundMessage.php +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/RefundMessage.php @@ -13,5 +13,6 @@ } else { $message['type'] = 'refund'; } + $message['gateway'] = 'paypal'; } } diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment.json b/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment.json new file mode 100644 index 0000000..342e7c1 --- /dev/null +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment.json @@ -0,0 +1,44 @@ +{ + "business": "nob...@wikimedia.org", + "receiver_email": "nob...@wikimedia.org", + "receiver_id": "1234567", + "payment_status": "Completed", + "payment_type ": "instant", + "payment_date": "16:03:13 Sep 21, 2016 PDT", + "txn_id": "0987654321", + "initial_payment_txn_id": "123456", + "mc_gross": "1.50", + "mc_fee": "0.10", + "mc_currency": "USD", + "payment_gross": "1.50", + "currency_code": "USD", + "payment_fee ": "0.10", + "first_name": "Testy", + "last_name": "McTesterson", + "address_name": "Testy McTesterson", + "address_street": "123 Fake St.", + "address_city": "Fakesville", + "address_state": "CA", + "address_zip": "92777", + "address_country": "United States", + "payer_email": "bl...@urgrar.com", + "payer_id": "XXXXXXXXXX", + "payer_status": "verified", + "residence_country": "US", + "address_country_code": "US", + "address_status": "confirmed", + "recurring_payment_id": "12345678", + "rp_invoice_id": "7373", + "product_name": "Donation to the Wikimedia Foundation", + "product_type": "Donation", + "period_type": "Regular", + "payment_cycle": "Monthly", + "outstanding_balance": "0", + "amount_per_cycle": "1.50", + "initial_payment_amount": "0", + "profile_status": "Active", + "amount": "1.50", + "time_created": "10:00:11 Mar 02, 2017 PST", + "next_payment_date": "03:00:00 Apr 01, 2017 PDT", + "txn_type": "recurring_payment" +} \ No newline at end of file diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment_transformed.json b/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment_transformed.json new file mode 100644 index 0000000..5a70b21 --- /dev/null +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/Data/recurring_payment_transformed.json @@ -0,0 +1,25 @@ +{ + "date": 1474498993, + "subscr_id": "12345678", + "txn_type": "subscr_payment", + "contribution_tracking_id": "7373", + "order_id": "7373", + "email": "bl...@urgrar.com", + "first_name": "Testy", + "middle_name": "", + "last_name": "McTesterson", + "street_address": "123 Fake St.", + "city": "Fakesville", + "state_province": "CA", + "country": "US", + "postal_code": "92777", + "gateway_txn_id": "0987654321", + "currency": "USD", + "gross": "1.50", + "fee": "0.10", + "gateway": "paypal_ec", + "recurring": "1", + "source_name": "SmashPig", + "source_type": "listener", + "source_version": "unknown" +} \ No newline at end of file diff --git a/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php b/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php index ce1655b..1a64a11 100644 --- a/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php +++ b/wikimedia/smash-pig/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php @@ -29,6 +29,7 @@ 'express_checkout.json' => 'donations', 'subscr_signup.json' => 'recurring', 'subscr_payment.json' => 'recurring', + 'recurring_payment.json' => 'recurring', 'refund.json' => 'refund-new', 'chargeback_settlement.json' => 'refund-new', // this should not actually get written to diff --git a/wikimedia/smash-pig/SmashPig.yaml b/wikimedia/smash-pig/SmashPig.yaml index 520c901..e68beb3 100644 --- a/wikimedia/smash-pig/SmashPig.yaml +++ b/wikimedia/smash-pig/SmashPig.yaml @@ -359,6 +359,7 @@ txn_type: txn_type parent_txn_id: gateway_parent_id txn_id: gateway_txn_id + recurring_payment_id: subscr_id # FIXME This is only true for refund messages. Where to represent? #txn_id: gateway_refund_id mc_currency: currency @@ -366,6 +367,7 @@ reason_code: type #test_ipn: # signals test mode custom: contribution_tracking_id + rp_invoice_id: contribution_tracking_id payer_email: email first_name: first_name last_name: last_name @@ -375,6 +377,7 @@ address_state: state_province address_country_code: country address_zip: postal_code + redidence_country: country # FIXME this too address_name: supplemental_address_1 gateway: gateway @@ -462,8 +465,12 @@ constructor-parameters: - cache-parameters: - duration: 300 + duration: 900 key-base: SMASHPIG_INGENICO_IDEAL_BANK_LIST + availability-parameters: + url: http://availability.ideal.nl/api/api/GetIssuers + # percentage availability below which issuers are omitted + threshold: 50 # deprecated, delete when projects using SmashPig rename adaptors globalcollect: -- To view, visit https://gerrit.wikimedia.org/r/344454 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c8ffb254fa143c52f760fcbafa64840bac45757 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface/vendor 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