function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
saurav_khuranasaurav_khurana 

Paypal Intergration with salesforce...

Can anybody help finding me the way how to refund amount from paypal and get balance enqiry using salesforce.

I already done successful integration with salesforce and paypal and my class is working for making payements to sandbox account of paypal using my VF page through the s=following controller and vf page.

 

Kartik PerisetlaKartik Perisetla

Hi Saurav,

 

I assume you must be consuming Web services for making payments through PayPal. There must be similar web service interface for getting balance enquiry and amount refund which can be consumed in Salesforce.com apex class.

 

 

Cheers !

saurav_khuranasaurav_khurana

Hi Kartik 

 

 Thanks for your help could you please help me more i cannot implement that refund and get balance through my class while i called the api method do direct payemnt in itself .

 Please find below my apex code .


Thanks in advance .

Regards,

Sorabh 

 

 

public class CT_PaypalProcessor {
public string amount{get; set;}
public String result {set;get;}
public string FirstName{get; set; }
public string LastName{get; set; }
public string Addy1{get; set; }
public string Addy2{get; set; }
public string Country{get; set; }
public string CardType{get; set; }
public string CardNo{get; set; }
public string expMo{get; set; }
public string expYe{get; set; }
public string CVV{get; set; }
public string city{get; set; }
public string state{get; set; }
public string zip{get; set; }
public string payer{ get; set; }
public string transid {get; set;}
public string message {get; set; }
public string err {get; set; }
public string rawResponse {get; set; }

public CT_PaypalProcessor(){
// city = 'NYC';
state = 'NY';
zip = '23233';
// CVV = '369';
expYe = '2012';
expMo = '03';
// CardNo = '4169826260837999';
// CardType = 'Visa';
// FirstName = 'saurav';
// LastName = 'khurana';
Country = 'US';
// Addy1 = 'G-13 Noida';
Addy2 = '';
payer = 'test@cloudsteer.com';
//amount = '500';
}

public void loadPage() {
system.debug('---------Pay()-----------' + this.pay());
}

public String doDirectPayment()
{

Http h = new Http();
HttpRequest req = new HttpRequest();
String url = 'https://api-3t.sandbox.paypal.com/2.0/';
string un = 'saurav_1331792090_biz_api1.gmail.com';
string pw = '1331792130';
string sig = 'AIfJWYD9IJU3IITi0kVhvZ-J-c2nA5Il5mGirwYMqXMxDT8fB34iiDOd';


String doDirectRequest;
doDirectRequest = '<soap:Envelope xmlns:soap=' + '\'' + 'http://schemas.xmlsoap.org/soap/envelope/' + '\'' + ' xmlns:xsi=' + '\''+ 'http://www.w3.org/2001/XMLSchema-instance' + '\'' + ' xmlns:xsd=' + '\''+ 'http://www.w3.org/2001/XMLSchema' + '\'' + '>';
doDirectRequest += '<soap:Header><RequesterCredentials xmlns="urn:ebay:api:PayPalAPI"><Credentials xmlns="urn:ebay:apis:eBLBaseComponents">';
doDirectRequest += '<Username>' + un + '</Username><ebl:Password xmlns:ebl="urn:ebay:apis:eBLBaseComponents">' + pw;
doDirectRequest += '</ebl:Password><Signature>' + sig + '</Signature>';
doDirectRequest += '</Credentials></RequesterCredentials></soap:Header><soap:Body><DoDirectPaymentReq xmlns="urn:ebay:api:PayPalAPI">';
doDirectRequest += '<DoDirectPaymentRequest><Version xmlns="urn:ebay:apis:eBLBaseComponents">1.00</Version>';
doDirectRequest += '<DoDirectPaymentRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">';
doDirectRequest += '<PaymentAction>Sale</PaymentAction><PaymentDetails><OrderTotal currencyID="USD">' + amount + '</OrderTotal>';
doDirectRequest += '<ShipToAddress><Name>' + FirstName + ' ' + LastName + '</Name><Street1>' + Addy1 + '</Street1><Street2>' +Addy2 + '</Street2>';
doDirectRequest += '<CityName>' + city + '</CityName><StateOrProvince>' + state + '</StateOrProvince><PostalCode>' + zip + '</PostalCode>';
doDirectRequest += '<Country>' + country + '</Country></ShipToAddress>';
doDirectRequest += '</PaymentDetails><CreditCard><CreditCardType>' + CardType + '</CreditCardType><CreditCardNumber>' + CardNo + '</CreditCardNumber>';
doDirectRequest += '<ExpMonth>' + expMo + '</ExpMonth><ExpYear>' + expYe + '</ExpYear><CardOwner><PayerStatus>verified</PayerStatus>';
doDirectRequest += '<PayerName><FirstName>' + FirstName+ '</FirstName><LastName>' + LastName + '</LastName></PayerName><PayerCountry>' + country + '</PayerCountry>';
doDirectRequest += '<Address><Street1>' + Addy1 + '</Street1><Street2>' + Addy2 + '</Street2><CityName>' + city + '</CityName>';
doDirectRequest += '<StateOrProvince>' + state + '</StateOrProvince><Country>' + country + '</Country><PostalCode>' + zip + '</PostalCode></Address>';
doDirectRequest += '</CardOwner><CVV2>' + CVV + '</CVV2></CreditCard></DoDirectPaymentRequestDetails>';
doDirectRequest += '</DoDirectPaymentRequest></DoDirectPaymentReq></soap:Body></soap:Envelope>';

req.setBody(doDirectRequest);

req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-length', '1753' );
req.setHeader('Content-Type', 'text/xml;charset=UTF-8');
req.setHeader('SOAPAction','');
req.setHeader('Host','api-aa.sandbox.paypal.com');
HttpResponse res = h.send(req);

String xml = res.getBody();
rawResponse = xml;
system.debug('---------xml-----------' + rawResponse);
XmlStreamReader reader = res.getXmlStreamReader();
result = readXMLResponse(reader,'Ack');
system.debug('---------result-----------' + result);
reader = res.getXmlStreamReader();
err = readXMLResponse(reader, 'LongMessage');

if (result == 'Success')
{
reader = res.getXmlStreamReader();
transid = readXMLResponse(reader, 'TransactionID');
system.debug('---------transid-----------' + transid);
}
else
{
result = err;
}
return result;
}

public String readXMLResponse(XmlStreamReader reader, String sxmltag)
{
string retValue; // Read through the XML
while(reader.hasNext())
{
if (reader.getEventType() == XmlTag.START_ELEMENT)
{
if (reader.getLocalName() == sxmltag) {
reader.next();
if (reader.getEventType() == XmlTag.characters)
{
retValue = reader.getText();
}
}
}
reader.next();
}
return retValue;
}

public String pay(){

err = '';
if (FirstName == '')
err = err + 'You must enter a First Name.\n';
if (LastName == '')
err = err + 'You must enter a Last Name.\n';
if (Addy1 == '')
err = err + 'You must enter an Address.\n';
if (city == '')
err = err + 'You must enter a City.\n';
if (state == '')
err = err + 'You must enter a State.\n';
if (zip == '')
err = err + 'You must enter a Zip.\n';
if (CardNo == '')
err = err + 'You must enter a Credit Card Number.\n';
if (expMo.length() != 2)
err = err + 'Expiration month must be in the format MM.\n';
if (expYe.length() != 4)
err = err + 'Expiration year must be in the format YYYY.\n';

if (amount == '0')
{
err += 'Amount 0 can not process.\n';
message = err;
}
message = err;
if (err == '')
{
message = doDirectPayment();
}

if (message == 'Success')
{

}
else
{
//pr = null;
}
return message;
}

}

Kartik PerisetlaKartik Perisetla

Hi Saurav,

 

I went through the code you gave. I uncommented few details like card number,etc and ran the method doDirectPayement().

It gave this response:

 

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:ed="urn:ebay:apis:EnhancedDataTypes" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:ns="urn:ebay:api:PayPalAPI">
<SOAP-ENV:Header>
<Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xsi:type="wsse:SecurityType"/>
<RequesterCredentials xmlns="urn:ebay:api:PayPalAPI" xsi:type="ebl:CustomSecurityHeaderType">
<Credentials xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:UserIdPasswordType">
<Username xsi:type="xs:string"/>
<Password xsi:type="xs:string"/>
<Signature xsi:type="xs:string"/>
<Subject xsi:type="xs:string"/>
</Credentials>
</RequesterCredentials>
</SOAP-ENV:Header>
<SOAP-ENV:Body id="_0">
<DoDirectPaymentResponse xmlns="urn:ebay:api:PayPalAPI">
<Timestamp xmlns="urn:ebay:apis:eBLBaseComponents">2012-04-02T12:16:25Z</Timestamp>
<Ack xmlns="urn:ebay:apis:eBLBaseComponents">Failure</Ack>
<CorrelationID xmlns="urn:ebay:apis:eBLBaseComponents">b6678902f2554</CorrelationID>
<Errors xmlns="urn:ebay:apis:eBLBaseComponents" xsi:type="ebl:ErrorType">
<ShortMessage xsi:type="xs:string">Invalid Data</ShortMessage>
<LongMessage xsi:type="xs:string">This transaction cannot be processed. Please use a valid credit card.</LongMessage>
<ErrorCode xsi:type="xs:token">10502</ErrorCode>
<SeverityCode xmlns="urn:ebay:apis:eBLBaseComponents">Error</SeverityCode>
</Errors>
<Version xmlns="urn:ebay:apis:eBLBaseComponents">1.00</Version>
<Build xmlns="urn:ebay:apis:eBLBaseComponents">2649250</Build>
<Amount xsi:type="cc:BasicAmountType" currencyID="USD">500.00</Amount>
</DoDirectPaymentResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 

Please make sure you use valid data while working with external systems. I believe if you use valid card details, this will definately work.

 

I hope you find this solution helpful.

 

Cheers !