In this session, we will show how you can easily connect the PayPal Payflow Pro payment gateway to Salesforce, in order to charge credit cards directly from Salesforce, either via embedded buttons.
Agenda:
- Purpose of Integration
- What is API?
- What is WebService?
- Live Demo
- Create a Paypal Account.
- Create Sandbox in PayPal Account.
- Paypal Connected App
- Paypal API
- Create Payment using Paypal Method
- Create Payment using Credit Card Method
- Create Order using API
- Create Invoice
- Send Invoice
- Create Product
- Create Product Subscription
- Object Structure of the Objects involved in Demo
- Walkthrough of how to set up the Integration and test API using Postman tool.
- Q & A
Here is the Link to Request Body that we used in our demo
https://docs.google.com/document/d/1JI1KuBE9vmfB5Ts6-msOdWINI7y_TkX0fFZpOHhCxi4/edit?usp=sharing
image copyrights to #ApexHours
Here is the recording of the session
Here is the PPT involved used for presentation
Hey Amit,
This was great session. I have few queries, when I am trying to implement.
Even though I am able to hit the endpoint and getting Success Response, I am not able to see the Amount in the Activities for PayPal method. And one more thing, for Credit card, how we have create the CARD ID which I am not able to find anywhere.
Appreciate your help on this
Here is the Link
https://developer.paypal.com/docs/integration/direct/vault/#store-credit-card-in-the-vault
Thanks & Regards,
SFDCPanther
Hi Amit,
I have been trying this integration, all the instances paypal method of payment is not working.
I am getting success response and also I have paid, its redirecting to the URL which I have given. But I dont see that transaction in the Business Account.
Do you have any idea what might be the reason?
Where are you checking in Sandbox or Main Account?
Also, while making the payment using paypal is 2 step process.
Hi , is it possible to see the code, are you sharing it somewhere on Github etc ?
Hi,
We have not hosted the code anywhere and this is the reason we provided the request and response format for all the Demo targets.
To get the Idea about how to start with Integration here is the Link for you
https://www.youtube.com/watch?v=Jcmw5WqjNwU&list=PLV3ll8m0ZlpqVOJCTFJu8uNJ-f2OppInR
Hi Amit,
Great video!
Can you share a code to get access token from Salesforce?
Thanks,
Here is the code for the same.
public static List apiDetails(){
String env = System.Label.PayPal_Environment;
List paypalCred = new List ();
paypalCred = [Select Id, MasterLabel, Client_ID__c, Client_Secret__c,
Token_URL__c, grant_type__c, Content_Type__c, Method__c From Paypal_API__mdt
Where MasterLabel =:env Limit 1];
return paypalCred;
}
public static void generateCredentials(){
String env = System.Label.PayPal_Environment;
List paypalCred = apiDetails();
If(paypalCred != null && paypalCred.size() > 0){
String clientId = paypalCred.get(0).Client_ID__c;
String clientSecret = paypalCred.get(0).Client_Secret__c;
String tokenURL = paypalCred.get(0).Token_URL__c;
String grantType = paypalCred.get(0).grant_type__c;
String contentType = paypalCred.get(0).Content_Type__c;
String method = paypalCred.get(0).Method__c;
/* Prepare Http Request to Get the Paypal Token Credentials */
String dataToEncode = clientId+':'+clientSecret;
Blob blobValue = Blob.valueOf(dataToEncode);
String encodedData = EncodingUtil.base64Encode(blobValue);
/*System.debug(' #### encodedData '+encodedData);*/
String body = 'grant_type='+grantType;
/* Prepare a Var for Error */
String errorMessage = '';
HttpRequest HttpReq = new HttpRequest();
HttpResponse httpRes = new HttpResponse();
HttpReq.setEndPoint(tokenURL);
httpReq.setMethod(method);
httpReq.setHeader('Authorization', 'Basic '+encodedData);
httpReq.setHeader('Content-Type' , contentType);
httpReq.setBody(body);
httpReq.setTimeOut(120000);
try{ responseMap = (Map)JSON.deserializeUntyped(responseBody);
httpRes = (new Http()).send(httpReq);
Integer statusCode = httpRes.getStatusCode();
String responseBody = httpRes.getBody();
if(statusCode == 200){
/*System.debug(' responseBody '+responseBody);*/
Map
String scope = (String)responseMap.get('scope');
String access_token = (String)responseMap.get('access_token');
String token_type = (String)responseMap.get('token_type');
String app_id = (String)responseMap.get('app_id');
Integer expires_in = (Integer)responseMap.get('expires_in');
String nonce = (String)responseMap.get('nonce');
DateTime experiesInTime = System.now().addSeconds(expires_in);
/* Create the Metadata for the Token */ fieldValueMap = new Map();
String fullName = 'PayPal_TokenInfo.'+env;
Map
fieldValueMap.put('access_token__c', access_token);
fieldValueMap.put('app_id__c', app_id);
fieldValueMap.put('expires_in_seconds__c', expires_in);
fieldValueMap.put('expires_in_time__c', experiesInTime);
fieldValueMap.put('nonce__c', nonce);
fieldValueMap.put('scope__c', scope);
fieldValueMap.put('token_type__c', token_type);
/* Create/Update the Metadata Record */
CreateUpdateMetadataUtils.createUpdateMetadata(fullName, env, fieldValueMap);
}else{
System.debug(' Error Occured '+responseBody);
errorMessage = 'Unexpected Error while communicating with PayPal API. '
+'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode();
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage));
}
}catch(System.Exception e){
System.debug('#### Exception Excuted '+e.getStackTraceString()+' '+e.getMessage());
if(String.valueOf(e.getMessage()).startsWith('Unauthorized endpoint')){
errorMessage = 'Unauthorize endpoint: An Administer must go to Setup -> Administer -> Security Control ->'
+' Remote Site Setting and add '+' '+ tokenURL+' Endpoint';
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage));
}else{
errorMessage = 'Unexpected Error while communicating with PayPal API. '
+'Status '+httpRes.getStatus()+' and Status Code '+httpRes.getStatuscode();
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, errorMessage));
}
}
}
}
Hi Amit,
can you please share the Create payment JSON creation code, i am facing some challenges there.
Hello, Which JSON are you looking for?
how you set the auth.providers and name credencials can you provide the screen shots please regarding paypal
There is no Auth. Provider. To use named credentials you need to use client id as username and client secret as the password. and the API base point as URL. We have not use the named credentials for this demo.
can we get the refresh token from salesforce after getting the access token?
Yes. There is refresh token flow which you need to use. The recommended way is to use Named Credentials so that we do not need to worry about the refresh token
If there is no auth provider, how can we integrate PayPal with salesforce…Could you please share the steps.. how to use the access token and client id and secrete key is code
What do you mean by when you say no auth provider? You have to read the API document and based on that select the appropriate tools
Will you please share the code for the PayPal payment apex callout..
thank you in advance!!!!!
Unfortunately, Code can not be shared for this integration