-
-
Save alpeb/4384401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import com.micronautics.paypal.PaypalTransaction | |
import play.api._ | |
import play.api.mvc._ | |
object PayPalController extends Controller { | |
var live = true | |
def url = | |
if (live) | |
"https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate&" | |
else | |
"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate&" | |
def ipn = Action(parse.tolerantFormUrlEncoded) { | |
request => | |
val queryString = request.body.toString | |
Logger.info("Paypal request: " + queryString) | |
Logger.info("Verifying request: " + url + queryString) | |
val response = io.Source.fromURL(url + queryString).mkString.trim | |
if (response != "VERIFIED") { | |
Logger.warn("Could not verify PayPal call " + "Verification response: " + response) | |
BadRequest("Verification response: " + response) | |
} else { | |
if (request.body.get("payment_status").exists(_ == "Completed")) { | |
val reqStr = request.body.toString | |
val dataMap = BodyParserUtils.parseTextAsFormUrlEncodedForJava(reqStr) | |
new PaypalTransaction(dataMap).processTransaction() | |
Ok | |
} else { | |
// what situation arises to get us here? | |
Ok | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment