-
Notifications
You must be signed in to change notification settings - Fork 4
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
Evgeniy Sinev
committed
Sep 29, 2020
1 parent
f7d057a
commit 2871ff3
Showing
13 changed files
with
312 additions
and
50 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
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
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
69 changes: 69 additions & 0 deletions
69
server/src/main/java/com/payneteasy/pos/proxy/impl/InpasNetworkManager.java
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,69 @@ | ||
package com.payneteasy.pos.proxy.impl; | ||
|
||
import com.payneteasy.android.sdk.reader.inpas.config.InpasTerminalConfiguration; | ||
import com.payneteasy.android.sdk.reader.inpas.network.InpasNetworkClient; | ||
import com.payneteasy.inpas.sa.client.handlers.DefaultClientPacketOptions; | ||
import com.payneteasy.pos.proxy.messages.PaymentResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
|
||
public class InpasNetworkManager { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(InpasNetworkManager.class); | ||
|
||
private final String amount; | ||
private final String currency; | ||
private final String posAddress; | ||
|
||
public InpasNetworkManager(String amount, String currency, String aPosAddress) { | ||
this.amount = amount; | ||
this.currency = currency; | ||
posAddress = aPosAddress; | ||
} | ||
|
||
public interface IInpasOperationHandler { | ||
PaymentResponse invokeOperation(InpasNetworkClient aClient) throws IOException; | ||
} | ||
|
||
public PaymentResponse makeOperation(IInpasOperationHandler aHandler) { | ||
InpasNetworkClient client = new InpasNetworkClient(posAddress, new InpasTerminalConfiguration.Builder() | ||
.packetOptions(new DefaultClientPacketOptions()) | ||
.throwExceptionIfCannotConnect(true) | ||
.build() | ||
); | ||
try { | ||
client.connect(); | ||
try { | ||
|
||
return aHandler.invokeOperation(client); | ||
|
||
} catch (Exception e) { | ||
client.sendEot(); | ||
LOG.error("Cannot process a payment", e); | ||
return error("-1"); | ||
} finally { | ||
client.closeConnection(); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw new IllegalStateException("Interrupted"); | ||
} catch (Exception e) { | ||
LOG.error("Cannot connect", e); | ||
return error("-2"); | ||
} | ||
|
||
} | ||
|
||
private PaymentResponse error(String aErrorCode) { | ||
return PaymentResponse.builder() | ||
.amount ( amount ) | ||
.currency ( currency ) | ||
.orderId ( null ) | ||
.responseCode ( aErrorCode ) | ||
.build(); | ||
} | ||
|
||
|
||
} |
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
16 changes: 12 additions & 4 deletions
16
server/src/main/java/com/payneteasy/pos/proxy/messages/PaymentRequest.java
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,13 +1,21 @@ | ||
package com.payneteasy.pos.proxy.messages; | ||
|
||
import lombok.Data; | ||
import lombok.NonNull; | ||
|
||
@Data | ||
public class PaymentRequest { | ||
|
||
public String amount; | ||
@NonNull | ||
private final String amount; | ||
|
||
public String currency; | ||
@NonNull | ||
private final String currency; | ||
|
||
public String posAddress; | ||
@NonNull | ||
private final String posAddress; | ||
|
||
public String posType; | ||
@NonNull | ||
private final String posType; | ||
|
||
} |
19 changes: 15 additions & 4 deletions
19
server/src/main/java/com/payneteasy/pos/proxy/messages/PaymentResponse.java
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,12 +1,23 @@ | ||
package com.payneteasy.pos.proxy.messages; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NonNull; | ||
|
||
@Data | ||
@Builder | ||
public class PaymentResponse { | ||
|
||
public String amount; | ||
public String currency; | ||
|
||
public String responseCode; | ||
@NonNull | ||
private final String amount; | ||
|
||
@NonNull | ||
private final String currency; | ||
|
||
@NonNull | ||
private final String responseCode; | ||
|
||
public Long orderId; | ||
private final Long orderId; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
server/src/main/java/com/payneteasy/pos/proxy/messages/RefundRequest.java
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,26 @@ | ||
package com.payneteasy.pos.proxy.messages; | ||
|
||
import lombok.Data; | ||
import lombok.NonNull; | ||
|
||
@Data | ||
public class RefundRequest { | ||
|
||
@NonNull | ||
private final String refundAmount; | ||
|
||
/** | ||
* Paynet order id to refund | ||
*/ | ||
private final long orderId; | ||
|
||
@NonNull | ||
private final String currency; | ||
|
||
@NonNull | ||
private final String posAddress; | ||
|
||
@NonNull | ||
private final String posType; | ||
|
||
} |
Oops, something went wrong.