Skip to content

Commit

Permalink
[FIX] Correção na integração com cielo checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Jan 2, 2019
1 parent a6db857 commit 19315b7
Showing 1 changed file with 29 additions and 45 deletions.
74 changes: 29 additions & 45 deletions br_payment_cielo/models/cielo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,62 +29,46 @@ def _default_return_url(self):
default=_default_return_url, size=300)

@api.multi
def cielo_form_generate_values(self, values):
def cielo_form_generate_values(self, tx_values):
""" Função para gerar HTML POST da Cielo """
order = odoo_request.website.sale_get_order()
if not order or not order.payment_tx_id:
return {
'checkout_url': '/shop/payment',
}

total_desconto = 0
items = []
for line in order.order_line:
if line.product_id.fiscal_type == 'service':
tipo = 'Service'
elif line.product_id.fiscal_type == 'product':
tipo = 'Asset'
else:
tipo = 'Payment'
total_desconto += line.discount
item = {
"Name": line.product_id.name,
"Description": line.name,
"UnitPrice": "%d" % round(line.price_unit * 100),
"Quantity": "%d" % line.product_uom_qty,
"Type": tipo,
}
if line.product_id.default_code:
item["Sku"] = line.product_id.default_code
if line.product_id.weight:
item['Weight'] = "%d" % (line.product_id.weight * 1000)
items.append(item)
shipping = {
"Type": "WithoutShipping",
"TargetZipCode": re.sub('[^0-9]', '', order.partner_id.zip),
}
items = [{
"Name": "Pagamento pedido: %s" % tx_values['reference'],
"Description": "Pagamento pedido: %s" % tx_values['reference'],
"UnitPrice": "%d" % round(tx_values['amount'] * 100),
"Quantity": '1',
"Type": 'Service',
}]
address = {
"Street": order.partner_id.street,
"Number": order.partner_id.number,
"Complement": order.partner_id.street2,
"District": order.partner_id.district,
"City": order.partner_id.city_id.name,
"State": order.partner_id.state_id.code,
"Street": tx_values['partner'].street,
"Number": tx_values['partner'].number,
"Complement": tx_values['partner'].street2,
"District": tx_values['partner'].district,
"City": tx_values['partner'].city_id.name,
"State": tx_values['partner'].state_id.code,
}
if len(order.partner_id.street2) > 0:
address['Complement'] = order.partner_id.street2
if len(tx_values['partner'].street2 or '') > 0:
address['Complement'] = tx_values['partner'].street2
payment = {"BoletoDiscount": 0, "DebitDiscount": 0}
customer = {
"Identity": re.sub('[^0-9]', '', order.partner_id.cnpj_cpf or ''),
"FullName": order.partner_id.name,
"Email": order.partner_id.email,
"Phone": re.sub('[^0-9]', '', order.partner_id.phone or ''),
"Identity": re.sub(
'[^0-9]', '', tx_values['partner'].cnpj_cpf or ''),
"FullName": tx_values['partner'].name,
"Email": tx_values['partner'].email,
"Phone": re.sub('[^0-9]', '',
tx_values['partner'].phone or '')[:11],
}
shipping = {
"Type": "WithoutShipping",
"TargetZipCode": re.sub(
'[^0-9]', '', tx_values['partner'].zip or ''),
"Address": address,
}
total_desconto *= 100
discount = {'Type': 'Amount', 'Value': int(total_desconto)}
options = {"AntifraudEnabled": False, "ReturnUrl": self.return_url}
order_json = {
"OrderNumber": values['reference'],
"OrderNumber": tx_values['reference'],
"SoftDescriptor": "FOOBARBAZ",
"Cart": {
"Discount": discount,
Expand Down

0 comments on commit 19315b7

Please sign in to comment.