Make a Payment Value Using Unique Code

Discussion in 'Free Talk for Website Owners and Webmasters' started by masdika, Dec 8, 2016.

  1. masdika

    masdika --

    Joined:
    Oct 6, 2013
    Messages:
    18
    Hello, all, I want to add a unique code on the payment of transaction value, how?



    Thanks

    Attached Files:

  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,686
    @masdika Do you mean you want to add some unique fraction to price for each invoice?

    You can use the following code in site.php file
    http://www.amember.com/docs/Site.php_file

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_PAYMENT_SIGNUP, function(Am_Event $e) {
       
    $invoice $e->getInvoice();
       
    $item $invoice->getItem(0);
       
    $item->data()->set('orig_first_price'$item->data()->get('orig_first_price') + ($invoice->pk() % 100));
       
    $invoice->calculate();
       
    $invoice->save();
    });
    bikinwebsitemudah likes this.
  3. bikinwebsitemudah

    bikinwebsitemudah New Member

    Joined:
    Jan 18, 2016
    Messages:
    7
    Ok, thank's... it work... but how to edit email sending to client.
    because invoice on email still fix rate... not use unique .
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,686
  5. bikinwebsitemudah

    bikinwebsitemudah New Member

    Joined:
    Jan 18, 2016
    Messages:
    7
    @caesar ok, i will write in support :)
  6. aditya99

    aditya99 aMember Pro Customer

    Joined:
    Sep 9, 2016
    Messages:
    2
  7. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    1,686
    Here is code that will work better for such case:

    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_CALCULATE, function(Am_Event $e) {
       if (@
    $GLOBALS['add_fraction']++) return;
       
    $invoice $e->getInvoice();
       
    $item $invoice->getItem(0);
       
    $id $invoice->pk() ?: $e->getDi()->db->selectCell("SELECT MAX(invoice_id)+1 FROM ?_invoice;");
       if (
    $item && !$item->data()->get('add_fraction')) {
           
    $item->data()->set('add_fraction'1);
           
    $item->data()->set('orig_first_price'$item->data()->get('orig_first_price') + ($id 100));
           
    $invoice->calculate();
       }
       unset(
    $GLOBALS['add_fraction']);
    });

Share This Page