cs3gallery Posted June 12, 2010 Share Posted June 12, 2010 I decided to finally be a man and come to the experts! I am new to php programming. Just a few months of experience. I am trying to run a script that I know is not advanced. However I cannot seem to figure it out and it seems somewhat confusing to me. So let me explain my situation. I currently am making a module for sugarcrm to connect to our payment gateway. The module will allow me to use a logic hook (meaning to run a script in the background depending on what I make as the trigger). However I can take care of that part. The part that I am stuck at is sending and receiving the information. Here is how the api works. After I pull the field information from the module and insert it into variables I submit it via a url like so: This is the url: https://secure.chargebackguardiangateway.com/api/transact.php The variables that come after would look like so: username=demo&password=password&type=sale&ccnumber=4111111111 111111&ccexp=0711&cvv=999&amount=10.00 of course the numbers and things will be stored in the variables from the fields. So for you to test it out just paste this in and press enter: https://secure.chargebackguardiangateway.com/api/transact.php?username=demo&password=password&type=sale&ccnumber=4111111111111111&ccexp=0711&cvv=999&amount=10.00 After taking a look at that you will notice how the response is received in basicly the same format. However instead of it being in the header it come only in the body in between the html tags. So my question is how do I go about submitting the information, receiving the information and putting that into variables to insert into the database? I appreciate all help. Thank You!! I have enclosed the api information in the pdf as an attachment. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/ Share on other sites More sharing options...
kenrbnsn Posted June 12, 2010 Share Posted June 12, 2010 Please post your script. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071045 Share on other sites More sharing options...
cs3gallery Posted June 12, 2010 Author Share Posted June 12, 2010 Here is what I have so far. Not sure if I am doing this right. <?php class Payment { // Initial Setting Functions function sendPayment(&$bean, $event, $arguments) { //create a new cURL resource $username = 'demo'; $password = 'password'; $type = $bean->type; $ccnumber = $bean->ccnumber; $ccexp = $bean->ccexp; $cvv = $bean->cvv; $amount = $bean->amount; $url = "https://secure.chargebackguardiangateway.com/api/transact.php"; $post = "?username=$username&password=$password&type=$type&ccnumber=$ccnumber&ccexp=$ccexp&cvv=$cvv&amount=$amount"; $type1 ='sale'; switch ($type) { case $type1: $ch = curl_init($url); //set URL and oter appropriate options curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_POST, 1); curl_close($ch); break; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071047 Share on other sites More sharing options...
backie Posted June 12, 2010 Share Posted June 12, 2010 From a quick glance try removing the "?" from the post data. I'll read the api docs and see if I notice anything else. Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071050 Share on other sites More sharing options...
cs3gallery Posted June 12, 2010 Author Share Posted June 12, 2010 Ok, Well, I just took out the ? from the beginning of the $post variable. Currently I receive no errors. So it must be working. However there really is no way for me to tell if it really is working since how it is a logic hook. It will only post errors like syntax errors etc. So looks to me like maybe the only thing left to do is grab the information after the post has been made. But my big question is how on earth do I get it then sort it then put it into variables to store into the db? Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071055 Share on other sites More sharing options...
backie Posted June 12, 2010 Share Posted June 12, 2010 Well I am not seeing a curl_execute call so, mabye do that and then format the return data? Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071056 Share on other sites More sharing options...
cs3gallery Posted June 12, 2010 Author Share Posted June 12, 2010 I dont know how to format the return data :'( Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071059 Share on other sites More sharing options...
backie Posted June 12, 2010 Share Posted June 12, 2010 Well from a quick glance at the api docs it would be a case of something like (Pretty sure there is a premade function to do this just can't think of it. <?php preg_match_all("~([a-z]+)=([a-z0-9]+)~",$Result,$Matches); $Results = array(); for ($i = 0; $i < sizeof($Matches[0]);$i++){ $Results[$Matches[1][$i]] = $Matches[2][$i]; } ?> $Results will return an array see below based upon $Results = "test=result&dkas=4h324jh"; Hope that's some help. Array ( [test] => result [dkas] => 4h324jh ) Quote Link to comment https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/#findComment-1071064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.