1,105,375 Community Members

paypal sandbox payment and return to website

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi ,

I am struggling for two to make test payment through paypal sandbox but after entering user and password simply received this image attached.I want to pay through paypal using paypal's sandbox for testing and retrund to my website (localhost) giving confirmation in "confirm.php" , here is my paypal code:

$strform="<form target='paypal' action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post'>
                                      <input type='hidden' name='cmd' value='_s-xclick'>
                                      <table>
                                          <tr>
                                              <td><input type='hidden' name='on0' value='Products'>Products</td>
                                          </tr>
                                          <tr>
                                            <td>
                                              <select name='os0'>
                                                  <option value='WiseImage'>WiseImage $68.00 USD</option>
                                                  <option value='WiseScan'>WiseScan $126.00 USD</option>
                                                  <option value='EDA'>EDA $83.00 USD</option>
                                               </select> 
                                            </td>
                                          </tr>
                                       </table>
                                       <input type='hidden' name='currency_code' value='USD'>

<input type='hidden' name='return' value='http://localhost/csoftworld/paypalinvoice/thanks.php' />

                                                                                   '>
                                      <input type='image' src='https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online! '>
                                      <img alt='' border='0' src='https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'>
                                  </form>";
                                  echo $strform;

can any one post steps?(I tried most of the examples but not matching)

Thanks in advance

Subrata

Attachments sandbox.png 58.73KB
Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

Is that all your codes? No IPN listener or anything to grab the response from paypal?

If possible try practicing on this one . The sample script is in the example directory.

Let us know about your progress. If you find any problem with the script, let me know so that I can update my forked version.

!UPDATE! Here is a much detailed tutorial from Dan Dawson .

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
1
 

Just to follow up.. If you will be using Micah's class, you will have to set your form like this

This will be on the storefront with the payment button or whatever settings you prefer.

First, open the ipn.php file and fill-in your paypal sandbox credentials. As shown by the lifted snippets from the ipn.php

     mail('YOUR EMAIL ADDRESS', 'Verified IPN', $listener->getTextReport());

} else {
    /*
    An Invalid IPN *may* be caused by a fraudulent transaction attempt. It's
    a good idea to have a developer or sys admin manually investigate any 
    invalid IPN.
    */
    mail('YOUR EMAIL ADDRESS', 'Invalid IPN', $listener->getTextReport());
}

Remember that the email address is the email address of the vendor you have created in the paypal sandbox, and the buyer must use the email address of the created buyer account.

Two, the storefront form can be as simple as this

    <?php

    ## define the location of the ipn.php
    $ipn = 'ipn.php';
    ## define the sandbox seller email addresss created from step one.
    $seller_email = "seller@yourDomain.com";
    ## define the item you are selling
    $item = 'ipad';
    $item_price = 600.00;
    $currency = 'USD'; // define your currency
    $return_url = 'YourSite.com';

    ?>
    <!-- show the form -->

    <form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" 
method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $seller_email;?>">
<input type="hidden" name="currency_code" value="<?php echo $currency;?>">
<input type="hidden" name="item_name" value="<?php echo $item;?>">
<input type="hidden" name="amount" value="<?php echo $item_price;?>">
<input type="hidden" name="return" value="<?php echo $return_url;?>">
<input type="hidden" name="notify_url" value="<?php echo $ipn;?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif" 
    border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

That's pretty much it.. paypal capable page with less than a page of codes php and html :)..

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi veedeoo ,
Thanks and it is done ,mail is sending within sandbox ,is successful .Now ,an another issue within is ,after payment ,the page will go to invoicing site tripletex.no to generate invoice to the seller/buyer. What are the steps to generate invoice from tripletex.no to seller/buyer and return to website ?

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

Do you have the basic tripletex basic syntax recommendation? I mean , how to handle or port the data to their application?

On success, paypal would send an array of response of which you will be able to either add them to your database, or send it somewhere else. If you look at the ipn listener, the IPN response is stored in variable response.

IPN response..

     $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));

     ## and response for the non-cURL
      $this->response .= $status = fgets($fp, 1024); 
      $this->response_status = trim(substr($status, 9, 4));
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi veedeoo ,

I have the tripletex basic which has the link as pdf here http://tripletex.no/resources/api/tripletex-api.pdf.The and the other links are given below where codes are given.
http://json-rpc.org/
https://tripletex.no/JSON-RPC
http://json-rpc.org/wiki/implementations
just to integrate tripletex.no where .php page will send parameters to tripletex invoice system and tripletex will send/mail invoice to respective customer/buyer as pdf or csv or doc .

Thanks
Subrata

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

The pdf file link is dead..

To send a jason to the tripletex, the recieved response from paypal can be forwarded to the tripletex..

example...

 ## response from paypal..this may contain payment, item, amount, quantity, subscriptions.
 $this->response_status = strval(curl_getinfo($ch, CURLINFO_HTTP_CODE));

 ## stablish a filtering mechanism to make sure response is true..
 if($this->response_status){

 ## use jason_encode the data recieved from paypal
 $paypal_data = json_encode($this->response_status);  

 ## stablish a new cURL connector for the tripletext
 ////////// put all cURL 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
'Content-Type: application/json',                                                                                
'Content-Length: ' . strlen($paypal_data))                                                                       
);       

If the data from paypal does not match the API format of the TRIPLETEX, then you can either add data to the paypal response or reiterate through the response array and just remove what is not needed.

To add mor data into the array response from paypal, you can use array_push(). Something like this. For example paypal response is given like this

    ## example of paypal response, shown as an array

    $paypal_data = array('success'=>'true','item'=>'ipad','confirmation_id'=>'1235488','amount'=>'15.00','currency'=>'USD');

If you need to add more data as per tripletex requirements, you can do it like this.

array_push($paypal_data,'inventory'=>'100','sold'=>'50','receipt'=>'45597798','t_id'=>'1235488')
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi veedeoo,

Thanks for the response.link is not dead ,there was mismatch of url . Now what I have given is correct and opening .
http://tripletex.no/resources/api/tripletex-api.pdf

Thanks,

Subrata

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

thanks for bringing that up... I will look at throughly later..

For the time being you may want to experiment by sending the cURL post request to https://tripletex.no/JSON-RPC . The common response from tripletex if we send an empty data to this url will be

{"error":{"code":590,"msg":"couldn't parse request arguments"}}

That response will enable us to create a cURL function using the proper protocol as described in the documentation.

Without reading the documentation in its entirety, they want us to send request in this format as shown in their JAVA recommendation.. here is an excerpt of the JAVA code..

public static void main(String[] args) throws Exception {
HttpClient httpClient = new HttpClient();
PostMethod method = new PostMethod("https://tripletex.no/JSON-RPC");
String request1 = "{\"method\": \"Sync.login\", \"params\":
[7,\"test246\",\"test@test.no\",\"pwd\"], \"id\": 1}";

What the JAVA code above is requesting a method login, and sending the user password and id to the tripletex.no/JSON-RPC()..

Now, the challenge is how are we going to create the same functionality in PHP.. Keep in mind that tripletex requires us to have the cookies, and not only a cookie, but specifically they want the second cookie from the two outputted by the server.

here is the typical tripletex response along with two cookies and they want the second one..

RESPONSE:
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.4; JBoss-4.0.2 (build: CVSTag=JBoss_4_0_2
date=200505022023)/Tomcat-5.5
Set-Cookie: JSESSIONID=09E2172BB69BA99F9CBA3AD9C0F2A025; Path=/; Secure
Set-Cookie: JSESSIONID=F81885A42D1CC3876039EAB8C441C5B3; Path=/; Secure
Content-Type: text/plain;charset=utf-8
Content-Length: 29
Date: Wed, 21 Jul 2010 06:59:38 GMT

Tripletex wants to validate on the second cookie from the response. This is all they want..

  Set-Cookie: JSESSIONID=F81885A42D1CC3876039EAB8C441C5B3; Path=/; Secure

Now we already done witht the layout, target url, data types, and requirements. The last thing we need to know about this API is the method of http request.. is it GET, POST or Hybrid? If look at the JAVA code example, we easily see that the JAVA sends the data by post method.

new PostMethod("https://tripletex.no/JSON-RPC");

Now, the fun and excruciating part of being a developer is translating the JAVA example to PHP and utilizing the cURL to tap into the external environment.

**WARNING! **I have not tested this script and this is primarily intended as a building block, this may work and it may NOT. However, the most important of building an application is the building block and we can build from it.. eliminate things that are already proven to be faulty or not functional in the intended environment.

!IMPORTANT! We will attempt to store both cookie first in the cookiejar and lets hope the API will find it acceptable once it knows that the second one is there.

Step 1. Create a directory called cookie, make sure this writtable.. 0777 will do it on the test site but for the production server, it is nice to have it in minimum writtable at 0755 ( it depends if running on fast CGI or not).

Step 2. Layout the cURL connector, while ignoring the Paypal API response. We don't want sending any actual data yet, until we are sure that our application is able to communicate, post, and retrieve information from the remote script.

!IMPORTANT! In the manual, there is terminology called method of invocation. The method of invocation in JAVA for this API is like this

 {method": "Sync.login", "params": [7,"pwd","json@test.no","pwd"], "id": 1}

My un-educated guess of the above invocation protocol can be express in PHP as this..

$methodData = array('method'=>'Sync.login','params'=>array(7,'pwd','jason@test.no','pwd'),'id'=>1);
## now we use json_encode function
$methodData = json_encode($methodData);

**!IMPORTANT! **when bridging the Paypal API response, you may need to include the response array.. I believed paypal API response is already in JSON encoded format, so you may not need it here, just use array_pust after the methodData..

here we go... live scripting on a textbox... only in Daniweb :)

## lets setup the target API url 
$url = 'https://tripletex.no/JSON-RPC';
## define the cookie directory wher the cookie recieved will be stored
$cookie_bin = 'cookie/cookie.txt'; // as described in step 1

## lets initialize the curl.. if this method does not work you can use the commented option below.

$ch = curl_init($url);
## we might not need this for now
//curl_setopt($ch, CURLOPT_HEADER, 0); 

## we define where to store and check for cookies
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_bin);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_bin);

## we try this first
curl_setopt($ch, CURLOPT_POSTFIELDS, $methodData);
## if the above does not work, uncomment below
//curl_setopt($ch,    CURLOPT_CUSTOMREQUEST, "POST");

## we need to witheld the paypal data for now.
//curl_setopt($ch, CURLOPT_POSTFIELDS, $methodData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, 
## we notify the remote server of the content type and the lenght of the entire methodData string
array('Content-Type: application/json',
'Content-Length: ' . strlen($methodData)) );  

## finally, we will use either var_dump or print_r to view the respnse of the remote server..

var_dump(curl_exec($ch);

If you get a successfull transaction with the remote server.. you should be able to view some response on the page... to decode them all you have to do is

var_dump(jason_decode(curl_exec($ch));

Step 3 to Step ???? , debug, clean up the codes, test run, until you get the results acceptable to API standards.

!IMPORTANT! You need to read the cURL documentation here.. most importantly this function CURLOPT_CUSTOMREQUEST. Some API does not allow this or will not respond to this method.

That's pretty much it.... that should conclude my semester break... I need to read my textbooks that were collecting dust on my table for 6 weeks now..

Good Luck to you.. I am pretty sure, the script above just needs a minor tweaking and it will be functional.

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

Please allow me to just add these info., because I am sure you will be asking how to create a remote CSV file using the API..

I will be using this as example, the integer coding guideline is located in the last page of the documentation.. I believe this is an example of a CVS file 1 as indicated on the id.

{"method": "Project.importOrdersTripletexCSV", "params": [";2010-01-01;10010;Tripletex;Kronprinsensgt.17;;251;Oslo;post@tripletex.no;;;;;1111;2010-03-01;Leveranseveien14;\"'Dette er en kommentar;;;;;;;;;1000;;3;Ordrelinje (h\u00f8ysats);\r\n","ISO-8859-1",true, false], "id": 1}

First, you can initialize the cURL to

$ch = curl_init('https://tripletex.no/resources/examples/order_import_example.csv');

Then you define your CVS data... values can be from database or from any resources you may have. Here is the equivalent post request in PHP

 $csv_data = array('method'=>'Project.importOrdersTripletexCSV','params'=>array('put all the data here'),'id'=>1);

  $csv_data = jason_encode( $csv_data);
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Dear Veedeoo ,

For curl_init and curl_setopt gives the error "Fatal error: Call to undefined function curl_setopt() "

Subrata

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Dear Veedeoo ,

Overall the code is not working ,so if you post a tested code will help me to proceed further.

Thanks
Subrata

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Veedeoo ,

Sorry ,it is working giving the output "boolean false null" but if you post some methods like "Sync.createTripletexAccount ,Sync.login , importInvoicesTripletexCSV " will help me to proceed further because I emphasising on "importInvoicesTripletexCSV" method .

Thanks

Subrata

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Dear Vedeoo ,

I understood that you are very busy reading text books ,but after too much struggle I was failure to retrieve csv file . When I send some information to tripletex this will return and mail invoice in csv/pdf format which is not executing . very urgent I will have to submit the project at the earliest.

Thanks
Subrata

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Dear Vedeoo ,

Thanks for the post, it is done.I am giving in details who is integrating tripletex in web service.
1. Create your user and password in tripletex.no
2. For default sync id 7 ,ask tripletex to send password and tripletex will send.
3. In the above code write like this .

$methodData = array('method'=>'Sync.login','params'=>array(7,'sync pwd','your user/email in tripletex','your pwd in tripletex'),'id'=>1);

Then write down the above code . Don't run from localhost because this will not return proper value. Upload the file then run from browser . But returning of file and send it to the mail is not done yet.

Member Avatar
oop_php
Newbie Poster
15 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

I am sure Veedeoo will be very happy to see your progress has been a positive one. The kid is busy on his schooling... He texted me a while ago, and we will be the acting Physics professor on Monday. Barely, glancing in becoming 20yo, I wish I was like this kid when I was his age..

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Dear veedeoo and opp_php ,

I am also very happy with you . One more thing is left .What next code veedeo sent "putting data to csv file and mail csv file as attachment to the email(customer is not working ). If veedeoo can post this my job will be over.

Thanks both of you

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Dear Veedeoo ,
Your code helped me a lot to proceed integration of tripletex and done . Tripletex is sending mail from my website and my task done. Thanks again veedeoo.

Thanks

Question Answered as of 1 Year Ago by veedeoo and oop_php
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: