Monday, April 20, 2015

Worldpay Integration

Worldpay is online payment gateway which is used to make online payment. In worldpay there are two types of payments
  1. Oneoff Payment
  2. Recurring Payment

Oneoff Payment means instant payment or single payment. In this type of payment the payment is done at once.

Recurring Payment means multiple payments which can be done weekly , monthly or yearly. This type of payment has certain start date of payment.

When we register with Worldpay we will be given two separate URLs for each method of payment and currency set we will be using. One will be the URL for the Test Environment and the other will be the URL for the Production Environment.
Initially the integration is done with Test Environment. After being successful integration with Test Environment stuff can be copied from Test Enviornment to Production.

To integrate with Worldpay we need to hit following urls



Both urls need certain parameters. Some of them are mandatory and some optional.

Mandatory Parameters:-
1. instId : Your Worldpay Installation ID. This is a unique 6-digit reference number assigned to us. It tells us which payment methods and currencies your installation supports.
  1. cartId : A reference we assign to help us identify the purchase.
  2. Amount : The total cost of the purchase.
  3. Currency : The purchase currency
  4. testMode : 100 for Test Enviornment/0 for Production
After redirecting on Worldpay we will see the following screen

From here we can select any card type and will process for payment. After a successful payment a response is generated which can be used to trigger in our system after writing a server side script.

The redirection from Worldpay may be customize. It means after a successful payment if we wish that shopper may be redirected to our website.
To make redirection at requested url resultY and resultC files are used whose code may be customized. ResultY is for successful payment and resultC is for cancelled payment.
We can add our own details to the result page, in order to individualise each transaction. For example, we can add the shopper’s name, the product description and the cost.

Payment Response Message:-

We can set up and use the Payment Response messages feature, which enables us to automate and control ourwebsite. The Payment Response feature posts the payment information from Worldpay server to a URL on our server securely.




References:-

More details about Worlpay Integration may be get from following urls
If you need any sample apex code you may contact to me at excellencegaur@gmail.com.



~Vikas

Monday, October 6, 2014

Case Team via Apex

Hello Guys,

I am back with new topic. This time we all are going to discuss about Case Team Via Apex. So first of all let's brief discussion on  Case Team.
 A case team is a team of users that work together on a case. For example, your case team may include a support rep, support manager, and a product manager.

So the requirement is that whenever a new case is created then creator should be added in Case Team.
The user who edit the case , will be added on that case based on last modified.

To implement this you will need following two main things

  1.  Case Team Roles 
  2.  Related List of Case Team in Case detail page.  


trigger addTeamMembers on Case (after insert, After Update) {
   User Us = [SELECt id, name , profile.name from User WHERE id =: UserInfo.getUserId( )];
   if(checkRecursive.runOnce()){
   if(us.profile.name != 'TM Customer Community Login'){
       Map<Id, CaseTeamMember> membersToAdd = new Map<Id, CaseTeamMember>();
       if(trigger.isAfter){
            List<Case> cases = [Select Id,OwnerId, LastModifiedById from Case where id IN :Trigger.newMap.keySet()];
            if(trigger.IsInsert){
                for (Case c : cases) {
                      membersToAdd.put(c.Id, new CaseTeamMember(ParentId = c.Id, MemberId = UserInfo.getUserId( )));
                }
            }
            if(trigger.IsUpdate){
               for (Case c : cases) {
                      membersToAdd.put(c.Id, new CaseTeamMember(ParentId = c.Id, MemberId = c.LastModifiedById));
                } 
            }    
            if (!membersToAdd.isEmpty()) {
              try {
                CaseTeamRole caseTeamRole = [SELECT Id FROM CaseTeamRole WHERE Name = 'Immerti' LIMIT 1];
        
                for (CaseTeamMember ctm : membersToAdd.values()) {
                  ctm.TeamRoleId = caseTeamRole.Id;
                }
              for (CaseTeamMember ctm : [SELECT Id, MemberId, ParentId FROM CaseTeamMember
                                           WHERE ParentId IN :membersToAdd.keySet()
                                           AND MemberId = :UserInfo.getUserId()
                                           ORDER BY ParentId]) {
                 if (membersToAdd.containsKey(ctm.ParentId)) {
                    membersToAdd.remove(ctm.ParentId);
                  }
                }
                
                if (!membersToAdd.isEmpty()) {
                  insert membersToAdd.values();
                }
              } catch (System.QueryException qe) {}
           }
        }
      }else{
           User u1 = [SELECT id, name from User WHERE name = 'Carla Martin'];
           User u = [SELECT id, name from User WHERE name = 'Zina Sejdic'];
           set<Id> csId = new set<Id>();
           if(trigger.isInsert){
           if(trigger.isAfter){
               for(Case c : trigger.new){
                   csId.add(c.id);  
               }
             if(csId.size() > 0){
                  Case cs = [SELECT id, ownerId from case WHERE id IN : csId];
                  cs.ownerId = u1.id;
                  update cs;
                  CaseTeamRole caseTeamRole = [SELECT Id FROM CaseTeamRole WHERE Name = 'Immerti' LIMIT 1];
                  CaseTeamMember tm = new CaseTeamMember();
                  tm.ParentId = cs.id;
                  tm.MemberId = u.id;
                  tm.TeamRoleId = caseTeamRole.id;
                  insert tm;
            }     
          }
        }
     }
   } 
}






~Vikas

Thursday, March 13, 2014

Sorting Table Using Apex

Hey guys, i am back to blog  with sorting table.
In standard UI of salesforce, if we are looking any list view, then salesforce provides the sorting in both way(ASC && DESC). The same functionally may be achieved using apex. Here i am going to write the code of Sorting the table using the Apex Class and VF page.


********************Controller**************************

public class SortTableController{
    public List<Account> acc {get; set;}
    public string uparr {get; set;}
    public boolean NameUpArrow {get; set;}
    public boolean NameDownArrow {get; set;}
    public boolean TypeDownArrow {get; set;}
    public boolean TypeUpArrow {get; set;}
    public boolean CreateDownArrow {get; set;}
    public boolean CreateUpArrow {get; set;}
    Public integer i {get; set;}
    Public integer j {get; set;}
    Public integer k {get; set;}
    public SortTableController(){
        acc = new List<Account>();
        acc = [select id , name , createddate, type from account];
        uparr = '&darr;';
        NameUpArrow = false;
        NameDownArrow = false;
        TypeUpArrow = false;
        TypeDownArrow = false;
        CreateUpArrow = false;
        CreateDownArrow = false;
        i = 0;
        j = 0;
        k = 0;
    }
    //sort by name....
    public pagereference NameSort(){
        TypeUpArrow = false;
        TypeDownArrow = false;
        CreateUpArrow = false;
        CreateDownArrow = false;
        if(i == 0){
            NameDownArrow = true;
            NameUpArrow = false;
        }else if(i == 1){
            NameUpArrow = true;
            NameDownArrow = false;
        }
        if(NameDownArrow == true){
            acc = [select id , name , createddate, type from account Order By Name ASC];
            i = 1;
            NameUPArrow = false;
        }else if(NameUpArrow == true){
            acc = [select id , name , createddate, type from account Order By Name DESC];
            i = 0;
            NameDownArrow = false;
        } 
        return null;
    }
    //sort by type....
    public pagereference TypeSort(){
        NameUpArrow = false;
        NameDownArrow = false;
        CreateUpArrow = false;
        CreateDownArrow = false;
        if(j == 0){
            TypeDownArrow = true;
            TypeUpArrow = false;
        }else if(j == 1){
            TypeUpArrow = true;
            TypeDownArrow = false;
        }
        if(TypeDownArrow == true){
            acc = [select id , name , createddate, type from account Order By type ASC];
            j = 1;
            TypeUPArrow = false;
        }else if(TypeUpArrow == true){
            acc = [select id , name , createddate, type from account Order By Type DESC];
            j = 0;
            TypeDownArrow = false;
        } 
        return null;
    }
    //sort by created date....
    public pagereference CreateSort(){
        NameUpArrow = false;
        NameDownArrow = false;
        TypeUpArrow = false;
        TypeDownArrow = false;
        if(k == 0){
            CreateDownArrow = true;
            CreateUpArrow = false;
        }else if(k == 1){
            CreateUpArrow = true;
            CreateDownArrow = false;
        }
        if(CreateDownArrow == true){
            acc = [select id , name , createddate, type from account Order By CreatedDate ASC];
            k = 1;
            CreateUPArrow = false;
        }else if(CreateUpArrow == true){
            acc = [select id , name , createddate, type from account Order By CreatedDate DESC];
            k = 0;
            CreateDownArrow = false;
        } 
        return null;
    }
    
}
*****************************Page*****************************

<apex:page controller="SortTableController">
  <apex:form >
      <apex:pageBlock >
          <table width="60%" border="0">
              <tr>
                  <th>
                      <apex:commandLink value="Name" action="{!NameSort}"/>
                      <apex:image value="{!$Resource.UpArrow}" width="10px" height="10px" rendered="{!NameUpArrow}"></apex:image>
                      <apex:image value="{!$Resource.DownArrow}" width="10px" height="10px" rendered="{!NameDownArrow}"></apex:image>
                  </th>
                  <th>
                      <apex:commandLink value="Type" action="{!TypeSort}"/>
                      <apex:image value="{!$Resource.UpArrow}" width="10px" height="10px" rendered="{!TypeUpArrow}"></apex:image>
                      <apex:image value="{!$Resource.DownArrow}" width="10px" height="10px" rendered="{!TypeDownArrow}"></apex:image>
                  </th>
                  <th>
                      <apex:commandLink value="Created Date" action="{!CreateSort}"/>
                      <apex:image value="{!$Resource.UpArrow}" width="10px" height="10px" rendered="{!CreateUpArrow}"></apex:image>
                      <apex:image value="{!$Resource.DownArrow}" width="10px" height="10px" rendered="{!CreateDownArrow}"></apex:image>
                  </th>
              </tr>
              <apex:repeat value="{!acc}" var="ac">
                  <tr>
                      <td>
                          <apex:outputfield value="{!ac.name}"/>
                      </td>
                      <td>
                          <apex:outputfield value="{!ac.type}"/>
                      </td>
                      <td>
                          <apex:outputfield value="{!ac.createddate}"/>
                      </td>
                  </tr>
             </apex:repeat>
         </table>
     </apex:pageBlock>
  </apex:form>
</apex:page>


For live demo please visit http://vickygaur-developer-edition.ap1.force.com/SortTable