Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

function Xbasic module

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Re: function Xbasic module

    Thanks guys I'll keep trying. Keep you posted

    Comment


      #17
      Re: function Xbasic module

      The curl code genie works fine in the xbasics module I just need to turn it into a function and figure out how
      to call and digest the API response in a UX. The show var works fine just change the plan name and ID and you’ll see the response, or leave it the same and you’ll see the error. use my posted code. Working in the Xbasic module and running the request from there. Stripes create plan code is above as well use my test account you can’t hurt anything.

      Comment


        #18
        Re: function Xbasic module

        Baby Steps
        Lol

        Comment


          #19
          Re: function Xbasic module

          Sign me up Alex!

          Comment


            #20
            Re: function Xbasic module

            Originally posted by bob9145 View Post
            Trying to turn this code created by the curl genie into a function that can be called from the browser like this video explains https://www.youtube.com/watch?v=BOUrEhYfZBk&t=186s
            not sure how you would code?
            Function plan as c ()
            Plan = ?
            end Function

            exports.create_plan = plan
            Alpha cURL to XBasic Genie is extremely sensitive to extra spaces and other stuff. Make sure your cURL command is all on one line and is clean. This cURL command goes through the genie cleanly...

            Code:
            curl https://api.stripe.com/v1/plans -u sk_test_4444: -d currency=usd -d interval=month -d product=prod_4444 -d nickname="Pro Plan" -d amount=3000
            Then comment out the showvar lines... and add this line into the ending if section...

            Code:
            flag_1 = ce.Exec()
            if flag_1 then
            
                dim headers as c
            	dim contents as c
            	headers = cf_1.GetHeaders()
            	contents = cf_1.GetContent()
            	
            	Plan = contents
            
            	'BE SURE TO COMMENT OUT THIS CODE IN A WEB APPLICATION AS showVar() CANNOT BE USED IN WEB APPLICATIONS
            	'dim msg as c
            	'msg = "Headers: " + crlf() + headers + crlf() + "Content: " + contents
            	'showvar( msg)
            
            
            else
            	dim errors as c
            	errors = ce.error()
            	
            	Plan = errors
            
            	'BE SURE TO COMMENT OUT THIS CODE IN A WEB APPLICATION AS showVar() CANNOT BE USED IN WEB APPLICATIONS
            	'showvar("error: " + errors)
            	
            end if
            Your XBasic Module function name is Plan... so you're assigning whatever Plan details (or error) Stripe returns to the function name Plan.

            Your Ajax Callback function to call the Module function would be...

            Code:
            function xbm_stripeCreatePlan as c (e as p)
            	
            	debug(1)
            	
            	dim xb1 as p
            	xb1 = require("stripeFunctions")
            	
            	dim stripePlan as c
            	stripePlan = xb1.create_plan()
            	
            end function
            You didn't mention what your XBasic Function Module was named. In this case my Module name is "stripeFunctions".

            Then you make your callback from, for example, a button...

            Code:
            {dialog.Object}.ajaxCallback('','','xbm_stripeCreatePlan','');

            Comment


              #21
              Re: function Xbasic module

              Cool! will try it tonight.

              Comment


                #22
                Re: function Xbasic module

                I'll say the curl genie is touchy, had to put the text on one line the carriage return in my text editor was causing it to create redundant flags. Also the / in Stripe's example code does similar things at least that' s the way it seems.

                Comment


                  #23
                  Re: function Xbasic module

                  Right... that's what I was saying... the cURL command needs to be all on one line and free of any extraneous characters. Many companies who supply cURL (bless their hearts) shove carriage returns, line connectors etc. into their commands. Everything needs to be stripped out or the XBasic cURL genies loses its mind. A Stripe cURL I had cleaned still created 4x the XBasic commands... and it was just some spaces as far as I could see - probably non-printable something.

                  Comment


                    #24
                    Re: function Xbasic module

                    Ok this is some combination of the above suggestions and the hello example. I simplified the then / else to test the response of the script. Either "True", or "False". The problem I'm having is that even though I submit a duplicate plan to produce a intentional error the script returns "True" . If flag_1 then is executed whether their is an error or not.
                    function stripecreateplan as c ()
                    dim cf_1 as extension::CurlFile
                    dim flag_1 as l
                    dim ce as extension::Curl

                    ce = extension::Curl.Init()
                    ce.setOpt("URL","https://api.stripe.com/v1/plans")
                    ce.setOpt("NOPROGRESS",1)
                    ce.setOpt("USERPWD","sk_test_sometestnumber:")
                    dim posted_fields as c = ("amount=40000&interval=month&product[name]=seven&currency=usd&id=seven")
                    ce.setOpt("POSTFIELDS",posted_fields)
                    ce.setOpt("POSTFIELDSIZE_LARGE", len(posted_fields) )
                    ce.setOpt("USERAGENT","curl/7.34.0")
                    ce.setOpt("MAXREDIRS",50)
                    ce.setOpt("CAINFO",a5.Get_Exe_Path()+"\caroot\ca-cert.pem")
                    ce.setOpt("CAPATH",a5.Get_Exe_Path()+"\caroot")
                    'ce.setOpt("SSH_KNOWNHOSTS","C:\Users\Robert Senski\AppData\Roaming/_ssh/known_hosts")
                    ce.setOpt("TCP_KEEPALIVE",1)
                    ce.SetOpt("FILE",cf_1)
                    flag_1 = ce.Exec()
                    if flag_1 then
                    'dim headers as c
                    'dim contents as c
                    'dim msg as c
                    'headers = cf_1.GetHeaders()
                    'contents = cf_1.GetContent()
                    'msg = "Headers: " + crlf() + headers + crlf() + "Content: " + contents
                    stripecreateplan = "True"
                    else
                    'dim errors as c
                    'errors = ce.error()
                    stripecreateplan = "False"

                    end if
                    ce.close()
                    end Function
                    exports.createplan = stripecreateplan
                    Calling Function
                    function f1 as c (e as p)
                    debug (1)
                    dim xb1 as p
                    xb1 = require("module1")

                    f1 = "alert ('"+xb1.createplan() +" ');"
                    end function
                    Don't understand how the logical test is suppose to work at
                    flag_1 = ce.Exec()
                    if flag_1 then
                    Last edited by bob9145; 03-05-2018, 05:23 PM.

                    Comment


                      #25
                      Re: function Xbasic module

                      There are 2 levels of errors we're dealing with here. flag_1 = ce.Exec() checks to see if ce.Exec() itself ran without error... not if the Stripe command it is executing was successful or not. Here's how to test...

                      Change https://api.stripe.com/v1/plans to https://api.stripeyyyyyyy.com/v1/plans. This will return false to flag_1. ce.Exec() as a call will now fail.

                      The Stripe plan error you're looking for is in the true section of the flag_1 test... within the Contents variable. That's where you'll get the Stripe message that something is wrong. ce.Exec() is a successful call... but the Stripe API command executed isn't successful.

                      Comment


                        #26
                        Re: function Xbasic module

                        Gotcha Thanks!

                        Comment


                          #27
                          Re: function Xbasic module

                          Parsing a successful response using
                          dim response as p
                          response = json_parse(contents)
                          reponse.product
                          response.ect....
                          That works well but it doesn't include response.error, or response.type. However the error message is in the contents variable.
                          { "error": { "type": "invalid_request_error", "message": "Plan already exists." } }
                          How can I parse out type, and message? Seems the script generated by the curl genie, doesn't address an error returned by stripe. only as Dave points out a uncompleted curl.

                          Comment


                            #28
                            Re: function Xbasic module

                            You've got either a good response or an error response. You know the contents of both. Just check for an error first...

                            Code:
                            	if variable_exists("response.error") then
                            		'we know we have an error
                            		dim errType as c = response.error.type
                            		dim errMsg as c = response.error.message
                            	else
                            		'all good		
                            	end if
                            Last edited by Davidk; 03-07-2018, 12:27 AM.

                            Comment


                              #29
                              Re: function Xbasic module

                              I was trying that, must of had a typo. Trying to return the response pass, fail, or unsuccessful back to controls in the ux . Almost there! "All Good" ? not yet someday maybe lol

                              Comment


                                #30
                                Re: function Xbasic module

                                Getting some strange behavior from variable_exists() it is doing it's job but is throwing an error. Check out the attached jing. It works if the variable exists and is true, but it throws an error when it is false.variable_exists.swf

                                Comment

                                Working...
                                X