Jump to content

Recommended Posts

:confused:    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]

Link to comment
https://forums.phpfreaks.com/topic/204548-help-connecting-to-payment-api/
Share on other sites

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;
}


}

}
?>

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?

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

)

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.