Ejemplo n.º 1
0
    def wallet_add_money_txn_2(self, **post):
        print("QUANTITY 2")
        print(post)



        user = request.env.user
        partner = user.partner_id
        PT = request.env['payment.transaction'].sudo()
        PM = request.env['payment.token'].sudo()


        tx = PT.search([
            ('is_wallet_transaction', '=', True), ('wallet_type', '=', 'credit'),
            ('partner_id', '=', partner.id), ('state', '=', 'draft')], limit=1)



        # create an instance of the API class
        api_instance = swagger_client.PayInsRedsysApi()
        marketpayid = tx.marketpay_txnid


        try:
            # View a Redsys payment
            api_response = api_instance.pay_ins_redsys_redsys_get_payment(marketpayid)
            print(api_response)

            print(api_response.execution_date)

        except ApiException as e:
            print("Exception when calling PayInsRedsysApi->pay_ins_redsys_redsys_get_payment: %s\n" % e)

        #return request.redirect("/wallet/add/money")

        if api_response.status == "FAILED":
            error = 'Received unrecognized RESULT for PayFlow Pro ' \
                    'payment %s: %s, set as error' % (tx.reference, api_response.result_message)
            _logger.info(error)
            tx.state = 'error'
            tx.state_message = error

        if api_response.status == "SUCCEEDED":
            _logger.info('%s Marketpay payment for tx %s: set as done' %
                         (tx.reference, api_response.result_message))

            tx.state = 'done'
            tx.date = datetime.now()

        #tx.s2s_feedback(data, 'payflow_pro')

        vals = {
                'tx_state': tx.state.capitalize(),
                'tx_amount': tx.amount,
                'tx_acquirer': tx.acquirer_id,
                'tx_reference': tx.acquirer_reference,
                'tx_time': tx.date,
                'wallet_bal': request.env.user.partner_id.wallet_balance,
        }
        return request.render("website_wallet.add_money_success", vals)
Ejemplo n.º 2
0
    def _redsys_form_validate(self, data):

        #Tomamos la id de paymenttransaction

        pedido = data['order']
        reference = pedido.transaction_ids[0].reference
        tx = self.search([('reference', '=', reference)])

        # create an instance of the API class
        api_instance = swagger_client.PayInsRedsysApi()
        pay_in_id = tx.redsys_txnid  # int | The Id of a payment
        print(pay_in_id)

        try:
            # View a Redsys payment
            api_response = api_instance.pay_ins_redsys_redsys_get_payment(
                pay_in_id)
            print(api_response)
        except ApiException as e:
            print(
                "Exception when calling PayInsRedsysApi->pay_ins_redsys_redsys_get_payment: %s\n"
                % e)

        print("vamos!!")
        print(api_response.status)

        #parameters_dic = self.merchant_params_json2dict(data)
        #status_code = int(parameters_dic.get('Ds_Response', '29999'))
        if api_response.status == "SUCCEEDED":
            print("dentro del if")
            self.write({
                'state': 'done',
                #'redsys_txnid': parameters_dic.get('Ds_AuthorisationCode'),
                'state_message': 'Ok',
            })
            #if self.acquirer_id.send_quotation:
            #    self.sale_order_ids.force_quotation_send()
            print("escrito el estado del pedido")
            return True

        if api_response.status == "FAILED":
            # 'Payment error: bank unavailable.'
            self.write({
                'state': 'cancel',
                #'redsys_txnid': parameters_dic.get('Ds_AuthorisationCode'),
                'state_message': 'Bank Error'
            })
            return False
Ejemplo n.º 3
0
    def redsys_form_generate_values(self, values):
        self.ensure_one()
        marketpay_values = dict(values)

        base_url = self._get_website_url()
        callback_url = self._get_website_callback_url()

        ## valores de marketpay para el usuario que hace la Operación ###
        marketpaydata = values['partner']

        # Configuración CLiente
        encoded = self.x_marketpay_key + ":" + self.x_marketpay_secret

        token_url = 'https://api-sandbox.marketpay.io/v2.01/oauth/token'

        key = 'Basic %s' % base64.b64encode(
            encoded.encode('ascii')).decode('ascii')
        data = {'grant_type': 'client_credentials'}
        headers = {
            'Authorization': key,
            'Content-Type': 'application/x-www-form-urlencoded'
        }

        r = requests.post(token_url, data=data, headers=headers)

        rs = r.content.decode()
        response = json.loads(rs)
        token = response['access_token']

        # Configuración default de Swagger
        config = swagger_client.Configuration()
        config.host = self.x_marketpay_domain
        config.access_token = token
        client = swagger_client.ApiClient(configuration=config)
        api_instance = swagger_client.Configuration.set_default(config)

        ############ trae los valores del partner ############

        # merchant_parameters = self._prepare_merchant_parameters(values)

        # walletid = marketpaydata.x_marketpaywallet_id
        # userid = marketpaydata.x_marketpayuser_id

        walletid = "9347379"
        userid = "9347382"

        currency = "EUR"
        amount = str(int(round(values['amount'] * 100)))
        #amount = 1000
        amountfee = self.x_marketpay_fee

        #success_url = '%s/payment/redsys/result/redsys_result_ok' % base_url
        #success_url = ('%s/payment/redsys/return' % (callback_url or base_url))[:250]
        success_url = '%s/wallet/add/money/transaction' % base_url
        cancel_url = '%s/payment/redsys/result/redsys_result_ko' % base_url

        apiPayin = swagger_client.PayInsRedsysApi()

        fees = swagger_client.Money(amount=amountfee, currency=currency)
        debited = swagger_client.Money(amount=amount, currency=currency)
        redsys_pay = swagger_client.RedsysPayByWebPost(
            credited_wallet_id=walletid,
            debited_funds=debited,
            fees=fees,
            success_url=success_url,
            cancel_url=cancel_url)
        #x_webhook = ('%s/payment/redsys/return' % (callback_url or base_url))[:250]
        #print(x_webhook)
        try:

            api_response = apiPayin.pay_ins_redsys_redsys_post_payment_by_web(
                redsys_pay_in=redsys_pay)

        except ApiException as e:
            print("Exception when calling UsersApi->users_post: %s\n" % e)

        pay_in_id = api_response.pay_in_id

        print(api_response)

        PT = request.env['payment.transaction'].sudo()
        tx = PT.search([('is_wallet_transaction', '=', True),
                        ('wallet_type', '=', 'credit'),
                        ('partner_id', '=', marketpaydata.id),
                        ('state', '=', 'draft')],
                       limit=1)

        tx.marketpay_txnid = pay_in_id

        print(tx)

        marketpay_values.update({
            'Ds_MerchantParameters': api_response.ds_merchant_parameters,
            'Ds_SignatureVersion': api_response.ds_signature_version,
            'Ds_Signature': api_response.ds_signature,
        })

        return marketpay_values