Integrating with a payment processor is often a major part of any e-commerce project. One of the options that you have available is Paymetric, which is a SaaS company that offers integrated, secure payment acceptance solution. At XCentium, one of our core specialties is CloudCraze and we specialize in customizing and delivering a high-quality e-commerce solution that allows our clients to integrate with any of their existing platforms to deliver a cohesive, seamless experience to their customers.
Within this post, I will go through and demonstrate how to integrate with Paymetric on the CloudCraze platform via a iFrame. Quick Note: when using the sample code from here, there are a few instances where you need to substitute in your credentials and specific information. They will be prepended and appended by ‘---‘.
I get it, we all have busy lives and busy days. It is hard to read through and entire blog post with our busy schedules. Lucky for you, here is the TL;DR
TL;DR – I don’t have time to read through the entire post
- Create a Vf page to host the payment form with a custom controller
- Update CloudCraze Config Settings to use the VF page as the payment form
- Make a WebService call to Paymetric XiIntercept to get the Access Token with your credentials
- Using the Access Token, initiate the iFrame styling the form as you see fit
- Create a onSubmit Handler to do a remote call to the controller method
- Call Paymetric XiIntercept to get the Tokenized Credit Card Number
- Call Paymetric XiPay to do the complete the Sale
- Process the response and update CloudCraze with the transaction information
Ta-Da…Let’s go back to our busy lives (creating memes and posting them on social media 😊)
The Good Stuff
*The post assumes that you have an intermediate to advanced familiarity with CloudCraze and Salesforce
The first step is to create a VF page to host the payment form with a custom controller. We recommend using a standard naming convention for better code quality.
Embed the XiFrameJS that enables the Paymetric iFrame/Ajax call using the following url (please refer to Paymetric Documentation for a up-to-date URL)
Easy enough, right?
Next we need to update CloudCraze to use our VF page for the credit card form:
1. Go to CC Admin > Configuration Modules and Create a new Configuration Module to hold the config metadata. Create the attributes as shown in the screenshot.
2. Go to the Storefront Settings that you are trying to configure Paymetric and Click on Configuration Settings > Payment Module and override the Whitelist Setting and add the custom VF page that you created previously.
3. Click on the new Config Module that you created previously and add the custom VF page that you created previously
4. Add CC to the Payment Types in the Storefront Settings
Next we need to make a webservice call to Paymetric XiIntercept to initialize the iFrame
Create the XML payload to send the form fields required using the Paymetric iFrame documentation. You can utilize the standard XML or customize the XML to include the fields that you need(refer to the Paymetric Documentation for more information). Here is a sample payload:
2. Call the Paymetric XiIntercept to get the Access Token by passing in your credentials. See below for sample payload:
Make sure to generate the signature using the hmacSHA256 algorithm. See below for sample code:
Using the access token returned in the response, embed the iframe on the VF page using the following URL format:
Next we need to create a onSubmit Handler to do a remote call. See below for sample code:
Next we need to call Paymetric XiIntercept to get the tokenized Credit Card Number. See below for sample code:
Parse the XML response to get the tokenized Credit Card Number
*Make sure you use the same signature and accessToken that you generated previously
Next we need to call Paymetric XiPay to get complete the sale. Couple of pointers here:
- Unfortunately, XiPay requires NTLM authentication and Salesforce doesn’t support NTLM Authentication by default. However, this is where the open-source developer community comes to our support. Nate Wallace has created this excellent library which provides NTLM Auth enabled HTTP method. Please download and add this excellent library to SF: https://github.com/natewallace/ApexNTLM
- When passing in the Card Type, make sure you use the card type returned from the previous web service call and convert the string to uppercase before passing it to XiPay
- The sample code provided below only lists basic fields and is meant for an Authorization only. If you are doing a different operation, please refer to XiPay Documentation for additional fields that are required by your payment processor.
Once you get a successful response from XiPay then, you can update CloudCraze with the payment information and the authorization codes.
- You need to create a new ccrz.cc_hk_Payment.TransactionPaymentParams object in your remote call and pass it back to VF as part of the response.
- In the TransactionPaymentParams object, you pass in the payment data per your data mapping strategy.
- In the VF Page, once you get the object you need to trigger the processPayment action using the TransactionPaymentParams object. See below for sample code:
At this point, you have successfully integrated Paymetric with CloudCraze via an iFrame. Even though this post specifically goes through the process with the iFrame, you can integrate with Paymetric via other options such as Form Post, Form Post with 3DS, Ajax, Hosted and AliPay. Please refer to Paymetric Documentation for further detatils.
Hope this post was helpful, if you have questions or comments about the post or if you need help configuring Paymetric Integration with CloudCraze or other CloudCraze customization, please reach out to us @ https://xcentium.com/contact and we would glad to chat!