Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c9699b
commit 446e20b
Showing
8 changed files
with
121 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
privat24/src/main/scala/com/github/unknownnpc/psw/p24/action/RetrieveCardBalanceAction.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.unknownnpc.psw.p24.action | ||
|
||
import com.github.unknownnpc.psw.api.action.ActionContext | ||
import com.github.unknownnpc.psw.api.executor.RestHttpExecutor | ||
import com.github.unknownnpc.psw.p24.model.P24Model | ||
import com.github.unknownnpc.psw.p24.model.P24Model.WalletHistory.WalletHistoryResponse | ||
import org.apache.http.client.methods.HttpPost | ||
import org.apache.http.impl.client.CloseableHttpClient | ||
|
||
private[action] trait RetrieveCardBalanceAction extends | ||
ActionContext[P24Model.Request, WalletHistoryResponse, HttpPost, String] with RestHttpExecutor[HttpPost] | ||
|
||
object RetrieveCardBalanceAction { | ||
|
||
def apply(httpClientParam: CloseableHttpClient): RetrieveCardBalanceAction = new RetrieveCardBalanceAction() { | ||
override val httpClient: CloseableHttpClient = httpClientParam | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
privat24/src/main/scala/com/github/unknownnpc/psw/p24/serializer/P24Serializer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package com.github.unknownnpc.psw.p24.serializer | ||
|
||
import com.github.unknownnpc.psw.api.Serializer | ||
import com.github.unknownnpc.psw.p24.model.P24Model.WalletHistory.{WalletHistoryRequest, WalletHistoryResponse} | ||
import com.github.unknownnpc.psw.p24.model.P24Model | ||
import com.github.unknownnpc.psw.p24.model.P24Model.WalletHistory.WalletHistoryResponse | ||
import org.apache.http.client.methods.HttpPost | ||
|
||
private[p24] object P24Serializer { | ||
|
||
implicit val walletHistoryReqResSerializer: Serializer[WalletHistoryRequest, WalletHistoryResponse, HttpPost, String] = new WalletHistoryReqResSerializer | ||
implicit val walletHistoryReqResSerializer: Serializer[P24Model.Request, WalletHistoryResponse, HttpPost, String] = new WalletHistoryReqResSerializer | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
privat24/src/main/scala/com/github/unknownnpc/psw/p24/serializer/P24SerializerLike.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.github.unknownnpc.psw.p24.serializer | ||
|
||
import java.security.MessageDigest | ||
import java.text.SimpleDateFormat | ||
|
||
import com.github.unknownnpc.psw.p24.model.P24Model | ||
import com.github.unknownnpc.psw.p24.model.P24Model.Merchant | ||
import org.apache.commons.codec.binary.Hex | ||
|
||
import scala.xml.{Elem, Node} | ||
|
||
trait P24SerializerLike { | ||
|
||
val p24ResponseDateFormatter = new SimpleDateFormat("yyyy-MM-dd") | ||
|
||
def unPrettyOut(string: String): String = { | ||
string.replaceAll(">\\s+<", "><") | ||
} | ||
|
||
def formRequestXmlStr(req: P24Model.Request): String = { | ||
val dataXml = requestDataToXml(req.data) | ||
val merchantXml = merchantToXml(req.merchant, dataXml.child, req.merchantPassword) | ||
|
||
unPrettyOut( | ||
formRequestXml(merchantXml, dataXml).toString() | ||
) | ||
} | ||
|
||
private def encodeMessage(message: String, hashType: String): String = { | ||
val messageDigest = MessageDigest.getInstance(hashType) | ||
messageDigest.update(message.getBytes()) | ||
new String(Hex.encodeHex(messageDigest.digest())) | ||
} | ||
|
||
private def formRequestXml(merchantXml: Elem, dataXml: Elem): Elem = { | ||
<request version="1.0"> | ||
<xml version="1.0" encoding="UTF-8"> | ||
{merchantXml}{dataXml} | ||
</xml> | ||
</request> | ||
} | ||
|
||
private def merchantToXml(merchant: Merchant, dataProps: Seq[Node], password: String): Elem = { | ||
|
||
val dataPropsStr: String = dataProps.map(d => unPrettyOut(d.toString())) | ||
.filter(d => !d.trim.isEmpty).mkString("") | ||
|
||
<merchant> | ||
<id>{merchant.id}</id> | ||
<signature>{encodeMessage(encodeMessage(dataPropsStr + password, "MD5"), "SHA1")}</signature> | ||
</merchant> | ||
} | ||
|
||
private def requestDataToXml(walletHistoryRequestData: P24Model.RequestData): Elem = { | ||
|
||
def walletHistoryRequestDataPropToXml(requestDataProp: P24Model.RequestDataProp): Elem = { | ||
<prop name={requestDataProp.name} value={requestDataProp.value}></prop> | ||
} | ||
|
||
<data> | ||
<oper>{walletHistoryRequestData.oper}</oper> | ||
<wait>{walletHistoryRequestData.waitField}</wait> | ||
<test>{walletHistoryRequestData.test}</test> | ||
<payment id={walletHistoryRequestData.payment.idAttr}>{walletHistoryRequestData.payment.props.map(walletHistoryRequestDataPropToXml)}</payment> | ||
</data> | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters