Skip to content

Commit

Permalink
Открытие Travel (ab-bonus-open-travel):
Browse files Browse the repository at this point in the history
- Первая версия провайдера.
  • Loading branch information
dukei committed May 2, 2020
1 parent e260aaf commit d0bf268
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
28 changes: 28 additions & 0 deletions providers/ab-bonus-open-travel/anybalance-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<provider>
<id version="1">ab-bonus-open-travel</id>
<api flags="no_browser"/>
<name>Открытие Travel</name>
<description html="true"><![CDATA[
<p>Предоставляет информацию о бонусном балансе на карте Travel банка Открытие (https://travel.open.ru/).</p>
]]></description>
<author>AnyBalance Team &lt;info@anybalance.ru&gt;</author>
<depends>
<module id="library"/>
</depends>
<files>
<icon>icon.png</icon>
<preferences>preferences.xml</preferences>
<js>main.js</js>
<history>history.xml</history>
</files>
<counters>
<counter id="balance" name="Баланс" units=" р"/>
<counter id="last_op_sum" name="Сумма последней операции" units=" р"/>
<counter id="last_op_date" name="Дата последней операции" type="time" format="dd/MM/yyyy"/>
<counter id="last_op_type" name="Тип последней операции" type="text"/>
</counters>
<keywords>пятерочка, накопительная программа, накопительная карта, бонус, бонусная карта, продукты, покупки, баллы</keywords>
<type>bonus</type>
<country>ru</country>
</provider>
9 changes: 9 additions & 0 deletions providers/ab-bonus-open-travel/history.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<history>
<change version="1" date="2020-05-02">
- Первая версия провайдера.
</change>
<change version="1" date="2017-08-02">
Первая версия провайдера
</change>
</history>
Binary file added providers/ab-bonus-open-travel/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions providers/ab-bonus-open-travel/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
Провайдер AnyBalance (http://any-balance-providers.googlecode.com)
Получает информацию о бонусах на карте Клуба Перекресток.
Сайт магазина: http://www.perekrestok.ru/
Личный кабинет: https://prcab.x5club.ru/cwa/
*/

var g_headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'ru,en-US;q=0.8,en;q=0.6',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
Origin: "https://travel.open.ru"
};

var baseurl = "https://travel.open.ru/"
var domain = getParam(baseurl, /\/\/(.*?)\//);
var apiHeaders = {
Referer: baseurl
};


function callApi(verb, postParams){
var method = 'GET';
var h = apiHeaders;
if(isset(postParams)){
method = 'POST';
}

var html = AnyBalance.requestPost(baseurl + '_api/' + verb, postParams, addHeaders(h), {HTTP_METHOD: method});

var json = getJson(html);
if(json.error){
AnyBalance.trace(html);
throw new AnyBalance.Error("Неправильный логин или пароль", null, /WRONG_STATE/i.test(json.error.code));
}

return json;
}

function main () {
var prefs = AnyBalance.getPreferences ();
AnyBalance.setDefaultCharset('utf-8');

checkEmpty(prefs.login, 'Введите 10 цифр номера бонусного счета (снизу на лицевой стороне карты Travel).');
checkEmpty(/^\d{10}$/.test(prefs.login), 'Введите 10 цифр номера бонусного счета без пробелов и разделителей.');
checkEmpty(prefs.password, 'Введите пароль.');

AnyBalance.trace('Входим в кабинет ' + baseurl);

var json = callApi('mt/authenticate', {
id: prefs.login,
password: prefs.password,
source: 'openbank'
});

var result = {success: true};

json = callApi('buyermanager/getUserInfo/?' + createUrlEncodedParams({
_: +new Date(),
allPaxLocales: 'true',
source: 'openbank'
}));

getParam(json.bonuses.bankTotals.openbank.amount, result, 'balance');
getParam(Object.keys(json.bonuses.bankTotals.openbank.cuids).join(', '), result, '__tariff');

if(json.bonuses.movements && json.bonuses.movements.length){
var m = json.bonuses.movements[json.bonuses.movements.length-1];
getParam(m.amount * (m.type === 'out' ? -1 : 1), result, 'last_op_sum');
getParam(m.dateCreated, result, 'last_op_date', null, null, parseDateISO);
getParam(m.type, result, 'last_op_type');
}

AnyBalance.setResult (result);
}
23 changes: 23 additions & 0 deletions providers/ab-bonus-open-travel/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen>
<EditTextPreference
key="login"
title="Номер карты"
summary="Номер карты для доступа к личному кабинету||{@s}\n"
inputType="number"
dialogTitle="Номер карты"
dialogMessage="Введите 10 цифр номера карты для входа в личный кабинет. Только цифры без пробелов и разделителей."
positiveButtonText="ОК"
negativeButtonText="Отмена">
</EditTextPreference>
<EditTextPreference
key="password"
title="Пароль"
summary="Пароль для входа в личный кабинет||**********\n"
inputType="textPassword"
dialogTitle="Пароль"
dialogMessage="Введите пароль, используемый для входа в личный кабинет"
positiveButtonText="ОК"
negativeButtonText="Отмена">
</EditTextPreference>
</PreferenceScreen>

0 comments on commit d0bf268

Please sign in to comment.