Commit 332d59d8 authored by Florian Duguet's avatar Florian Duguet Committed by ntome

[orange] update bill page for par website

Closes: 34908@sibi
parent dad4eb6d
......@@ -25,7 +25,7 @@ from weboob.browser import LoginBrowser, URL, need_login
from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, ActionNeeded
from .pages import LoginPage, BillsPage
from .pages.login import ManageCGI, HomePage
from .pages.bills import SubscriptionsPage, BillsApiPage, ContractsPage
from .pages.bills import SubscriptionsPage, BillsApiProPage, BillsApiParPage, ContractsPage
from .pages.profile import ProfilePage
from weboob.browser.exceptions import ClientError, ServerError
from weboob.tools.compat import basestring
......@@ -47,6 +47,7 @@ class OrangeBillBrowser(LoginBrowser):
subscriptions = URL(r'https://espaceclientv3.orange.fr/js/necfe.php\?zonetype=bandeau&idPage=gt-home-page', SubscriptionsPage)
manage_cgi = URL('https://eui.orange.fr/manage_eui/bin/manage.cgi', ManageCGI)
# is billspage deprecated ?
billspage = URL('https://m.espaceclientv3.orange.fr/\?page=factures-archives',
'https://.*.espaceclientv3.orange.fr/\?page=factures-archives',
'https://espaceclientv3.orange.fr/\?page=factures-archives',
......@@ -56,10 +57,13 @@ class OrangeBillBrowser(LoginBrowser):
'https://espaceclientv3.orange.fr/\?page=factures-historique&idContrat=(?P<subid>.*)',
BillsPage)
bills_api = URL('https://espaceclientpro.orange.fr/api/contract/(?P<subid>\d+)/bills\?count=(?P<count>)',
BillsApiPage)
bills_api_pro = URL('https://espaceclientpro.orange.fr/api/contract/(?P<subid>\d+)/bills\?count=(?P<count>)',
BillsApiProPage)
doc_api = URL('https://espaceclientpro.orange.fr/api/contract/(?P<subid>\d+)/bill/(?P<dir>.*)/(?P<fact_type>.*)/\?(?P<billparams>)')
bills_api_par = URL(r'https://sso-f.orange.fr/omoi_erb/facture/v2.0/billsAndPaymentInfos/users/current/contracts/(?P<subid>\d+)', BillsApiParPage)
doc_api_par = URL(r'https://sso-f.orange.fr/omoi_erb/facture/v1.0/pdf')
doc_api_pro = URL('https://espaceclientpro.orange.fr/api/contract/(?P<subid>\d+)/bill/(?P<dir>.*)/(?P<fact_type>.*)/\?(?P<billparams>)')
profile = URL('/\?page=profil-infosPerso', ProfilePage)
def do_login(self):
......@@ -132,12 +136,13 @@ class OrangeBillBrowser(LoginBrowser):
def iter_documents(self, subscription):
documents = []
if subscription._is_pro:
for d in self.bills_api.go(subid=subscription.id, count=72).get_bills(subid=subscription.id):
for d in self.bills_api_pro.go(subid=subscription.id, count=72).get_bills(subid=subscription.id):
documents.append(d)
# check pagination for this subscription
assert len(documents) != 72
else:
self.billspage.go(subid=subscription.id)
headers = {'x-orange-caller-id': 'ECQ'}
self.bills_api_par.go(subid=subscription.id, headers=headers)
for b in self.page.get_bills(subid=subscription.id):
documents.append(b)
return iter(documents)
......
......@@ -72,6 +72,10 @@ class OrangeModule(Module, CapAccount, CapDocument, CapProfile):
document = self.get_document(document)
if document.url is NotAvailable:
return
if document._is_v2:
# get 404 without this header
return self.browser.open(document.url, headers={'x-orange-caller-id': 'ECQ'}).content
return self.browser.open(document.url).content
def get_profile(self):
......
......@@ -28,7 +28,9 @@ except ImportError:
from weboob.browser.pages import HTMLPage, LoggedPage, JsonPage
from weboob.capabilities.bill import Subscription
from weboob.browser.elements import DictElement, ListElement, ItemElement, method, TableElement
from weboob.browser.filters.standard import CleanDecimal, CleanText, Env, Field, Regexp, Date, Currency, BrowserURL, Format
from weboob.browser.filters.standard import (
CleanDecimal, CleanText, Env, Field, Regexp, Date, Currency, BrowserURL, Format, Eval
)
from weboob.browser.filters.html import Link, TableCell
from weboob.browser.filters.javascript import JSValue
from weboob.browser.filters.json import Dict
......@@ -38,7 +40,7 @@ from weboob.tools.date import parse_french_date
from weboob.tools.compat import urlencode
class BillsApiPage(LoggedPage, JsonPage):
class BillsApiProPage(LoggedPage, JsonPage):
@method
class get_bills(DictElement):
item_xpath = 'bills'
......@@ -64,9 +66,33 @@ class BillsApiPage(LoggedPage, JsonPage):
params = {'billid': Dict('id')(self), 'billDate': Dict('dueDate')(self)}
return urlencode(params)
obj_url = BrowserURL('doc_api', subid=Env('subid'), dir=Dict('documents/0/mainDir'), fact_type=Dict('documents/0/subDir'), billparams=get_params)
obj_url = BrowserURL('doc_api_pro', subid=Env('subid'), dir=Dict('documents/0/mainDir'), fact_type=Dict('documents/0/subDir'), billparams=get_params)
obj__is_v2 = False
class BillsApiParPage(LoggedPage, JsonPage):
@method
class get_bills(DictElement):
item_xpath = 'billsHistory/billList'
class item(ItemElement):
klass = Bill
obj_date = Date(Dict('date'), default=NotAvailable)
obj_price = Eval(lambda x: x / 100, CleanDecimal(Dict('amount')))
obj_format = 'pdf'
def obj_label(self):
return 'Facture du %s' % Field('date')(self)
def obj_id(self):
return '%s_%s' % (Env('subid')(self), Field('date')(self).strftime('%d%m%Y'))
obj_url = Format('%s%s', BrowserURL('doc_api_par'), Dict('hrefPdf'))
obj__is_v2 = True
# is BillsPage deprecated ?
class BillsPage(LoggedPage, HTMLPage):
@method
class get_bills(TableElement):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment