no Invoice# passed

Discussion in 'aMember Pro v.4' started by xindexer, May 27, 2012.

  1. xindexer

    xindexer Member

    Joined:
    Apr 17, 2011
    Messages:
    52
    I'm trying to allow my users to purchase a product directly from my dashboard and avoid going through the amember shopping cart. I have Paypal buttons set up and have placed the code into the "PayPal Button Item Number" for each product.

    When the user selects the option to purchase a product, I am creating an invoice in the system using the following code:

    PHP:
    $invoice Am_Di::getInstance()->invoiceRecord;
    $invoice->setUser(Am_Di::getInstance()->userTable->load($user_id));
    $invoice->add(Am_Di::getInstance()->productTable->load($product_id));
    $invoice->paysys_id "paypal";
    $invoice->calculate();
    $invoice->insert();
    I'm then sending them to paypal using this link:

    https://paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=(the button id)

    When the payment is complete, the system does not go to the thank you page and no payment is recorded...and I get this in the log - "Looks like an invalid IPN post - no Invoice# passed"

    I'm sure the problem is in the link that I'm using to send my users to Paypal. Is there a function that I can call to generate the proper link?
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    What exactly you set in PayPal Button Item Number inside product settings in aMember? Do you use the same value as in this url:
    https://paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=(the button id)
    If so this is incorrect. Above is paypal hosted button ID which is different value then Item number which you set when create button in paypal.
    Also have you enabled auto create in paypal plugin?
  3. xindexer

    xindexer Member

    Joined:
    Apr 17, 2011
    Messages:
    52
    When I create the button in Paypal it gives me this code:

    Code:
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="******MH5C852">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>
    
    I used the ******MH5C852and put that into the "PayPal Button Item Number" field for the respective product.

    I have it set up so that when the user clicks on the pay now button, I create the invoice and send them to this link:

    https://paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=******MH5C852


    This sends them to the correct page in paypal and allows them to make the payment which shows up in my account - but this does not send the correct data back to amember.

    I do not see an "auto create" feature in paypal plugin (I'm using V 4.1.14 and the "Paypal" plugin)

    After reading your post again and looking at the product page - you say this:

    "if you want to use PayPal buttons, create button with the same billing settings, and enter its item number here"

    There is no "Item Number" in paypal - there is a "Subscription ID" and I just tried to use that number instead of the *******MH5C852 and got the same results.

    Still need some help here

    Thanks
  4. xindexer

    xindexer Member

    Joined:
    Apr 17, 2011
    Messages:
    52
    Looking at the receipt that paypal just sent me - it does label the "Subscription ID" as the "Item #"

    Description:500 Credits, Item#: 46

    But I had that number in the PayPal Button Item Number and it still didn't work.

    and I still got this in the error log:

    "Looks like an invalid IPN post - no Invoice# passed"
  5. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Please contact us in helpdesk and provide amember CP access info I need to check transaction log.
  6. xindexer

    xindexer Member

    Joined:
    Apr 17, 2011
    Messages:
    52
    I was able to get this to work.

    The connection between the amember and paypal and back finally makes sense. When you use a paynow type button you need to do a couple of things in amember that I described above with one addition. You need to create an invoice#. This is called the "public_id" in the invoice class and it is a 5 CHAR code (R3C8O). If you look in the invoice table you'll see it.

    So your code should look like this:

    PHP:
    $public_id Am_Di::getInstance()->app->generateRandomString(5'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890');
     
    $invoice Am_Di::getInstance()->invoiceRecord;
    $invoice->setUser(Am_Di::getInstance()->userTable->load($user_id));
    $invoice->add(Am_Di::getInstance()->productTable->load($product_id));
    $invoice->paysys_id "paypal";
    $invoice->public_id $public_id
    $invoice
    ->calculate();
    $invoice->insert();
    Now when you send your customer to paypal you need to include that invoice number, paypal treats this as a pass through variable:

    https://paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=******MH5C852&invoice=R3C8O

    Hope this helps somebody out.
    julianbittel likes this.
  7. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    xindexer, thank you for your message. I have to clarify that public_id is automatically generated after insertion.

    You may use the following code instead:
    Code:
    $invoice = Am_Di::getInstance()->invoiceRecord;
    $invoice->setUser($user_id);
    $invoice->add(Am_Di::getInstance()->productTable->load($product_id));
    $invoice->paysys_id = "paypal";
    $invoice->calculate();
    $invoice->insert();
    // from there you can use $invoice->public_id , it is set now
    
    julianbittel likes this.
  8. julianbittel

    julianbittel New Member

    Joined:
    Mar 24, 2012
    Messages:
    1
    Dear Alex and Indexer,

    I have exactly the same problem but cant seem to make it work.

    2 Questions:
    - How can I include the invoice number when i send a customer to paypal? When I just add "
    &invoice=R3C8O" to the link to paypal, obviously it won't work..​

    - Do I just place the code​
    "$invoice = Am_Di::getInstance()->invoiceRecord;
    $invoice->setUser($user_id);
    $invoice->add(Am_Di::getInstance()->productTable->load($product_id));
    $invoice->paysys_id = "paypal";
    $invoice->calculate();
    $invoice->insert();
    " into the "invoice.php"-file and everything will work automatically?​

    Big regards,​

    Julian​
  9. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    add the following bits of magic to your code:

    PHP:
    // as we are calling this code not from a controller, we need to create an instance of some controller
    class MyInvoiceRedirectController extends Am_Controller {}
    $front Zend_Controller_Front::getInstance();
    $controller = new MyInvoiceRedirectController($front->getRequest(), $front->getResponse(), $front->getParams());
    // now we are going to give paysystem plugin do the job as it desires
    // normally we have to check $result, but we know PayPal will just do redirect
    $payProcess = new Am_Paysystem_PayProcessMediator($controller$invoice);
    $result $payProcess->process();
  10. doyo

    doyo aMember Pro Customer

    Joined:
    Aug 16, 2012
    Messages:
    23
    I need would like to use paypal buttons on html pages to promote each product/subscription. An order went through today via a buy-now paypal button. The invoice log says
    "Looks like an invalid IPN post - no Invoice# passed"

    The paypal button's "hosted_button_id" is in the proper place in Products for the item.

    Based on this thread, in order to use PayPal buttons and to get user names listed in the amember database, I need to place the bits of magic that Alex posted into the Invoice.php file that is in the folder: application > default > models?

    If yes, at what line do I place the code?

    If no, where exactly do I place Alex's bits of magic?

    Edit:
    I just saw this:
    http://www.amember.com/forum/threads/paypal-in-front-of-amember.14963/#post-57650

    I looked at my paypal plugin setup and I do not have "Accept Direct Payments" checked. Perhaps this is why the invoice did not pass and the person did not get added to the amember database?

    (I am rather new at this and have not quite wrapped my brain around how it works)

    Perhaps I should write my html pages and then direct the person to the amember sign up page?
  11. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Yes, you need to click "Accept Direct Payments" in PayPal plugin settings, then visit all product settings and enter related PayPal ItemId. The same itemId must be used during Paypal button creation.
  12. doyo

    doyo aMember Pro Customer

    Joined:
    Aug 16, 2012
    Messages:
    23
    Thank you Alex!
    And I finally know what the PayPal Item Id is - I was using the wrong number.

    I have a couple of questions.

    Does selecting "Accept Direct Payments" create an all or none senerio in which all items will need to be purchased through a button? In other words if I select this, can I utilize both buttons and the sign-up page?

    Assuming that I set this up correctly and the customers who purchase through a button are added to the amember database - Will the customer who buys through a button be prompted by amember to create a login at some point during the process?
  13. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Sure, you can use both signup process and paypal buttons.

    In case of direct paypal payment, user will not be asked to create login (it would create wide field for problems - what if user does not create?). Instead, aMember will add user record for user with auto-generated username and password, and aMember will send registration e-mail with the username and password.
  14. doyo

    doyo aMember Pro Customer

    Joined:
    Aug 16, 2012
    Messages:
    23
    Thank you Alex! :)

Share This Page