• khillan Singh
  • NEWBIE
  • 0 Points
  • Member since 2013
  • Khillan Singh
  • Astrea IT Service


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi All,

         I am try to do payment by using Paypal gateway.I use following code:

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 = '';
  }
 
 
  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;
}

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 void pay1(){
     pay();
}
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;
   } 
  System.debug('err------+++++-------'+err);
   message = err;
   if (err == '')
   {
     message = doDirectPayment();
   }else{
       apexpages.addmessage(new Apexpages.Message(ApexPages.Severity.ERROR,err));
   }
  
   if (message == 'Success')
   {
    
   }
   else
   {
     //pr = null;
   }
   return message;
}

}

Add the Url to Remote Site Setting: https://api-3t.sandbox.paypal.com  but in response itt give response like follow:

<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 give some suggesstion

thanks
Khilan Singh
Hi ,

I need to integrate of beanstream with salesforce. i have create sanbox of beanstream. Can some once let me know the apex code  for intregation with beansstream

Thanks
Khillan Singh
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;
}

"
Hi
I have one picklist in opportunity
based on that picklist value i need to fetch the all products.
What i need is i need to create a button to search all products

Example: i craeted one opportunity with pick list value " Inernet banking "
when click on add products i need fetch all products  have inertnet banking
how can i do it can any one tell me.


Regards
Venkatesh.