How using paypal pro ?

armand 28 Dec, 2011
Helle every body,

I'll like to kniw how using paypal pro in CF.

What i need exactly is to set my chronoforms using express checkout of paypal. I'll like that when customer come on the web site, he choose product, make paiement and if the paiement is OK, chronoforms execute some CURL. I think that PAYPAL PRO can do it but i don't know how.

Need help please.
AF.
GreyHead 28 Dec, 2011
Hi armand,

I think that there is a tutorial for using PayPal Pro with ChronoForms in the Tutorials area here. It's for CFv3 but you can adapt it if you are using CFv4.

Bob
GreyHead 28 Dec, 2011
Hi armand,

If that is all the info you are collecting then you probably don't need PayPal Pro. If you just need a basic PayPal payment then you can use the ReDirect URL and ReDirect User actions to pass the amount and product to PayPal and send the User there to pay.

Bob
armand 28 Dec, 2011
Hi Bob,

I always need to excute an API if and only if the paiement to paypal is validate; That's why i want to use express paypal.

AF.
armand 28 Dec, 2011
Bob,

Please, can i quickly contact somegroup or somebody which can help me to solve this problem?

I'll be glad if they can speak french.

I'm reaady to buy a beer or small billing.

AF.
GreyHead 28 Dec, 2011
Hi armand,

Contact me by PM or email if you want to. My French is basic but we can get there with a little help from Google.

Bob
GreyHead 31 Dec, 2011
Hi armand,

I've built a simple example of a form that uses the PayPal Express Checkout API with ChronoForms V4 RC3.0

Notes: [list=a]
  • that to keep it simple this example is incomplete: there is very little validation of the responses and none of the data is logged or saved.

  • All the code here is using the PayPal Sandbox for testing; on a live site you should implement secure CURL to protect the transaction data.

  • I've made use of my cURL [GH] and Event Switcher [GH] actions to make the code simpler; you could do the same with the standard actiosn by using more custom code.
  • [/list:o]

    The form
    The form has an amount input; a submit button and the PayPal Checkout Express button.
    [attachment=2]31-12-2011 12-00-36.png[/attachment]
    It is displayed with a Show HTML action in the On Load event (more about the On Load event later).

    On Submit
    When the form is submitted we first use the cURL [GH] action to notify PayPal about the transaction; then we redirect the user to PayPal to approve payment.

    The CURL [GH] settings are:
    Target URL:
    https://api-3t.sandbox.paypal.com/nvp
    (this is a Sandbox URL and is used in all the cURL actions here).
    Params/Fields map
    METHOD=SetExpressCheckout
    VERSION=76.0
    USER=apitst_1268761554_biz_api1.xxxxxx.com
    PWD=1268761569
    SIGNATURE=AgxQfaOts4BFxGZfkSaLBPfEPZsbAj0MZEba9KiNqRxV6Wv1GWdj4DWk
    PAYMENTREQUEST_0_PAYMENTACTION=Sale
    RETURNURL=http%3A%2F%2Ffrances%2FJoomla1.7b%2Findex.php%3Foption%3Dcom_chronoforms%26chronoform%3Dtest_form_pp_express%26ppx%3Dreturn
    CANCELURL=http%3A%2F%2Ffrances%2FJoomla1.7b%2Findex.php%3Foption%3Dcom_chronoforms%26chronoform%3Dtest_form_pp_express%26ppx%3Dcancel
    PAYMENTREQUEST_0_AMT={amount}
    PAYMENTREQUEST_0_DESC=a digeridoo

    The main information here are the two URL entries RETURNURL and CANCELURL; in each case these are the URLs of the form with an added parameter ppx=return or ppx=cancel. We use these to check the repose when the user is returned from PayPal.

    Notes: [list=a]
  • The URLs have been URL encoded by hand - I'll update the cURL [GH] action to do this automatically.

  • I've added a description entry at the end just to check that it works - there are many other entries that you can add here to show more information when the user is sent to PayPal. Check the PayPal docs for the complete list.
  • [/list:o]

    The next step is to get the cURL response. We do this with a Custom Code action.
    <?php
    // get the CURL response from PayPal and add it to the Form data
    $temp = explode('&', $form->data['curl_gh']);
    $curl_response = array();
    foreach ( $temp as $v ) {
      $t = explode('=', $v);
      $curl_response[$t[0]] = urldecode($t[1]);
    }
    $form->data['curl_response'] = $curl_response;
    unset($temp);
    unset($curl_response);
    // add parameters to use in the ReDirect URL
    $form->data['cmd'] = '_express-checkout';
    $form->data['token'] = $form->data['curl_response']['TOKEN'];
    ?>

    Note that this *doesn't* include the code to check that ACK=Success - this needs to be added as well as code to log this transaction info for reference later.

    The last two lines of this code set up the values of cmd and token to add to the ReDirect URL action which is the next step.
    The Target URL is
    https://www.sandbox.paypal.com/cgi-bin/webscr
    (a sandbox URL again); and the Params/Fields map has just
    cmd={cmd}
    token={token}

    Lastly for the OnSubmit event add a ReDirect User action to send the user to PayPal.

    The full OnSubmit event then looks like this:
    [attachment=1]31-12-2011 12-45-38.png[/attachment]

    When the User returns from PayPal they will back to the form On Load event (though you could also use a new Custom event). We need to know if check if this is the first time the form is loaded, or if it is a user returning from PayPal; and, if they are coming back from PayPal is this from the 'return' URL or the 'cancel' URL.

    To do this I've used an Event Switcher [GH] action. The action lets us handle five events - four in the action and the fifth to continue the On Load event if we do nothing.

    In this case I've used 'Event A' to show the form HTML; 'Event B' to handle the 'Cancel' URL and the continued 'ON Load' event to handle the 'Return' URL as this is the most complicated sequence.

    The Event Switcher [GH] code is this
    <?php
    if ( isset($form->data['ppx']) ) {
      if ( $form->data['ppx'] == 'return' ) {
        // user approved payment
        // continue in On Load event
      } elseif ( $form->data['ppx'] == 'cancel' ) {
        // user cancelled
        return 'event_b';
      }
    } else {
      // Show the Form HTML
      return 'event_a';
    }
    ?>
    First it checks for the ppx parameter that was added to the PayPal URLs, if there's no paramter it returns 'event_b'; if the value is 'cancel' it returns 'event_a' otherwise it returns nothing.

    In the Event Switcher [GH] Event A box we add the Show HTML action and a Show Stopper action in (the Show Stopper prevents any more actions running).

    In the Event Switcher [GH] Event B box we add a Show Thanks Message action with a 'sorry you cancelled' message and a Show Stopper action.

    In the rest of the On Load event we handle the remaining steps in the PayPal Express Checkout process. First we get the payee transaction details back from PayPal. (These should be logged or saved and can be used to populate an order confirmation page. This is not included here.) Second we confirm the payment and again get confirmation back from PayPal.

    To do this we use two more cURL [GH] + Custom Code pairs of action.

    The first cURL [GH] has this code to resuest the payee details:
    METHOD=GetExpressCheckoutDetails
    VERSION=76.0
    USER=apitst_1268761554_biz_api1.xxxxx.com
    PWD=1268761569
    SIGNATURE=AgxQfaOts4BFxGZfkSaLBPfEPZsbAj0MZEba9KiNqRxV6Wv1GWdj4DWk 
    TOKEN={token}

    and the following Custom Code again unpacks the response, addds it to the Form data and sets up a aouple of parameters for the final stage:
    <?php
    $temp = explode('&', $form->data['curl_gh']);
    $curl_response = array();
    foreach ( $temp as $v ) {
      $t = explode('=', $v);
      $curl_response[$t[0]] = urldecode($t[1]);
    }
    $form->data['curl_response'] = $curl_response;
    $form->data['PAYMENTREQUEST_0_AMT'] = $form->data['PAYMENTREQUEST_0_AMT'] = $curl_response['PAYMENTREQUEST_0_AMT'];
    $form->data['PAYERID'] = $curl_response['PAYERID'];
    unset($temp);
    unset($curl_response);
    ?>

    You can add more custom code here to check the values returned and take appropriate action.

    The final stage completes the payment. The cURL [GH] code is
    METHOD=DoExpressCheckoutPayment
    VERSION=76.0
    USER=apitst_1268761554_biz_api1.bobjanes.com
    PWD=1268761569
    SIGNATURE=AgxQfaOts4BFxGZfkSaLBPfEPZsbAj0MZEba9KiNqRxV6Wv1GWdj4DWk 
    TOKEN={token}
    PAYMENTREQUEST_0_PAYMENTACTION=Sale
    PAYERID={PAYERID}
    PAYMENTREQUEST_0_AMT={PAYMENTREQUEST_0_AMT}

    and the following Cusom code is
    <?php
    $temp = explode('&', $form->data['curl_gh']);
    $curl_response = array();
    foreach ( $temp as $v ) {
      $t = explode('=', $v);
      $curl_response[$t[0]] = urldecode($t[1]);
    }
    $form->data['curl_response'] = array_merge($form->data['curl_response'], $curl_response);
    unset($temp);
    unset($curl_response);
    ?>

    Again, this does not do any checking on the responses. At a minimum you should check for ACK=Success and handle any errors if the transaction isn't successful.

    Here is the set of actions from the On Load event:
    [attachment=0]31-12-2011 13-11-15.png[/attachment]

    That's it. All the PayPal data is now added to the Form Data and can be saved, logged, emailed or displayed. Here's the result from a test payment:
                [TOKEN] => EC-6TS98843CC621254Y
                [CHECKOUTSTATUS] => PaymentActionNotInitiated
                [TIMESTAMP] => 2011-12-31T10:48:47Z
                [CORRELATIONID] => 2ba0e625e9eac
                [ACK] => Success
                [VERSION] => 76.0
                [BUILD] => 2271164
                [EMAIL] => paypal@xxxxx.com
                [PAYERID] => R9NZXGF4FMVLE
                [PAYERSTATUS] => unverified
                [FIRSTNAME] => Test
                [LASTNAME] => Account
                [COUNTRYCODE] => GB
                [SHIPTONAME] => Test Account
                [SHIPTOSTREET] => 17 High Street
                [SHIPTOCITY] => Somewhere
                [SHIPTOSTATE] => London
                [SHIPTOZIP] => W1S T99
                [SHIPTOCOUNTRYCODE] => GB
                [SHIPTOCOUNTRYNAME] => United Kingdom
                [ADDRESSSTATUS] => Confirmed
                [CURRENCYCODE] => USD
                [AMT] => 89.63
                [SHIPPINGAMT] => 0.00
                [HANDLINGAMT] => 0.00
                [TAXAMT] => 0.00
                [DESC] => digeridoo
                [INSURANCEAMT] => 0.00
                [SHIPDISCAMT] => 0.00
                [PAYMENTREQUEST_0_CURRENCYCODE] => USD
                [PAYMENTREQUEST_0_AMT] => 89.63
                [PAYMENTREQUEST_0_SHIPPINGAMT] => 0.00
                [PAYMENTREQUEST_0_HANDLINGAMT] => 0.00
                [PAYMENTREQUEST_0_TAXAMT] => 0.00
                [PAYMENTREQUEST_0_DESC] => digeridoo
                [PAYMENTREQUEST_0_INSURANCEAMT] => 0.00
                [PAYMENTREQUEST_0_SHIPDISCAMT] => 0.00
                [PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED] => false
                [PAYMENTREQUEST_0_SHIPTONAME] => Test Account
                [PAYMENTREQUEST_0_SHIPTOSTREET] => 17 High Street
                [PAYMENTREQUEST_0_SHIPTOCITY] => Somewhere
                [PAYMENTREQUEST_0_SHIPTOSTATE] => London
                [PAYMENTREQUEST_0_SHIPTOZIP] => W1S T99
                [PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE] => GB
                [PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME] => United Kingdom
                [PAYMENTREQUESTINFO_0_ERRORCODE] => 0
                [SUCCESSPAGEREDIRECTREQUESTED] => false
                [INSURANCEOPTIONSELECTED] => false
                [SHIPPINGOPTIONISDEFAULT] => false
                [PAYMENTINFO_0_TRANSACTIONID] => 6D900291LA760382S
                [PAYMENTINFO_0_TRANSACTIONTYPE] => expresscheckout
                [PAYMENTINFO_0_PAYMENTTYPE] => instant
                [PAYMENTINFO_0_ORDERTIME] => 2011-12-31T10:48:45Z
                [PAYMENTINFO_0_AMT] => 89.63
                [PAYMENTINFO_0_TAXAMT] => 0.00
                [PAYMENTINFO_0_CURRENCYCODE] => USD
                [PAYMENTINFO_0_PAYMENTSTATUS] => Pending
                [PAYMENTINFO_0_PENDINGREASON] => multicurrency
                [PAYMENTINFO_0_REASONCODE] => None
                [PAYMENTINFO_0_PROTECTIONELIGIBILITY] => Eligible
                [PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE] => ItemNotReceivedEligible,UnauthorizedPaymentEligible
                [PAYMENTINFO_0_SECUREMERCHANTACCOUNTID] => X58SRD4RK8TWU
                [PAYMENTINFO_0_ERRORCODE] => 0
                [PAYMENTINFO_0_ACK] => Success

    Bob
    armand 02 Jan, 2012
    Hi Bob,

    Have some problem; i did all the first step (on submit).

    But, since the morning, i get some error message :

    "La transaction n'est pas valable. Veuillez retourner sur le site du destinataire pour compléter cette transaction à l'aide de la procédure normale de paiement."




    don't know what happens ?
    GreyHead 02 Jan, 2012
    Hi armand,

    No, not enough information there to give me any idea what is wrong.

    Are you using a valid PayPal sandbox account with your own Username and password, etc. in the configuration?

    Bob
    armand 02 Jan, 2012
    I was wrong. I was get a mistake in signature.
    armand 03 Jan, 2012
    Hi Bob,

    What can i do to see (like you) this result from paypal ? (i don't want to make a mistake)

    I'll try to adapt this big big explanation you give to my need.

    AF.
    GreyHead 04 Jan, 2012
    Hi Armand,

    I added a Debugger action to the On Load and On Submit events.

    Bob
    armand 04 Jan, 2012
    Hi Bob,

    Thanks very much; I was allready getting the solution for displayed. But to save or email some part of result i'm continue to check it.

    What i'm looking for now is how using some of this informations results as conditions for execute some special custom code (information like : PAYMENTINFO_0_ACK=Success).


    In other side, we are still in sandbox.paypal.com, and you say that for paypal.com, we have to use secure CURL to protect the transaction data. I'm not know how do it.

    One again thanks.

    (Remember that i'm french speaking, my english is not good).
    AF.
    armand 06 Jan, 2012
    Hi Bob,

    Since yesterday, i took the time to review the differents points of these codes. I finally understood how to use a part of the final result for an email or even as a condition, by define them as data at the end of custom code.

    Could you please help me once again :
    1 - Can you telling me what are the differents mostly importants data in result which reassures me the transaction is OK and then my seller account CREDITED.
    2 - Can you please explain me how secure CURL to protect the transaction data on live paypal.com .

    AF.
    GreyHead 06 Jan, 2012
    Hi Armand,

    1 - Can you telling me what are the differents mostly importants data in result which reassures me the transaction is OK and then my seller account CREDITED.


    Please check the PayPal documents. I think that the ACK=Success message is the main one; but you need to add code to handle the failure messages too.

    2 - Can you please explain me how secure CURL to protect the transaction data on live paypal.com .


    I don't know how to do this, I think you have to get and install security certificates - please check the CURL documents. Google 'secure curl' to find them.

    Bob
    rushseeker 29 Jan, 2012
    Hi

    Can i use this tutorial to a BUY NOW BUTTON?
    GreyHead 29 Jan, 2012
    Hi rushseeker ,

    Yes, but do you need all the complexity here?

    Bob
    rushseeker 29 Jan, 2012
    I don't know...
    i must do this:
    the user make a payment and if is OK then i must register in database the Session data.
    GreyHead 30 Jan, 2012
    Hi rushseeker,

    If you are selling goods for immediate despatch the you probably do need something like this. If it's a service or a donation then probably a simple Redirect will work OK as there will be an email ntoce of a failed payment.

    Bob
    adricist 18 Mar, 2012
    Hi Bob,

    I have created a form to collect donations with ChronoForms 4.0 RC3.2

    On submitting the form I am generating 2 emails, one to the person donating and one to the company receiving the donation. All of this works fine but what I now need is for the data collected in the form to be used to automatically fill in the Login page on PayPal, so that the user does not have to enter it again there.

    I am assuming that I need to place some php code under Custom Code - After Email(s)

    I am also assuming that the code would have to be built around the PayPal SetExpressCheckout

    &METHOD=SetExpressCheckout
    &RETURNURL=https://...
    &CANCELURL=https://...
    &AMT=10.00
    &PAYMENTACTION=Sale
    &SHIPTONAME=A Jones
    &SHIPTOSTREET=1 Main Street
    &SHIPTOCITY=San Jose
    &SHIPTOSTATE=CA
    &SHIPTOCOUNTRYCODE=US
    &SHIPTOZIP=95131
    [email]&EMAIL=jsmith01@example.com[/email]
    &SHIPTOPHONENUM=408-559-5948

    I do not really need to capture back a response, using the RETURNURL and CANCELURL will be enough for what I am doing. But I do need to fill in the field data collected when the form is submitted to send it with the above code. The fields I am using are

    &SHIPTONAME={cf_name} {cf_surname}
    &SHIPTOSTREET={cf_address}
    &SHIPTOCITY={cf_suburb}
    &SHIPTOSTATE={cf_state}
    &SHIPTOCOUNTRYCODE=US
    &SHIPTOZIP={cf_postcode}
    &EMAIL={cf_email}
    &SHIPTOPHONENUM={cf_phone_home}


    Am I on the right track? And if so how should I structure the PHP code in order to capture the values of those fields?

    I look forward to your comments.

    Regards,
    Adri
    GreyHead 18 Mar, 2012
    Hi adricist,

    I suggest that you follow my example earlier in this thread which does pretty much exactly this.

    Bob
    adricist 19 Mar, 2012
    Hi again Bob,

    Unfortunately I am not understanding how I can structure the events in the Forms. Is there a tutorial that explains this? When I look at the Basic or Advanced Elements in the Form Editor I cannot see anything that points to an On Load or On Submit Event.

    Can you please point me in the right direction?

    Thanks,
    Adri
    GreyHead 19 Mar, 2012
    Hi Adri,

    There are a series of videos here that will help you get started with CFv4.

    Bob
    fschutzman 08 Apr, 2012
    I have noticed a disturbing pattern in the response to questions asked regarding paypal. The response by Max and Greyhead are basically the same. They refer to some videos and tutorials that were very basic regarding CF version 4 or an outdated book. What we need is a step by step tutorial for a non-programmer on setting up paypal from within Chronoforms V4. I, for one, do not like to buy an outdated book that just adds to the confusion. If you want serious business people to be willing to pay for something, make it relevant. I do not mind paying for relevant and timely information but not old recycled stuff. I can just imagine how many people go somewhere else in frustration. IMHO, not a very good business model.
    GreyHead 08 Apr, 2012
    Hi fschutzman,

    The example earlier in this thread is a step by step example of using ChronoForms v4 with PayPal Checkout express. I also take great care not to refer to the book or to irrelevant examples or videos - though I may occasionally get it wrong.

    I'm also mostly a volunteer here (though Max does occasionally pay me a small royalty and some users are kind enoough to buy a tutorial or a beer).

    Apologies if this doesn't help you but right now is the Sunday of a Bank holiday weekend here.

    Bob
    This topic is locked and no more replies can be posted.