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

Change subject: Script to update d*Local payment submethods
......................................................................

Script to update d*Local payment submethods

Get the lists via the GetBankList API.
However, the results differ from what is on developers.astropay.com,
and both of these differ from the lists on the marketing materials.

Bug: T167378
Change-Id: I88a67a1c492e40dc7f88433d2bfdb14477a798c9
---
A astropay_gateway/scripts/submethods.php
1 file changed, 97 insertions(+), 0 deletions(-)


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

diff --git a/astropay_gateway/scripts/submethods.php 
b/astropay_gateway/scripts/submethods.php
new file mode 100644
index 0000000..03b1367
--- /dev/null
+++ b/astropay_gateway/scripts/submethods.php
@@ -0,0 +1,97 @@
+<?php
+use SmashPig\PaymentProviders\AstroPay\ReferenceData;
+use Symfony\Component\Yaml\Yaml;
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+       $IP = __DIR__ . '/../../../..';
+}
+
+// If you get errors on this next line, set (and export) your MW_INSTALL_PATH 
var.
+require_once( "$IP/maintenance/Maintenance.php" );
+
+// Updates our list of payment submethods
+class AstroPaySubmethodsQuery extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+       }
+
+       public function execute() {
+               $countries = array(
+                       'AR',
+                       'BR',
+                       'CL',
+                       'CO',
+                       'MX',
+                       'PE',
+                       'UY'
+               );
+               $submethods = array();
+               $rates = CurrencyRates::getCurrencyRates();
+               $types = array(
+                       '00' => 'rtbt',
+                       '01' => 'bt',
+                       '02' => 'cash',
+                       '03' => 'cc',
+                       '04' => 'cc'
+               );
+               $old_submethods = null;
+               foreach ( $countries as $country ) {
+                       $currency = NationalCurrencies::getNationalCurrency( 
$country );
+                       $amount = 2 * $rates[$currency];
+                       $gateway_opts = array(
+                               'batch_mode' => true,
+                               'external_data' => array(
+                                       'order_id' => $this->getArg( 'id' ),
+                                       'contribution_tracking_id' => 0, // 
ut-oh
+                                       // Dummy data to satisfy validation :P
+                                       'payment_method' => 'cc',
+                                       'amount' => $amount,
+                                       'country' => $country,
+                                       'currency' => $currency,
+                                       'email' => 'du...@example.org',
+                               ),
+                       );
+                       $this->output( "Looking up submethods for $country\n" );
+                       $adapter = new AstroPayAdapter( $gateway_opts );
+                       if ( $old_submethods === NULL ) {
+                               $old_submethods = $adapter->getConfig( 
'payment_submethods' );
+                       }
+                       $result = $adapter->do_transaction( 'GetBanks' );
+                       $data = $result->getData();
+                       $this->output( print_r( $data, true ) );
+                       foreach ( $data as $entry ) {
+                               $code = $entry['code'];
+                               $name = $entry['name'];
+                               $logo = $entry['logo'];
+                               $type = $entry['payment_type'];
+                               $our_type = $types[$type];
+                               $our_code = 
ReferenceData::decodePaymentSubmethod( $our_type, $code );
+                               if ( array_key_exists( $our_code, $submethods ) 
) {
+                                       
$submethods[$our_code]['countries'][$country] = true;
+                               } else {
+                                       if ( array_key_exists( $our_code, 
$old_submethods ) ) {
+                                               // We've already got a logo and 
maybe a translated label
+                                               // only override the country 
list
+                                               $submethods[$our_code] = 
$old_submethods[$our_code];
+                                       } else {
+                                               $submethods[$our_code] = array(
+                                                       'bank_code' => $code,
+                                                       'label' => $name,
+                                                       'logo' => $logo,
+                                                       'group' => 
$types[$type],
+                                               );
+                                       }
+                                       $submethods[$our_code]['countries'] = 
array(
+                                               $country => true
+                                       );
+                               }
+                       }
+               }
+               $yaml = Yaml::dump( $submethods );
+               $this->output( $yaml );
+       }
+}
+
+$maintClass = 'AstroPaySubmethodsQuery';
+require_once RUN_MAINTENANCE_IF_MAIN;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I88a67a1c492e40dc7f88433d2bfdb14477a798c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

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

Reply via email to