+ Start a Discussion
khillan bhardwajkhillan bhardwaj 

salesforce to paypal Intregation

Hi All,

I need to do payment from salesforce to paypal by using doDirectPayment method , in the i am getting Expception 'The element type "p" must be terminated by the matching end-tag "</p>".' I get the respponse in following form :'<HTML><HEAD>
<TITLE>Invalid URL</TITLE>
</HEAD><BODY>
<H1>Invalid URL</H1>
The requested URL "&#47;2&#46;0", is invalid.<p>
Reference&#32;&#35;9&#46;1ce0fc7d&#46;1387534802&#46;12140fd8
</BODY></HTML>'

please let me know where is the problem .The method written by me to for payment is :
"
public String doDirectPayment()
  {
   
    Http h = new Http();
    HttpRequest req = new HttpRequest();
  //String url = 'https://api-3t.sandbox.paypal.com/2.0';
    String url = 'https://api-3t.sandbox.paypal.com/2.0';
    string un = 'ksingh2-facilitator_api1.astreait.com';
    string pw = '1386759617';
    string sig = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AeW1L0989VvCKlBMtw6BBk5qEslE';
   
   
    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>';
    System.debug('---------------'+doDirectRequest );
    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();
    System.debug('xml----------------------'+xml);
    rawResponse = xml;
    system.debug('::' + rawResponse);
    XmlStreamReader reader = res.getXmlStreamReader();
    result = readXMLResponse(reader,'Ack');
    reader = res.getXmlStreamReader();
    err = readXMLResponse(reader, 'LongMessage');
   
    if (result == 'Success')
    {
      reader = res.getXmlStreamReader();
      transid = readXMLResponse(reader, 'TransactionID');
        system.debug('::' + transid );
    }
    else
    {
      result = err;
   }
   return result;
}

"
sfdcfoxsfdcfox
The only obvious piece that seems to be left out is you've left out a trailing slash on the URL. Try using https://api-3t.sandbox.paypal.com/2.0/ instead.
rishiravi1.3959884063722622E12rishiravi1.3959884063722622E12
Hello sfdcfox,
I am geeting same error in my debug log please advise ASAP
i have tryed with this https://api-3t.sandbox.paypal.com/2.0/ url as well but occurring same error.

khillan Singhkhillan Singh
public class PaypalProccessor{
   public  string amount;
   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 PaypalProccessor(){
    city = 'ajm';
    state = 'CA';
    zip = '4534';
    CVV = '';
    expYe = '2018';
    expMo = '12';
    CardNo = '4312559707914610';
    CardType = 'Visa';
    FirstName = 'khillan';
    LastName = 'singh';
    Country = 'US';
    Addy1 = '44';
    Addy2 = '433';
    payer = 'ksingh2@astreait.com';
    amount = '1';
    err = '';
    message = '';
  }
 
 // i have input some default values as above
  public String doDirectPayment()
  {
    try{
        Http h = new Http();
        HttpRequest req = new HttpRequest();
      //String url = 'https://api-3t.sandbox.paypal.com/2.0/';
        String url = 'https://api-3t.sandbox.paypal.com/2.0/';
        string un = 'ksingh2-facilitator_api1.astreait.com'; // marchachange account username
        string pw = 'XXXXXXXXXXXXXXXXXXXX';  // merchant password
        string sig = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AeW1L0989VvCKlBMtw6BBk5qEslE';  // marchange signature
       
       
        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>';
        System.debug('---------------'+doDirectRequest );
        req.setBody(doDirectRequest);
       
        req.setEndpoint(url);
        req.setMethod('POST');
        //req.setHeader('Content-length', '1753' );
        //req.setHeader('Content-Type', 'application/xml');
        //req.setHeader('SOAPAction','');
        //req.setHeader('Host','api-aa.sandbox.paypal.com');
        HttpResponse res = h.send(req);
        System.debug('res ----------------------'+res);
        String xml = res.getBody();
        System.debug('xml----------------------'+xml);
        rawResponse = xml;
        system.debug('::' + rawResponse);
        //XmlStreamReader reader = res.getXmlStreamReader();
        //result = readXMLResponse(reader,'Ack');
        //reader = res.getXmlStreamReader();
        //err = readXMLResponse(reader, 'LongMessage');
       
        if (result == 'Success')
        {
         // reader = res.getXmlStreamReader();
        //  transid = readXMLResponse(reader, 'TransactionID');
        //    system.debug('::' + transid );
        }
        else
        {
          result = err;
       }
   }catch(Exception e) {
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,'ERROR : '+e));
   }
   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;
}


this code is working fine i have check it in