How to send http 200 to paypal ipn
alloy_bacon
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Oct-05-2018
02:57 PM
Hi, when my tcp socket server receives the paypal ipn from 173.0.81.1 im supposed to send back an http 200 so that paypal does not repeat the message 15x, its not a problem getting the message 15x but it is more bandwidth and it does help if I resond with http 200 through tcp, so how should I send it, here is my script if you need. import flash.display.Sprite; import flash.events.Event; import flash.events.ProgressEvent; import flash.events.ServerSocketConnectEvent; import flash.net.ServerSocket; import flash.net.Socket; import flash.utils.ByteArray; import flash.net.FileReference; import flash.filesystem.File; import flash.filesystem.FileMode; import flash.filesystem.FileStream; var serverSocket:ServerSocket = new ServerSocket(); var clientSocket:Socket; var clientObject = {}; var pid:Number=0; var _function:String; var completeString:String; var parsedString:String; var fr:FileReference = new FileReference(); var FileName:URLLoader; var f:File = new File(); var fs:FileStream; var fr2:FileReference = new FileReference(); var FileName2:URLLoader; var f2:File = new File(); var fs2:FileStream; var memberPackages=["001",28,"Digital Goods 001",31,"Digital Goods 002",93,"Digital Goods 003",365]; function register_account(a,b){ if(a!=undefined&&b!=undefined){ FileName=new URLLoader(); f=File.documentsDirectory; f=f.resolvePath("storage_lock/paypal/"+a+".txt"); if(f.exists){ if(b.split("mc_gross=")[1].split('.')[0]=="-0"&&f.size!=0){ fs = new FileStream(); fs.open(f, FileMode.WRITE); fs.writeUTFBytes(""); fs.close(); trace("negative"); MovieClip(root.parent).modify_membership_for(memberPackages[memberPackages.indexOf(b.split("item_number=")[1].split("~")[0])+1],b.split("custom=")[1].split("~")[0],true) } }else{ fs = new FileStream(); fs.open(f, FileMode.WRITE); fs.writeUTFBytes(b); fs.close(); if(b.split("custom=")[1].split("~")[0]!=b){ MovieClip(root.parent).modify_membership_for(memberPackages[memberPackages.indexOf(b.split("item_number=")[1].split("~")[0])+1],b.split("custom=")[1].split("~")[0],false) } } //do something at end? }else{ } } function load_new_player(a,b){ trace("Current port set"); currentPort=a; bind(); } var generatedNumber:String; function randomRange(minNum:Number,maxNum:Number):Number{ return (Math.floor(Math.random()*(maxNum - minNum + 1))+minNum); } function onConnection(e:ServerSocketConnectEvent){ pid++; clientSocket = e.socket; clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, onClientSocketData); clientObject[(clientSocket.remoteAddress).toString()+":"+(clientSocket.remotePort).toString()] = {"pid":pid, connection:e.socket, "msg_num":0,paypal_vars:""}; log("in connected" + pid + (clientSocket.remoteAddress).toString() + "_" +(clientSocket.remotePort).toString()); } var msg_num:Number=0; var nullByte:String=""; var temp_name=""; var error_log=""; var ipn_vars:Array =new Array(); var _functionList = {"name":null,"register":null,"path":null,"tokens2":null,"mapsize":null,"loadmap":null}; function onClientSocketData(e:ProgressEvent){ clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].msg_num++; var buffer:ByteArray = new ByteArray(); var temp_Bytes:ByteArray= new ByteArray(); e.currentTarget.readBytes(buffer, 0, e.currentTarget.bytesAvailable); try{ completeString = buffer.toString(); for(var bu=0;bu 2 && clientObject[od].connection.connected){ trace("broadcasting " +a); clientObject[od].connection.writeUTFBytes(a + nullByte); clientObject[od].connection.flush(); } } } function log(a){ trace(a); }
1 REPLY 1
alloy_bacon
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct-02-2020
11:01 PM
Ok this issue is resolved by sending the http 200 string back to the socket as follows in response to the ipn client connection from paypal while the connection is still open:
if((e.currentTarget.remoteAddress).toString()=="173.0.81.1"){
trace(completeString)
clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.writeUTFBytes(
'HTTP/1.1 200 OK'+'\n'+
'Server: MangoWave'+'\n'+
'Content-Type: text/html; charset=UTF-8'+'\n'+
'Content-Encoding: UTF-8'+'\n'+
'Accept-Ranges: bytes'+'\n'+
'Connection: keep-alive'+'\n'+'\n'+nullByte);
clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.writeUTFBytes('VERIFIED')
clientObject[(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString()].connection.flush();
setTimeout(bootUser,5000,(e.currentTarget.remoteAddress).toString()+":"+(e.currentTarget.remotePort).toString())
}
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- IPN works in sandbox but not live in Sandbox Environment
- User is asked for shipping address when creating a credit card order in REST APIs
- Webhook notifications are not being sent to my server in REST APIs
- Handling payouts that are being on hold/blocked in REST APIs
- When I do PayPal capture Order, I keep on getting Invalid Request Connection in REST APIs