Skip to Content
Menu
This question has been flagged

I created my Payment Provider (and Payment method) based on Payment Demo.


But in screen choose payment method (/shop/payment), When choose my payment method, it's show a field image, and I want to check: If field image is null, return a ErrorDialog .


- Field image has value: Enable button Pay -> Payment successful

- Field image null: Disable button Pay  (Or show ErrorDialog for user upload image) -> When user upload image -> Payment Successful



Please help me ~~~`

Avatar
Discard
Author Best Answer
/** @odoo-module **/

import { _t } from '@web/core/l10n/translation'
import { jsonrpc, RPCError } from '@web/core/network/rpc_service'

const getBase64 = (file) =>
  new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    reader.onload = () => resolve(reader.result)
    reader.onerror = (error) => reject(error)
  })

export default {
  /**
   * Simulate a feedback from a payment provider and redirect the customer to the status page.
   *
   * @private
   * @param {object} processingValues - The processing values of the transaction.
   * @return {void}
   */

  async processPMSolutionPayment(processingValues) {
    const customerInput = document.getElementById(
      'o_payment_pmsolution_shipping_payment_image'
    ).files[0]

    jsonrpc('/payment/pmsolution/simulate_payment', {
      reference: processingValues.reference,
      sale_order_ids: processingValues.sale_order_id,
      payment_image: await getBase64(customerInput),
      simulated_state: 'pending',
    })
      .then(() => {
        window.location = '/payment/status'
      })
      .catch((error) => {
        if (error instanceof RPCError && this._displayErrorDialog) {
          this._displayErrorDialog(
            _t('Payment processing failed'),
            error.data.message
          )
          this._enableButton?.() // This method doesn't exists in Express Checkout form.
        } else {
          return Promise.reject(error)
        }
      })
  },
}



Please help me ~~~

Avatar
Discard
Related Posts Replies Views Activity
3
Feb 25
4850
1
Mar 24
2668
6
Jan 22
80605
4
Dec 19
19365
4
Oct 16
5374