Created
June 23, 2023 15:16
-
-
Save Eragoo/ecc659edc0d7999f6d5bbaf8dbfa57d1 to your computer and use it in GitHub Desktop.
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
public class WayForPayClient { | |
private final RestTemplate restTemplate; | |
private final WayForPayProperties wayForPayProperties; | |
public void createPayment(SubscriptionType subscriptionType, Long userId) { | |
String formUrl = "https://secure.wayforpay.com/pay"; | |
String orderReference = subscriptionType.name() + ":"+userId + ":" + System.currentTimeMillis(); | |
long time = System.currentTimeMillis(); | |
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); | |
formData.add("merchantAccount", wayForPayProperties.getMerchantAccount()); | |
formData.add("merchantAuthType", "SimpleSignature"); | |
formData.add("merchantDomainName", "www.market.ua"); | |
formData.add("orderReference", orderReference); | |
formData.add("orderDate", String.valueOf(time)); | |
formData.add("amount", "1547.36"); | |
formData.add("currency", "UAH"); | |
formData.add("orderTimeout", "49000"); | |
formData.add("productName[]", "Процессор Intel Core i5-4670 3.4GHz"); | |
formData.add("productName[]", "Память Kingston DDR3-1600 4096MB PC3-12800"); | |
formData.add("productPrice[]", "1000"); | |
formData.add("productPrice[]", "547.36"); | |
formData.add("productCount[]", "1"); | |
formData.add("productCount[]", "1"); | |
formData.add("clientFirstName", "Вася"); | |
formData.add("clientLastName", "Пупкин"); | |
formData.add("clientAddress", "пр. Гагарина, 12"); | |
formData.add("clientCity", "Днепропетровск"); | |
formData.add("clientEmail", "some@mail.com"); | |
formData.add("defaultPaymentSystem", "card"); | |
String signature = WayForPayUtils.createPaymentSignature(formData, wayForPayProperties.getMerchantSecretKey()); | |
formData.add("merchantSignature", signature); | |
HttpHeaders headers = new HttpHeaders(); | |
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); | |
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers); | |
ResponseEntity<String> response = restTemplate.exchange(formUrl, HttpMethod.POST, requestEntity, String.class); | |
String responseBody = response.getBody(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment