14 Replies Latest reply on Aug 4, 2014 9:09 PM by user19752

    FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)

    BenGraham

      I am working on integrating my FM solution to accept mobile payments with the PayPalHere app for iOS.  I can get my invoices to post fine and process in the app and can return to FMGo and even call a script, just no parameters are coming across.  My trouble seems to be with structuring the returnURL so that the output fields from PayPalHere are properly posted as parameter or parameters to the FM script.

       

      PayPalHere API reference: https://github.com/paypal/here-sideloader-api-samples/tree/master/docs

       

      Recommended example:

       

       

      What I have that is correctly posting the invoice to PayPalHere and returns to my FMG solution and calls the script: PostPayPalPayment. This script for the moment just brings up a custom dialog to display the specified $param script parameter and Get ( ScriptParameter ) just incase.  Both values are coming up empty when the script runs.

       

      "paypalhere://takePayment?

      accepted=cash,card,paypal

      &returnUrl=FMP://~/FlatRateGo.fmp12?script=PostPayPalPayment&$param=//takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}

      &as=b64

      &step=choosePayment

      &payerPhone=" & inv_CLIENT::Phone

      & "&invoice=" // append JSON Invoice object here

       

      Since it is able to call the script I think the problem is after '$param=' that either the PayPal here app will has trouble seeing the '/takePayment/{result} due to the longer url preceeding it or it is a character needed between these, or maybe an encoding issue?  I have tried using the ":" after the '=' and using a single '/' instead of '//' before 'takePayment/{result}?...'

       

      The API says returnURL is: Root URL of your app, including the call that was invoked by your app.

      Example: my_registered_location://takePayment

       

      An example of the full URL before encoding is:

      paypalhere://takePayment?
      accepted=cash,card,paypal
      &returnUrl=my_registered_location://takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}
      &as=b64
      &step=choosePayment
      &payerPhone=4155551212
      &invoice=
      {
          "paymentTerms": "DueOnReceipt",
          "discountPercent": "0",
          "currencyCode": "USD",
          "number": "1457",
          "merchantEmail": "merchant@ebay.com",
          "payerEmail": "foo@bar.com",
          "itemList": {
              "item": [
                  {
                      "taxRate": "8.5000",
                      "name": "Curtains",
                      "description": "Blue curtains",
                      "unitPrice": "29.99",
                      "taxName": "Tax",
                      "quantity": "1"
                  },
                  {
                      "taxRate": "0",
                      "name": "Delivery Fee",
                      "description": "Delivery Fee",
                      "unitPrice": "5.0",
                      "taxName": "Tax",
                      "quantity": "1"
                  }
              ]
          }
      }

       

       

      Anyone with experience working with communication between FMG and other apps in iOS that can point me in the right direction. 

       

      Thank you for any help.

        • 1. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
          PalmDBS

          You don't appear to be encoding the return URL in any way.  Unencoded, when the return URL encounters IT'S second querystring parameter (first occurence of "&" in the return URL), it is actually ending your return URL parameter being passed to paypalhere.  The "&$param" and everything beyond is actually being passed as new items to paypalhere, and are no longer part of the return URL.

           

          You'll need to encode the full return URL (as well as other parameters, such as the json response, etc) before appending it as a parameter in the querystring to paypalhere, otherwise that full URL will not parse correctly.

           

          You'll note in the sample on the link you provided that this is what they do (albeit in javascript):

           

              //creating vars to be used in API call

              var retUrl = encodeURIComponent("http://www.myurl.com/return.php?{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}");

              var pphereUrl = "paypalhere://takePayment?accepted=" + encodeURIComponent("cash,card,paypal") + "&returnUrl=" + retUrl;

           

          Assuming this link is generated from within FileMaker, you'll probably end up with something like:

          "paypalhere://takePayment?

          accepted=cash,card,paypal

          &returnUrl=" & GetAsURLEncoded ("FMP://~/FlatRateGo.fmp12?script=PostPayPalPayment&$param=//takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}") &

          "&as=b64

          &step=choosePayment

          &payerPhone=" & inv_CLIENT::Phone

          & "&invoice=" & GetAsURLEncoded (<// append JSON Invoice object here>)

           

          That should get you going in the right direction.

           

          In the end the returnURL portion of the call to paypalhere is going to look more like this:

           

          FMP:%2F%2F~%2FFlatRateGo.fmp12%3Fscript%3DPostPayPalPayment%26%24param%3D%2F%2FtakePayment%2F%7Bresult%7D%3FType%3D%7BType%7D%26InvoiceId%3D%7BInvoiceId%7D%26Tip%3D%7BTip%7D%26Email%3D%7BEmail%7D%26TxId%3D%7BTxId%7D

          • 2. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
            BenGraham

            Thanks PalmDBS. I will give it a try.  I had not used the GetASURLEncoded () initially to see if it worked, and it worked as far as getting the Invoice items.  It makes sense what you are saying on it splitting the URL for the return params and the {result} part to come from PayPalHere. 

            I will repost my results in follow up.

            • 3. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
              BenGraham

              Well, I have tried:

              1. using the GetAsURLEncoded as shown: encoding return URL and JSON invoice and it failed to open PayPalHere with an invoice.

               

              2. Then I tried only encoding the returnURL and the accepted payment methods, an creates the invoice to pay, but when going to Pay it crashed PayPalHere, indicating it does not like the payment choices being encoded.

               

              3. Only encoding the returnURL, after taking the payment it tried to return to my FM file, but said 'can't open file " ". Indicating that the encoded returnURL would not be understood by PayPalHere.

               

              4. lastly I tried just encoding GetAsURLEncoded ( "//takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}" ) portion of the url.  This was equal to my original tests of not using GetAsURLEncoded at all where It is able to return to FM and run my script, but the parameters are empty again.

               

              I am using the OpenURL script step here which I believe FM does some auto encoding and that may be why the encoded portions of the url are failing to work.

               

              So it may still be something wrong with what is after "...script=PostPayPalPayment&$param=" within the returnURL or possibly PayPalHere will not understand its own parameters if my 'root URL' is also containing 'script=PostPayPalPayment&$param=" ' preceding the parameters requesting the {result} from PayPalHere?

               

              Perhaps having something to do with the connecting characters between $param= and 'takePament/{result}..."?

              • 4. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                PalmDBS

                My apologies for not looking closer.  Since the $param variable itself contains forward slashes, it needs encoded again, otherwise those forward slashes are read as directories in the FMP link.

                 

                So, on top of encoding the returnUrl as shown in the example, we ALSO need to wrap the $param value in another getasurlencoded.

                 

                Let me know how this works:

                "paypalhere://takePayment?accepted=cash,card,paypal&returnUrl=" & GetAsURLEncoded ("FMP://~/FlatRateGo.fmp12?script=PostPayPalPayment&$param="& GetAsURLEncoded("//takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}")) & "&as=b64&step=choosePayment&payerPhone=".......

                • 5. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                  BenGraham

                  Hi PalmDBS,

                   

                  Thanks again for your reply.  I tried this as well.  It will bring the invoice over as long as it is NOT encoded, but the returnURL results in “ Error - The file “” could not be opened. (Not Found).  This is what it does whether I encode exactly as shown here:

                   

                  "paypalhere://takePayment?accepted=cash,card,paypal

                  &returnUrl=" & GetAsURLEncoded ( "FMP://~/FlatRateGo.fmp12?script=PostPayPalPayment&$param=" & GetAsURLEncoded ( "//takePayment/?Type=&InvoiceId=&Tip=&Email=&TxId=" )

                  & "&as=b64

                  &step=choosePayment

                  &payerPhone="

                  & inv_CLIENT::Phone

                  & "&invoice=“ //json invoice object here

                   

                  or if done this way with param in separate GetAsURLEncoded.:

                   

                   

                  "paypalhere://takePayment?accepted=cash,card,paypal

                   

                  &returnUrl=" & GetAsURLEncoded ( "FMP://~/FlatRateGo.fmp12?script=PostPayPalPayment&$param=“ ) & GetAsURLEncoded ( "//takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}" )

                  & "&as=b64

                  &step=choosePayment

                  &payerPhone="

                  & inv_CLIENT::Phone

                  & "&invoice=“ //json invoice object here

                   

                  So any time that a portion of the url is encoded that portion is not readable by PayPalHere.  In the previous tests when encoding the JSON invoice there was no readable data for PayPalHere to be ready to pay. 

                   

                  It sure seems that FM is already encoding or something since the only time it comes close to working is when I do not use GetAsURLEncoded.

                   

                  Not sure where to go from here at the moment.  Will see what else I can find.  Unless again there is some other requirement from the PayPalHere app in the url formulation that does not fit with adding the script and param for FM?

                  • 6. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                    BenGraham

                    After much playing about it seems clear that the trouble is likely the PayPalHere app's ability to process this returnURL:

                     

                    returnUrl=fmp://~/FlatRateGo?script=PostPayPalPayment&param=://takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Email={Email}&TxId={TxId}"

                     

                    The PayPalHere API reference for structuring the returnURL says to URL encode, infact most of the URL is to be encoded, however ,as mentioned on one of my recent replies to this post, any portion of the URL that is encoded does not work with PayPalHere (PPH).  If the URL is not encoded and the returnURL is as above the invoice is able to propogate into PPH, PPH is able to return to my FM file and call my script.  Where it fails is there are no parameters passed. 

                     

                    I think the problem is in the fact there are two sets of "://" in the returnURL, the first required by FMP protocol and the 2nd being where PPH uses the portion of the returnURL to return the specified fields of data after '://takePayment/{result}?'.

                     

                    Would the solution not be in finding a way to properly structure the returnURL so that PPH is able to read and provide the responce whilst putting it into the fmp script parameter?

                    • 7. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                      PalmDBS

                      It CAN'T parse the second :// which is why it has to be encoded again per previous post.  Yesterday I had a chance to actually look at it with PPH on my iPhone, and found a couple of things in reading the documentation. 

                       

                      • You had a $ in front of the word param, which is setting a variable named "param" as opposed to passing it as a parameter to the script.  In see in your last post that this has been corrected.
                      • When including "&as=b64" in the link, it expects the invoice to be base64 encoded.  By removing that parameter, it will accept the invoice in URL encoded format.

                       

                      Below is the URL calculation that I have in FileMaker.  Vey important: You'll note that I do a Substitution on the encoded param string.  The reason in that when PPH parses the returnUrl, the param string is STILL encoded (as we did a second layer of encoding to deal with the additional // and & characters).  In encoding the string, it also encodes the curly braces.  So when PPH is looking for {Type} to substitute in the value, it won't work (because the string value is %7BType%7D).  So I manualy unencode the curly braces with the substitute function.  Now PPH will properly inject it's values into our string.

                       

                      The only reason we have to do this is because we are dealing with three layers of urls/querystrings - the param value, inside the returnUrl value, inside the overall link.  Every layer past the original needs that additional layer of encoding to protect the structure of its parent URL.

                       

                      So, it works on my phone now, with param being fully passed and {Type} is substituted with UNKNOWN, {Tip} with 0, etc (I hit cancel on the phone, which is why I receive UNKNOWN as the type).

                       

                      Now, one thing I should point out is that since Paypal is substituting it's values ({Type},{Tip},{Email}, etc) into the middle of an otherwise encoded param value, that any special characters contained within those Paypal values will break the overall link.  I don't know that there is anything that can be done to prevent that.  Given the nature of the fields though, I don't think it will be an issue.

                       

                      So, swap back in your file and script name and give this a shot - it is working on my end.

                       

                      FM URL Calculation:

                      "paypalhere://takePayment?accepted=" & GetAsURLEncoded("cash,card,paypal") & "&returnUrl=" &

                      GetAsURLEncoded ("FMP://~/test13.fmp12?script=postpayment&param=" & Substitute(GetAsURLEncoded("//takePayment/{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}");["%7B";"{"];["%7D";"}"])) &

                      "&step=choosePayment&payerPhone=8582165356&invoice=" & GetAsURLEncoded("{

                          \"paymentTerms\": \"DueOnReceipt\",

                          \"discountPercent\": \"0\",

                          \"currencyCode\": \"USD\",

                          \"number\": \"1459\",

                          \"merchantEmail\": \"solutions@palmdbs.com\",

                          \"payerEmail\": \"foo@bar.com\",

                          \"itemList\": {

                              \"item\": [

                                  {

                                      \"taxRate\": \"8.5000\",

                                      \"name\": \"Curtains\",

                                      \"description\": \"Blue curtains\",

                                      \"unitPrice\": \"29.99\",

                                      \"taxName\": \"Tax\",

                                      \"quantity\": \"1\"

                                  },

                                  {

                                      \"taxRate\": \"0\",

                                      \"name\": \"Delivery Fee\",

                                      \"description\": \"Delivery Fee\",

                                      \"unitPrice\": \"5.0\",

                                      \"taxName\": \"Tax\",

                                      \"quantity\": \"1\"

                                  }

                              ]

                          }

                      }")

                      • 8. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                        BenGraham

                        Hi PalmDBS,

                         

                        Thanks again for your continued support on this.

                         

                        Okay, after setting the FM file name to my file and script 'PostPayPalPayment' I was able to creat the PPH invoice pay and the script parameter came up empty.  Then I put the "$" back on the param as in "...?script=PostPayPalPayment&$param=" and it was able to bring the PPH response into the $param as shown in the screen shot.

                         

                        PayPalHere_response.jpg

                         

                        The $PayPalHereOutPut showing as "" is Get ( ScriptParameter ) and $param = $param from the returnURL of PPH.

                         

                        Now just to parse the result.

                         

                        I think I am on the right track now.

                         

                        Thank you so much for you help PalmDBS, and I don't even know your name to thank you properly.

                         

                        Cheers,

                        Ben

                         

                        PS- you can complete the PPH payment by choosing Cash and it will not affect your PayPal balance, it only keeps a record of the transaction.

                        • 9. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                          PalmDBS

                          Glad I could help.  My name is Mike, by the way.  I guess I need to update my signature! 

                           

                          Odd that it wouldn't pass as the script parameter (as I used param= and get(scriptparameter) showed the content), but as long as you're getting the value through the variable then all is good!

                           

                          That was a tricky one - especially figuring out that the curly braces needed unencoded for PPH to do it's substitution.  But tricky == fun for me!

                           

                          All in all, though, just helping on this showed me how relatively easy it is to integrate FMGO with PPH (once the URL is formatted).  I'll be sure to use it in the future. 

                           

                          Good luck with the rest of the project!

                           

                          Mike

                          • 10. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                            user19752

                            I think it will be a bit simpler if 'PostPayPalPayment' script get only variable data from the URL and construct URL in it concatening constant "//takePayment/".and variable data.

                             

                            One thing is that some HTMLic situation, &para is treated as entity &para; (mean one character, paragraph mark).

                            • 11. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                              PalmDBS

                              Yes, param string could be adjusted to only pass values, and not be constructed as a URL itself (thereby alleviaing the need for the string to be URL encoded and for the curly braces to be unencoded).  I just responded to the code in the OP.

                               

                              Ben, something like this should also work:

                              "paypalhere://takePayment?accepted=" & GetAsURLEncoded("cash,card,paypal") & "&returnUrl=" &

                              GetAsURLEncoded ("FMP://~/test13.fmp12?script=postpayment&param={result}~~~{Type}~~~{InvoiceId}~~~{Tip}~~~{Email}~~~{TxId}") &

                              "&step=choosePayment&payerPhone="........

                               

                              Where you simply pass the variables in the param, using a custom delimeter (not "&" that would break the URL), then parse the values and reconstruct the url inside your script.

                              • 12. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                                BenGraham

                                Hi Mike,

                                 

                                I tried changing to this param={result}~~~{Type}~~~{InvoiceId}~~~{Tip}~~~{Email}~~~{TxId}") it was unable to create the PPH invoice.  

                                 

                                Yes as you said that is some tricky business with the substitution of the {}.  URL's and encoding can drive those of us with less web experience crazy because it can be just a single character that is not right and result will be just that it does not work.  I am truly greatful for your help and all of the FM community.  Yes, being able to integrate PPH with FMG is a very useful tool and I am sure we will save many others some trouble with this thread, should they find it. 

                                 

                                Cheers,

                                Ben

                                • 13. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                                  user14047

                                  I Created a sample file.

                                  https://github.com/Genecom/FileMakerSampleSolutions > PayPalHere.fmp12

                                   

                                   

                                  Set Variable [
                                       $UrlScheme ; 
                                       Value:
                                            "paypalhere://takePayment?returnUrl=" & 
                                            GetAsURLEncoded ( 
                                                 "fmp://$/SOLUTION.FMP12?script=CALLBACKSCRIPT&param=" & 
                                                 "{result}&$Type={Type}&$InvoiceId={InvoiceId}&$Tip={Tip}&$Email={Email}&$TxId={TxId}" 
                                            ) & 
                                            "accepted=card&step=choosePayment&invoice=" & 
                                            Substitute( 
                                                 GetAsURLEncoded ( $json ) ; 
                                                 [ ":" ; "%3A" ] 
                                            )
                                  ]
                                  Open URL [ No dialog; $UrlScheme ]
                                  

                                   

                                   

                                  The main point is a position of suitable GetAsURLEncoded function.
                                  And It is carrying out URLEncoded of ":" in JSON data exactly.

                                   

                                  要点は GetAsURLEncoded 関数の位置と、JSONデータの中の ":" もきちんと URLEncoded してやることです。

                                  • 14. Re: FileMaker Go solution connect with PayPalHere app - how to structure returnURL with script parameter(s)
                                    user19752

                                    {} shouldn't encoded, so

                                     

                                    & "&returnUrl=" &

                                    GetAsURLEncoded ("FMP://~/test13.fmp12?script=postpayment&$data=") &

                                    "{result}~~~{Type}~~~{InvoiceId}~~~{Tip}~~~{Email}~~~{TxId}" &

                                     

                                    I'm not sure that "~" should be encoded or not.

                                    if the returning data not contain carriage return, using "%od" instead of "~~~" makes it easy to parse with GetValue() function.