Ok
I been playing around with the sample code files that where given and have gotten somewhere but not sure about a couple things.
I have this
expresscheckout.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="expresscheckout.aspx.cs"
Inherits="PayPalEC" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form action='expresscheckout.aspx' method='post' runat="server">
<asp:ImageButton ID="ImageButton1" runat="server"
src='https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif'
onclick="ImageButton1_Click" />
</form>
</body>
</html>
codebehind
Code:
using System;
using System.Web;
using GenerateCodeNVP;
using System.Net;
using System.IO;
public partial class PayPalEC : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
ECSetExpressCheckout setCheckout = new ECSetExpressCheckout();
string result = setCheckout.ECSetExpressCheckoutCode("http://localhost:3300/return.aspx", "http://localhost:3300/cancel.aspx", "20", "Sale", "USD");
Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr&cmd=_express-checkout&token=" + result + "&AMT=20&CURRENCYCODE=USD&RETURNURL=http://localhost:3300/return.aspx&CANCELURL=http://localhost:3300/cancel.aspx");
}
}
So right now I am just had coded alot of the stuff. but my first question is with the one of their sample files
ECSetExpressCheckout.cs
Code:
/*
* Copyright 2005, 2008 PayPal, Inc. All Rights Reserved.
*
* SetExpressCheckout NVP example; last modified 08MAY23.
*
* Initiate an Express Checkout transaction.
*/
using System;
using com.paypal.sdk.services;
using com.paypal.sdk.profiles;
using com.paypal.sdk.util;
/**
* PayPal .NET SDK sample code
*/
namespace GenerateCodeNVP
{
public class ECSetExpressCheckout
{
public ECSetExpressCheckout()
{
}
public string ECSetExpressCheckoutCode(string returnURL,string cancelURL,string amount,string paymentType,string currencyCode)
{
NVPCallerServices caller = new NVPCallerServices();
IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
/*
WARNING: Do not embed plaintext credentials in your application code.
Doing so is insecure and against best practices.
Your API credentials must be handled securely. Please consider
encrypting them for use in any production environment, and ensure
that only authorized individuals may view or modify them.
*/
// Set up your API credentials, PayPal end point, API operation and version.
profile.APIUsername = "name";
profile.APIPassword = "pass";
profile.APISignature = "sig";
profile.Environment="sandbox";
caller.APIProfile = profile;
NVPCodec encoder = new NVPCodec();
encoder["VERSION"] = "51.0";
encoder["METHOD"] = "SetExpressCheckout";
// Add request-specific fields to the request.
encoder["RETURNURL"] = returnURL;
encoder["CANCELURL"] = cancelURL;
encoder["AMT"] = amount;
encoder["PAYMENTACTION"] = paymentType;
encoder["CURRENCYCODE"] = currencyCode;
// Execute the API operation and obtain the response.
string pStrrequestforNvp= encoder.Encode();
string pStresponsenvp=caller.Call(pStrrequestforNvp);
NVPCodec decoder = new NVPCodec();
decoder.Decode(pStresponsenvp);
return decoder["token"];
// return decoder["ACK"];
}
}
}
So they return decorder["ACK"] and this returns sucessful or failed. I don't' understand why it does not build the string for me? Like it has all the parts it could have easily built the required string yet I get a sucessful or failed.
I am not sure what it succeded into doing(testing to see the stuff can be transmited??).
Also how I see it I need to send with the set the token value. How do I get the token value? Like the only way I was able to get the token was returing that from the decoder if I did not do that I would have no clue how to get the token value.
When I do the response redirect I get to the paypal site. I am able to login and confirm my address(even though for mysite address does not really need an address since I won't send them anything).
I noticed though when there logged in I can see no where the price is listed on how much I sent to the site.
Like if I said the item would cost $20. I thought it would display this number to them while they where at paypal.
So then it gets returned to my return.aspx
return.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="return.aspx.cs" Inherits="paypalTest1._return" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>returned</h1>
</div>
</form>
</body>
</html>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GenerateCodeNVP;
namespace paypalTest1
{
public partial class _return : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.HttpMethod == "GET")
{
char[] ampersand = { '&','='};
string url = Request.RawUrl;
string[] splitArray = url.Split(ampersand);
ECDoExpressCheckout doNow = new ECDoExpressCheckout();
string test= doNow.ECDoExpressCheckoutCode(splitArray[1], splitArray[3], "20.0", "Sale", "USD");
}
}
}
}
Again I just used some hardcoded values and jsut looked at what postions the token and payerID was.
One thing I am not sure of is how do I keep track of how much there items cost? Like in my case I got 1 item and I know it is $20. I also know they only can purchase one quaity of it.
But what happens if I was sending a list of stuff from a cart. say $60 worth of stuff.
How do I keep track of the $60 when I return to another page and to finalize the transaction I must specify how much it will all cost.
How will I even know at this point what items they have bought?
So looking at the buyers account in my sandbox it takes the $20 off but I am not sure where that $20 goes. I have a sellers account setup too in my sandbox but it gets nothing. So I am guessing I am missing something still not sure what.
Does this look right what I have so far?