Sample project that shows how to integrate Samsung Pay with Datatrans
Samsung Pay allows merchants to collect payments through their payment platform that connects the Samsung Pay wallet and lets users authenticate through their mobile device. It enables merchants to receive encrypted payment information which can be forwarded to their Payment Processor for authorization. This Guide is intended for merchants who would like to integrate Samsung Pay with Datatrans. For more Information on Samsung Pay visit: http://www.samsung.com/ch/samsung-pay/
The SamsungPay solution is made out of two APIs. The first one is just a WebSDK to trigger the payments on the web. The second one is a REST-like server-to-server API. The application/ message flow is as follows:
Please note that these steps are required to use the sample application as well as if you want to use Samsung Pay in your productive environment. These steps require your to get in touch with Samsung.
Navigate to https://us-partner.pay.samsung.com/ and sign up. You can use this account later on for testing on your Samsung device.
To make sure only you can decrypt the messages coming from Samsung you need to submit a self signed CSR for each Environment. The CSR should have following attributes:
- File extension CSR
- RSA Key Size 2048 bit or higher
- Signature Algorithm: Sha256WithRSAEncryption
Create one CSR for your Test and Production environment
Furthermore you need to submit your list of IP addresses to Samsung during the onboarding process. Please get in touch for more information. Submit each CSR to Samsung. After verifying your account, the IP addresses and your CSRs you will be given a service-ID and access to their Documentation
Generate your private key
openssl genrsa -out domain.com.key 2048
Generate the CSR with your private key
openssl req -out CSR.csr -key domain.com.key -new -sha256
Verify your CSR
openssl req -in CSR.csr -noout -text
The sample application is a spring boot application ( https://projects.spring.io/spring-boot/) that can be run out of the box. It uses an embedded tomcat.
$ git clone [email protected]:datatrans/samsungpay-web-sample.git
$ cd samsungpay-web-sample
mvn clean install
To decrypt the payment credentials sent by Samsung you need to use your private key in DER format. Here is how you convert it.
openssl pkcs8 -topk8 -in domain.com.key -outform DER -nocrypt -out rsapriv.der
Do this for each private key in each environment. Copy the file to src/main/resources
Property | Description | File |
---|---|---|
server.port | The port the server should be running on | application.properties |
callbackUrl | The callback Samsung uses. Make sure this is aligned with your server port | application.properties |
merchant.name | Your company's name. | application.properties |
merchant.reference | This is used by Samsung to display transactions in the SamsungPay App | application.properties |
samsung.serviceId | Your ServiceID given by Samsung | application-dev.properties / application-prod.properties |
datatrans.merchantId | Your datatrans merchantId | application-dev.properties / application-prod.properties |
datatrans.sign | The sign belonging to the merchantId | application-dev.properties / application-prod.properties |
During contact with Samsung you will be provided with a sample Samsung Pay app. The app will contain test cards, those will not be charged by Datatrans but will be replaced if a valid Samsung Pay token is sent as follows:
If
cardno=4242 4242 4242 4242 expm=12 expy=18
Check out src/main/java/ch/datatrans/examples/samsungpay/client/DatatransClient.java
to see how the authorization is done.
Sample request:
<?xml version="1.0" encoding="UTF-8" ?>
<authorizationService version="1">
<body merchantId="$merchantId">
<transaction refno="$refno">
<request>
<samsungPayData><![CDATA[$token]]></samsungPayData>
<reqtype>NOA</reqtype>
<transtype>05</transtype>
<sign>$sign</sign>
</request>
</transaction>
</body>
</authorizationService>
Sample response:
<?xml version="1.0" encoding="UTF-8" ?>
<authorizationService version="1">
<body merchantId="$merchantId" status="accepted">
<transaction refno="$refno" trxStatus="response">
<request>
<samsungPayData><![CDATA[$token]]></samsungPayData>
<reqtype>NOA</reqtype>
<transtype>05</transtype>
<sign>$sign</sign>
</request>
<response>
<responseCode>01</responseCode>
<responseMessage>Authorized</responseMessage>
<uppTransactionId>160823101329060450</uppTrasactionId>
<authorizationCode>538050451</authorizationCode>
<acqAuthorizationCode>101538</acqAuthorizationCode>
<aliasCC>70119122433810042</aliasCC>
<expy>18</expy>
<expm>12</expm>
</response>
</transaction>
</body>
</authorizationService>
A successful call will return <body>
’s attribute status="accepted"
and <transaction>
’s trxStatus="response"
as
well as a new <response>
element containing the responseCode. A responseCode equal to "01" or "02" indicates
an authorized transaction. Elements aliasCC, expy and expm will be returned only if the merchant uses credit card aliases.
Datatrans APIs