├── .gitattributes ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── _config.yml ├── docs ├── allclasses-frame.html ├── allclasses-noframe.html ├── com │ └── midtrans │ │ ├── Config.html │ │ ├── ConfigBuilder.html │ │ ├── ConfigFactory.html │ │ ├── Midtrans.html │ │ ├── httpclient │ │ ├── APIHttpClient.html │ │ ├── CoreApi.html │ │ ├── IrisApi.html │ │ ├── SnapApi.html │ │ ├── TransactionApi.html │ │ ├── error │ │ │ ├── MidtransError.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ └── package-tree.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html │ │ ├── java │ │ ├── ConcurrentTest.html │ │ ├── ConfigGlobalTest.html │ │ ├── ConfigTest.html │ │ ├── ConfigViaBuilderTest.html │ │ ├── CoreApiStaticTest.html │ │ ├── CoreApiTest.html │ │ ├── IrisApiStaticTest.html │ │ ├── IrisApiTest.html │ │ ├── MidtransCoreApiTest.html │ │ ├── MidtransIrisApiTest.html │ │ ├── MidtransSnapApiTest.html │ │ ├── SnapApiStaticTest.html │ │ ├── SnapApiTest.html │ │ ├── TransactionApiTest.html │ │ ├── mockupdata │ │ │ ├── Constant.html │ │ │ ├── DataMockup.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ └── package-tree.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ ├── proxy │ │ ├── ProxyConfig.html │ │ ├── ProxyConfigBuilder.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html │ │ ├── service │ │ ├── MidtransCoreApi.html │ │ ├── MidtransIrisApi.html │ │ ├── MidtransSnapApi.html │ │ ├── impl │ │ │ ├── MidtransCoreApiImpl.html │ │ │ ├── MidtransIrisApiImpl.html │ │ │ ├── MidtransSnapApiImpl.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ └── package-tree.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html │ │ └── utils │ │ ├── Utility.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ └── package-tree.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-files │ ├── index-1.html │ ├── index-10.html │ ├── index-11.html │ ├── index-12.html │ ├── index-13.html │ ├── index-14.html │ ├── index-15.html │ ├── index-16.html │ ├── index-17.html │ ├── index-18.html │ ├── index-19.html │ ├── index-2.html │ ├── index-20.html │ ├── index-21.html │ ├── index-22.html │ ├── index-3.html │ ├── index-4.html │ ├── index-5.html │ ├── index-6.html │ ├── index-7.html │ ├── index-8.html │ └── index-9.html ├── index.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── script.js ├── serialized-form.html └── stylesheet.css ├── example ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── midtrans │ │ ├── sample │ │ ├── SampleApplication.java │ │ ├── SampleCoreApi.java │ │ ├── SampleIrisApi.java │ │ ├── SampleSnapApi.java │ │ ├── controller │ │ │ ├── CoreApiController.java │ │ │ ├── HomeController.java │ │ │ ├── IrisController.java │ │ │ ├── MobileSdkBackendController.java │ │ │ ├── SnapController.java │ │ │ └── TokenizationSdkController.java │ │ └── data │ │ │ ├── Constant.java │ │ │ └── DataMockup.java │ │ └── snapbi │ │ ├── SnapBiCancel.java │ │ ├── SnapBiDirectDebitPayment.java │ │ ├── SnapBiQris.java │ │ ├── SnapBiRefund.java │ │ ├── SnapBiStatus.java │ │ ├── SnapBiVa.java │ │ └── SnapBiWebhookServer.java │ └── resources │ ├── application.properties │ └── templates │ ├── coreapi │ ├── core-api.html │ ├── credit-card.html │ └── gopay.html │ ├── fragments │ └── header.html │ ├── index.html │ ├── iris │ ├── create-payout.html │ └── index.html │ ├── layout.html │ ├── mobile │ └── mobile-sdk.html │ └── snap │ ├── check-out.html │ └── snap.html ├── library ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── midtrans │ │ │ ├── Config.java │ │ │ ├── ConfigBuilder.java │ │ │ ├── ConfigFactory.java │ │ │ ├── Midtrans.java │ │ │ ├── httpclient │ │ │ ├── APIHttpClient.java │ │ │ ├── CoreApi.java │ │ │ ├── IrisApi.java │ │ │ ├── SnapApi.java │ │ │ ├── TransactionApi.java │ │ │ └── error │ │ │ │ └── MidtransError.java │ │ │ ├── proxy │ │ │ ├── ProxyConfig.java │ │ │ └── ProxyConfigBuilder.java │ │ │ ├── service │ │ │ ├── MidtransCoreApi.java │ │ │ ├── MidtransIrisApi.java │ │ │ ├── MidtransSnapApi.java │ │ │ └── impl │ │ │ │ ├── MidtransCoreApiImpl.java │ │ │ │ ├── MidtransIrisApiImpl.java │ │ │ │ └── MidtransSnapApiImpl.java │ │ │ ├── snapbi │ │ │ ├── SnapBi.java │ │ │ ├── SnapBiApiRequestor.java │ │ │ └── SnapBiConfig.java │ │ │ └── utils │ │ │ └── Utility.java │ └── resources │ │ └── version.properties │ └── test │ ├── java │ └── com │ │ └── midtrans │ │ └── java │ │ ├── ConcurrentTest.java │ │ ├── ConfigGlobalTest.java │ │ ├── ConfigTest.java │ │ ├── ConfigViaBuilderTest.java │ │ ├── CoreApiTest.java │ │ ├── IrisApiTest.java │ │ ├── MidtransCoreApiTest.java │ │ ├── MidtransIrisApiTest.java │ │ ├── MidtransSnapApiTest.java │ │ ├── SnapApiTest.java │ │ ├── TransactionApiTest.java │ │ └── mockupdata │ │ ├── Constant.java │ │ └── DataMockup.java │ └── resources │ └── junit-platform.properties ├── mvnw ├── mvnw.cmd └── pom.xml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | **/test-launch.config 7 | 8 | # BlueJ files 9 | *.ctxt 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | *.iml 22 | **/*.vsix 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | 27 | 28 | **/.idea/ 29 | **/node_modules/ 30 | .DS_Store 31 | target/ 32 | .classpath 33 | .project 34 | .settings 35 | **/.checkstyle 36 | target/ 37 | bin/ 38 | **/lib/ 39 | out/ 40 | server/ 41 | 42 | jdtls/ 43 | 44 | !java-extension/.mvn/wrapper/maven-wrapper.jar 45 | 46 | out 47 | node_modules 48 | *.vsix 49 | .vscode-test 50 | resources/templates/css/** 51 | resources/templates/js/** 52 | resources/templates/fonts/** 53 | dist 54 | 55 | ## Maven: 56 | !.mvn/wrapper/maven-wrapper.jar 57 | /.mvn/ 58 | /mvnw 59 | /mvnw.bat 60 | mvnw.cmd -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | before_install: cd library 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGELOG MIDTRANS JAVA LIBRARY 2 | 3 | ## v3.2.1 (October 16, 2024) 4 | 5 | Feature: 6 | - New method to verify webhook notification 7 | 8 | ## v3.2.0 (September 24, 2024) 9 | 10 | Feature: 11 | - New method to support SnapBi for direct debit, va, and qris. 12 | 13 | - 14 | ## v3.0.0 (April 13, 2021) 15 | 16 | Feature: 17 | - new static method CoreApi, SnapApi, IrisApi, TransactionApi 18 | - can change, TimeUnit for http connection settings 19 | - can set global config via Midtrans class 20 | - can add custom headers with config class 21 | - validation for server-key empty, contain whitespace 22 | 23 | Improvement: 24 | - handle okhttp raw error/exception via MidtransError exception class 25 | 26 | Notable changes: 27 | - Migrate from retrofit to okhttp as http client 28 | - Migrate repo host from jcenter/bintray to maven central 29 | 30 | ## v2.1.1 (April 27, 2020) 31 | 32 | Feature: 33 | 34 | - API Iris disbursement 35 | - Payment BIN API 36 | - Set Connection Pool & Keep alive connection 37 | - Set header X-Idempotency-key for Iris and Idempotency-Key for Payment 38 | - Set `X-Append-Notification`: to add new notification url(s) alongside the settings on dashboard 39 | - Set `X-Override-Notification`: to use new notification url(s) disregarding the settings on dashboard 40 | - Library version on `User-Agent` header 41 | 42 | Improvement: 43 | 44 | - Change logic for setup headers 45 | - Remove versioning path from base URL, move to `String API_VERSION` in CoreAPI, SnapAPI interface class 46 | - Improve conditional logic for HttpLoggingInterceptors. Now all debugging response will be handled only from HttpLoggingInterceptors Which can show logs request and response information 47 | 48 | Bugs fix: 49 | - Failure/error response from Midtrans api result in empty json. 50 | 51 | ## v1.1.1 (Feb 3, 2020) 52 | 53 | Improvement: 54 | 55 | HttpLoggingInterceptor: Which can show logs request and response information. This feature This feature is disabled by default on production mode. 56 | 57 | ## v1.1.0 (Nov 27, 2019) 58 | 59 | Feature: 60 | 61 | - Allow HTTP Proxy config 62 | - Allow set connectionTimeout 63 | - Allow set readTimeout 64 | - Allow set writeTimeout 65 | 66 | ## v1.0.0 (Sep 25, 2019) New release 67 | 68 | Feature: 69 | - CoreAPI basic functionality 70 | - Snap API basic functionality 71 | - Include Spring project example 72 | - Basic usage sample on Readme 73 | - Release via Bintray maven 74 | 75 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 MIDTRANS PT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /docs/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /docs/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes 7 | 8 | 9 | 10 | 11 | 12 |

All Classes

13 |
14 | 48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /docs/com/midtrans/httpclient/error/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.httpclient.error 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.httpclient.error

13 |
14 |

Exceptions

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/com/midtrans/httpclient/error/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.httpclient.error 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package com.midtrans.httpclient.error

73 |
74 |
75 | 94 |
95 | 96 |
97 | 98 | 99 |
Skip navigation links
100 | 101 | 102 | 103 | 112 |
113 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /docs/com/midtrans/httpclient/error/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.httpclient.error Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans.httpclient.error

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 95 |
96 | 97 |
98 | 99 | 100 |
Skip navigation links
101 | 102 | 103 | 104 | 113 |
114 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /docs/com/midtrans/httpclient/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.httpclient 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.httpclient

13 |
14 |

Classes

15 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/com/midtrans/httpclient/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.httpclient Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans.httpclient

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 91 |
92 | 93 |
94 | 95 | 96 |
Skip navigation links
97 | 98 | 99 | 100 | 109 |
110 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /docs/com/midtrans/java/mockupdata/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.java.mockupdata 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.java.mockupdata

13 |
14 |

Classes

15 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/com/midtrans/java/mockupdata/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.java.mockupdata 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package com.midtrans.java.mockupdata

73 |
74 |
75 | 96 |
97 | 98 |
99 | 100 | 101 |
Skip navigation links
102 | 103 | 104 | 105 | 114 |
115 | 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /docs/com/midtrans/java/mockupdata/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.java.mockupdata Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans.java.mockupdata

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 88 |
89 | 90 |
91 | 92 | 93 |
Skip navigation links
94 | 95 | 96 | 97 | 106 |
107 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/com/midtrans/java/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.java 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.java

13 |
14 |

Classes

15 | 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/com/midtrans/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans

13 |
14 |

Classes

15 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/com/midtrans/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 90 |
91 | 92 |
93 | 94 | 95 |
Skip navigation links
96 | 97 | 98 | 99 | 108 |
109 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /docs/com/midtrans/proxy/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.proxy 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.proxy

13 |
14 |

Classes

15 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/com/midtrans/proxy/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.proxy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package com.midtrans.proxy

73 |
74 |
75 | 100 |
101 | 102 |
103 | 104 | 105 |
Skip navigation links
106 | 107 | 108 | 109 | 118 |
119 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/com/midtrans/proxy/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.proxy Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans.proxy

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 88 |
89 | 90 |
91 | 92 | 93 |
Skip navigation links
94 | 95 | 96 | 97 | 106 |
107 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/com/midtrans/service/impl/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.service.impl 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.service.impl

13 |
14 |

Classes

15 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/com/midtrans/service/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.service 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.service

13 |
14 |

Interfaces

15 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/com/midtrans/service/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.service 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package com.midtrans.service

73 |
74 |
75 | 104 |
105 | 106 |
107 | 108 | 109 |
Skip navigation links
110 | 111 | 112 | 113 | 122 |
123 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /docs/com/midtrans/service/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.service Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans.service

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Interface Hierarchy

80 | 85 |
86 | 87 |
88 | 89 | 90 |
Skip navigation links
91 | 92 | 93 | 94 | 103 |
104 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /docs/com/midtrans/utils/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.utils 7 | 8 | 9 | 10 | 11 | 12 |

com.midtrans.utils

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/com/midtrans/utils/package-summary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.utils 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Package com.midtrans.utils

73 |
74 |
75 | 92 |
93 | 94 |
95 | 96 | 97 |
Skip navigation links
98 | 99 | 100 | 101 | 110 |
111 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /docs/com/midtrans/utils/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.midtrans.utils Class Hierarchy 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Hierarchy For Package com.midtrans.utils

73 | Package Hierarchies: 74 | 77 |
78 |
79 |

Class Hierarchy

80 | 87 |
88 | 89 |
90 | 91 | 92 |
Skip navigation links
93 | 94 | 95 | 96 | 105 |
106 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Generated Documentation (Untitled) 7 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | <noscript> 69 | <div>JavaScript is disabled on your browser.</div> 70 | </noscript> 71 | <h2>Frame Alert</h2> 72 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview List 7 | 8 | 9 | 10 | 11 | 12 |
All Classes
13 |
14 |

Packages

15 | 26 |
27 |

 

28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/package-list: -------------------------------------------------------------------------------- 1 | com.midtrans 2 | com.midtrans.httpclient 3 | com.midtrans.httpclient.error 4 | com.midtrans.java 5 | com.midtrans.java.mockupdata 6 | com.midtrans.proxy 7 | com.midtrans.service 8 | com.midtrans.service.impl 9 | com.midtrans.utils 10 | -------------------------------------------------------------------------------- /docs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Serialized Form 7 | 8 | 9 | 10 | 11 | 12 | 22 | 25 | 26 |
27 | 28 | 29 |
Skip navigation links
30 | 31 | 32 | 33 | 42 |
43 | 70 | 71 |
72 |

Serialized Form

73 |
74 |
75 | 110 |
111 | 112 |
113 | 114 | 115 |
Skip navigation links
116 | 117 | 118 | 119 | 128 |
129 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.midtrans 7 | sample-application 8 | 2.0.1 9 | war 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.1.7.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | 1.8 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-thymeleaf 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | nz.net.ultraq.thymeleaf 34 | thymeleaf-layout-dialect 35 | 2.3.0 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | test 43 | 44 | 45 | com.midtrans 46 | java-library 47 | 3.2.1 48 | compile 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 58 | 59 | com.heroku.sdk 60 | heroku-maven-plugin 61 | 62 | midtrans-java 63 | 64 | 65 | 66 | 67 | 2.0.16 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/SampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 8 | 9 | @SpringBootApplication 10 | public class SampleApplication extends SpringBootServletInitializer { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SampleApplication.class, args); 14 | } 15 | 16 | @Override 17 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 18 | return builder.sources(SampleApplication.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/SampleCoreApi.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.ConfigFactory; 5 | import com.midtrans.Midtrans; 6 | import com.midtrans.httpclient.CoreApi; 7 | import com.midtrans.httpclient.error.MidtransError; 8 | import com.midtrans.sample.data.DataMockup; 9 | import com.midtrans.service.MidtransCoreApi; 10 | import org.json.JSONObject; 11 | 12 | import java.util.Map; 13 | 14 | import static com.midtrans.sample.data.Constant.sandboxClientKey; 15 | import static com.midtrans.sample.data.Constant.sandboxServerKey; 16 | 17 | public class SampleCoreApi { 18 | 19 | public static void main(String[] args) throws MidtransError { 20 | DataMockup dataMockup = new DataMockup(); 21 | dataMockup.setPaymentType("gopay"); 22 | 23 | /* 24 | Core Api Request with global config 25 | */ 26 | RequestWithCoreApiAndGlobalConfig(dataMockup.initDataMock()); 27 | 28 | /* 29 | Core Api Request with options config 30 | */ 31 | RequestWithCoreApiAndConfigOptions(dataMockup.initDataMock()); 32 | 33 | /* 34 | Api Request with MidtransCoreApi object and specific config 35 | */ 36 | RequestWithMidtransCoreApiObject(dataMockup.initDataMock()); 37 | } 38 | 39 | 40 | private static void RequestWithCoreApiAndGlobalConfig(Map request) throws MidtransError { 41 | /* 42 | Set configuration globally 43 | */ 44 | Midtrans.serverKey = sandboxServerKey; 45 | Midtrans.clientKey = sandboxClientKey; 46 | 47 | /* 48 | Api Request with static method using Global Config 49 | */ 50 | JSONObject result = CoreApi.chargeTransaction(request); 51 | System.out.println(result); 52 | } 53 | 54 | private static void RequestWithCoreApiAndConfigOptions(Map request) throws MidtransError { 55 | /* 56 | Initiate Config Object 57 | */ 58 | Config configOptions = Config.builder() 59 | .setServerKey(sandboxServerKey) 60 | .setClientKey(sandboxClientKey) 61 | .setIsProduction(false) 62 | .build(); 63 | 64 | /* 65 | Api request with static method using Config Options 66 | */ 67 | 68 | JSONObject result = CoreApi.chargeTransaction(request, configOptions); 69 | System.out.println(result); 70 | } 71 | 72 | private static void RequestWithMidtransCoreApiObject(Map request) throws MidtransError { 73 | /* 74 | Initiate MidtransCoreApi Object with minimal config, also you can initiate config, with config builder. 75 | */ 76 | MidtransCoreApi coreApi = new ConfigFactory(new Config(sandboxServerKey, sandboxClientKey, false)).getCoreApi(); 77 | 78 | /* 79 | Api request to Midtrans API 80 | */ 81 | JSONObject result = coreApi.chargeTransaction(request); 82 | System.out.println(result); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/SampleIrisApi.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.ConfigFactory; 5 | import com.midtrans.httpclient.IrisApi; 6 | import com.midtrans.httpclient.error.MidtransError; 7 | import com.midtrans.service.MidtransIrisApi; 8 | import org.json.JSONObject; 9 | 10 | import static com.midtrans.sample.data.Constant.*; 11 | 12 | public class SampleIrisApi { 13 | 14 | public static void main(String[] args) throws MidtransError { 15 | /* 16 | Iris Api Request with options config 17 | */ 18 | RequestWithIrisApiAndConfigOptions(); 19 | 20 | /* 21 | Api Request via MidtransIrisApi object with minimal config 22 | */ 23 | RequestWithMidtransIrisApiObject(); 24 | } 25 | 26 | 27 | private static void RequestWithIrisApiAndConfigOptions() throws MidtransError { 28 | /* 29 | Initiate Config Object 30 | */ 31 | Config configOptions = Config.builder() 32 | .setServerKey(sandboxCreatorKey) 33 | .setIsProduction(false) 34 | .build(); 35 | 36 | /* 37 | Api request with static method using Config Options 38 | */ 39 | JSONObject result = IrisApi.getBalance(configOptions); 40 | System.out.println(result); 41 | } 42 | 43 | 44 | private static void RequestWithMidtransIrisApiObject() throws MidtransError { 45 | /* 46 | Initiate MidtransSnapApi Object with minimal config, also you can initiate config with config builder. 47 | */ 48 | MidtransIrisApi irisApi = new ConfigFactory(new Config(sandboxCreatorKey, null, false)).getIrisApi(); 49 | 50 | /* 51 | Api request to Midtrans API 52 | */ 53 | JSONObject result = irisApi.getBalance(); 54 | System.out.println(result); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/SampleSnapApi.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.ConfigFactory; 5 | import com.midtrans.Midtrans; 6 | import com.midtrans.httpclient.SnapApi; 7 | import com.midtrans.httpclient.error.MidtransError; 8 | import com.midtrans.sample.data.DataMockup; 9 | import com.midtrans.service.MidtransSnapApi; 10 | import org.json.JSONObject; 11 | 12 | import java.util.Map; 13 | 14 | import static com.midtrans.sample.data.Constant.sandboxClientKey; 15 | import static com.midtrans.sample.data.Constant.sandboxServerKey; 16 | 17 | public class SampleSnapApi { 18 | 19 | public static void main(String[] args) throws MidtransError { 20 | DataMockup dataMockup = new DataMockup(); 21 | dataMockup.setPaymentType("gopay"); 22 | 23 | /* 24 | Snap Api Request with global config 25 | */ 26 | RequestWithSnapApiAndGlobalConfig(dataMockup.initDataMock()); 27 | 28 | /* 29 | Snap Api Request with options config 30 | */ 31 | RequestWithSnapApiAndConfigOptions(dataMockup.initDataMock()); 32 | 33 | /* 34 | Api Request with MidtransSnapApi object and specific config 35 | */ 36 | RequestWithMidtransSnapApiObject(dataMockup.initDataMock()); 37 | } 38 | 39 | 40 | private static void RequestWithSnapApiAndGlobalConfig(Map request) throws MidtransError { 41 | /* 42 | Set configuration globally 43 | */ 44 | Midtrans.serverKey = sandboxServerKey; 45 | Midtrans.clientKey = sandboxClientKey; 46 | 47 | /* 48 | Api Request with static method using Global Config 49 | */ 50 | JSONObject result = SnapApi.createTransaction(request); 51 | System.out.println(result); 52 | } 53 | 54 | private static void RequestWithSnapApiAndConfigOptions(Map request) throws MidtransError { 55 | /* 56 | Initiate Config Object 57 | */ 58 | Config configOptions = Config.builder() 59 | .setServerKey(sandboxServerKey) 60 | .setClientKey(sandboxClientKey) 61 | .setIsProduction(false) 62 | .build(); 63 | 64 | /* 65 | Api request with static method using Config Options 66 | */ 67 | JSONObject result = SnapApi.createTransaction(request, configOptions); 68 | System.out.println(result); 69 | } 70 | 71 | private static void RequestWithMidtransSnapApiObject(Map request) throws MidtransError { 72 | /* 73 | Initiate MidtransSnapApi Object with minimal config, also you can initiate config, with config builder. 74 | */ 75 | MidtransSnapApi snapApi = new ConfigFactory(new Config(sandboxServerKey, sandboxClientKey, false)).getSnapApi(); 76 | 77 | /* 78 | Api request to Midtrans API 79 | */ 80 | JSONObject result = snapApi.createTransaction(request); 81 | System.out.println(result); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample.controller; 2 | 3 | import com.midtrans.sample.data.DataMockup; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Controller; 6 | import org.springframework.ui.Model; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | 11 | import java.util.Map; 12 | 13 | 14 | @Controller 15 | public class HomeController { 16 | 17 | String clientKey = "SB-Mid-client-nKsqvar5cn60u2Lv"; 18 | 19 | @Autowired 20 | private DataMockup dataMockup; 21 | 22 | @RequestMapping(value = "/", method = RequestMethod.GET) 23 | public String home() { 24 | return index(); 25 | } 26 | 27 | @RequestMapping(value = "/index", method = RequestMethod.GET) 28 | private String index() { 29 | return "index"; 30 | } 31 | 32 | @RequestMapping(value = "/mobile-sdk", method = RequestMethod.GET) 33 | private String mobileSdk() { 34 | return "mobile/mobile-sdk"; 35 | } 36 | 37 | @RequestMapping(value = "/api/core-api", method = RequestMethod.GET) 38 | public String coreApi(Model model) { 39 | Map objectMap = dataMockup.initDataMock(); 40 | model.addAttribute("data", objectMap); 41 | return "coreapi/core-api"; 42 | } 43 | 44 | @RequestMapping(value = "/api/checkout", method = RequestMethod.GET) 45 | public String checkOut(@RequestParam(value = "paymentType") String typePayment, 46 | Model model) { 47 | Map result = dataMockup.initDataMock(); 48 | model.addAttribute("result", result); 49 | model.addAttribute("clientKey", clientKey); 50 | if (typePayment.equals("cc")) { 51 | return "coreapi/credit-card"; 52 | } else if (typePayment.equals("gopay")) { 53 | return "coreapi/gopay"; 54 | } 55 | return "redirect:/api/core-api"; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/controller/MobileSdkBackendController.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample.controller; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.error.MidtransError; 5 | import com.midtrans.httpclient.SnapApi; 6 | import com.midtrans.httpclient.TransactionApi; 7 | import org.json.JSONObject; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import java.util.Map; 16 | 17 | import static com.midtrans.sample.data.Constant.sandboxServerKey; 18 | 19 | /** 20 | * This is sample springboot controller for implement Midtrans mobile SDK. 21 | * You need to setup Frontend (Midtrans SDK Config) into your mobile app that using Midtrans mobile SDK. 22 | * 23 | * more details: https://mobile-docs.midtrans.com/#getting-started 24 | */ 25 | @RestController 26 | public class MobileSdkBackendController { 27 | 28 | /** 29 | * Midtrans java sample use, Using static method and Midtrans Config {@link Config}. 30 | * This is a new static method, the config will use for request Snap token on Midtrans API static (SnapApi class). 31 | * {@link SnapApi} 32 | * Sample use on mobile sdk backend Controller @line 47 33 | * 34 | * also you can put others config, like enableLog, timeConnect, proxy, idempotent-key, etc. 35 | */ 36 | private Config configOptions = Config.builder() 37 | .setServerKey(sandboxServerKey) 38 | .setIsProduction(false) 39 | .setPaymentOverrideNotification("https://midtrans-java.herokuapp.com/payment-status-notification-handler") 40 | .build(); 41 | 42 | 43 | // API `/charge` for mobile SDK to get Snap Token 44 | @PostMapping(value = "/charge", produces = MediaType.APPLICATION_JSON_VALUE) 45 | public ResponseEntity createTokeSnap(@RequestBody Map body) { 46 | try { 47 | JSONObject result = SnapApi.createTransaction(body, configOptions); 48 | return new ResponseEntity<>(result.toString(), HttpStatus.OK); 49 | } catch (MidtransError midtransError) { 50 | midtransError.printStackTrace(); 51 | return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); 52 | } 53 | } 54 | 55 | @PostMapping(value = "/payment-status-notification-handler", produces = MediaType.APPLICATION_JSON_VALUE) 56 | public ResponseEntity mobileHandleNotification(@RequestBody Map body) { 57 | String notifResponse = null; 58 | if (!(body.isEmpty())) { 59 | //Get Midtrans transaction ID from notification body 60 | String orderId = (String) body.get("transaction_id"); 61 | 62 | // Get status transaction to api with transaction id 63 | JSONObject transactionResult = null; 64 | try { 65 | transactionResult = TransactionApi.checkTransaction(orderId, configOptions); 66 | } catch (MidtransError midtransError) { 67 | midtransError.printStackTrace(); 68 | } 69 | 70 | String transactionStatus = (String) transactionResult.get("transaction_status"); 71 | String fraudStatus = (String) transactionResult.get("fraud_status"); 72 | 73 | notifResponse = "Transaction notification received. Order ID: " + orderId + ". Transaction status: " + transactionStatus + ". Fraud status: " + fraudStatus; 74 | System.out.println(notifResponse); 75 | 76 | if (transactionStatus.equals("capture")) { 77 | if (fraudStatus.equals("challenge")) { 78 | // TODO set transaction status on your database to 'challenge' e.g: 'Payment status challenged. Please take action on your Merchant Administration Portal 79 | } else if (fraudStatus.equals("accept")) { 80 | // TODO set transaction status on your database to 'success' 81 | } 82 | } else if (transactionStatus.equals("cancel") || transactionStatus.equals("deny") || transactionStatus.equals("expire")) { 83 | // TODO set transaction status on your database to 'failure' 84 | } else if (transactionStatus.equals("pending")) { 85 | // TODO set transaction status on your database to 'pending' / waiting payment 86 | } 87 | } 88 | return new ResponseEntity<>(notifResponse, HttpStatus.OK); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/controller/SnapController.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample.controller; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.ConfigFactory; 5 | import com.midtrans.Midtrans; 6 | import com.midtrans.httpclient.SnapApi; 7 | import com.midtrans.httpclient.error.MidtransError; 8 | import com.midtrans.service.MidtransSnapApi; 9 | import com.midtrans.sample.data.DataMockup; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.ui.Model; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestMethod; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | 17 | import java.util.ArrayList; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | import static com.midtrans.sample.data.Constant.sandboxClientKey; 24 | import static com.midtrans.sample.data.Constant.sandboxServerKey; 25 | 26 | @Controller 27 | public class SnapController { 28 | 29 | //Data transaction Mockup 30 | @Autowired 31 | private DataMockup dataMockup; 32 | 33 | @RequestMapping(value = "/snap", method = RequestMethod.GET) 34 | public String snap(Model model) { 35 | Map objectMap = dataMockup.initDataMock(); 36 | model.addAttribute("data", objectMap); 37 | return "snap/snap"; 38 | } 39 | 40 | @RequestMapping(value = "/snap/check-out", method = RequestMethod.POST) 41 | public String checkout(@RequestParam(value = "enablePay", required = false) List listPay, 42 | @RequestParam(value = "snapType") String snapType, 43 | Model model) throws MidtransError { 44 | 45 | Midtrans.clientKey = sandboxClientKey; 46 | Midtrans.serverKey = sandboxServerKey; 47 | // Get ClientKey from Midtrans Configuration class 48 | String clientKey = Midtrans.getClientKey(); 49 | 50 | // New Map Object for JSON raw request body 51 | Map requestBody = new HashMap<>(); 52 | 53 | // Add enablePayment from @RequestParam to dataMockup 54 | List paymentList = new ArrayList<>(); 55 | if (listPay != null) { 56 | paymentList.addAll(listPay); 57 | } 58 | Map creditCard = new HashMap<>(); 59 | creditCard.put("secure", "true"); 60 | dataMockup = new DataMockup(); 61 | dataMockup.creditCard(creditCard); 62 | dataMockup.enablePayments(paymentList); 63 | 64 | // PutAll data mockUp to requestBody 65 | requestBody.putAll(dataMockup.initDataMock()); 66 | 67 | // send data to frontEnd snapPopUp 68 | if (snapType.equals("snap")) { 69 | model.addAttribute("result", requestBody); 70 | model.addAttribute("clientKey", clientKey); 71 | // token object getData token to API with createTransactionToken() method return String token 72 | model.addAttribute("transactionToken", SnapApi.createTransactionToken(requestBody)); 73 | return "snap/check-out"; 74 | 75 | // send data to frontEnd redirect-url 76 | } else { 77 | model.addAttribute("result", requestBody); 78 | // redirectURL get url redirect to API with createTransactionRedirectUrl() method, with return String url redirect 79 | model.addAttribute("redirectURL", SnapApi.createTransactionRedirectUrl(requestBody)); 80 | return "snap/check-out"; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/controller/TokenizationSdkController.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample.controller; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.ConfigFactory; 5 | import com.midtrans.httpclient.error.MidtransError; 6 | import com.midtrans.service.MidtransCoreApi; 7 | import org.json.JSONObject; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.Map; 14 | 15 | import static com.midtrans.sample.data.Constant.sandboxClientKey; 16 | import static com.midtrans.sample.data.Constant.sandboxServerKey; 17 | 18 | @RestController 19 | @RequestMapping("/tokenization") 20 | public class TokenizationSdkController { 21 | 22 | /** 23 | * Midtrans Config library java sample, 24 | * also you can put others config, like enableLog, timeConnect, proxy, etc. 25 | */ 26 | Config configOptions = Config.builder() 27 | .setServerKey(sandboxServerKey) 28 | .setClientKey(sandboxClientKey) 29 | .setIsProduction(false) 30 | .setPaymentOverrideNotification("https://midtrans-java.herokuapp.com/payment-status-notification-handler") 31 | .build(); 32 | 33 | /** 34 | * Midtrans java sample use `com.midtrans`: Using Midtrans Config class {@link Config}. 35 | * The config will use method from Object MidtransCoreAPI class library 36 | * {@link MidtransCoreApi} 37 | * Sample use on Charge Controller @line 59 38 | */ 39 | MidtransCoreApi coreApi = new ConfigFactory(configOptions).getCoreApi(); 40 | 41 | 42 | // API `/v2/pay/account` for Tokenization SDK to linking payment 43 | @PostMapping(value = "/v2/pay/account", produces = MediaType.APPLICATION_JSON_VALUE) 44 | public ResponseEntity linkPaymentAccount(@RequestBody Map body) { 45 | try { 46 | JSONObject result = coreApi.linkPaymentAccount(body); 47 | return new ResponseEntity<>(result.toString(), HttpStatus.OK); 48 | } catch (MidtransError midtransError) { 49 | midtransError.printStackTrace(); 50 | return new ResponseEntity<>(midtransError.getResponseBody(), HttpStatus.valueOf(midtransError.getStatusCode())); 51 | } 52 | } 53 | 54 | // API `/v2/pay/account/{accountId}` for Tokenization SDK to get account details 55 | @GetMapping(value = "/v2/pay/account/{accountId}", produces = MediaType.APPLICATION_JSON_VALUE) 56 | public ResponseEntity getPaymentAccount(@PathVariable String accountId) { 57 | try { 58 | JSONObject result = coreApi.getPaymentAccount(accountId); 59 | return new ResponseEntity<>(result.toString(), HttpStatus.OK); 60 | } catch (MidtransError midtransError) { 61 | midtransError.printStackTrace(); 62 | return new ResponseEntity<>(midtransError.getResponseBody(), HttpStatus.valueOf(midtransError.getStatusCode())); 63 | } 64 | } 65 | 66 | // API `/v2/charge` for Tokenization SDK request charge 67 | @PostMapping(value = "/v2/charge", produces = MediaType.APPLICATION_JSON_VALUE) 68 | public ResponseEntity charge(@RequestBody Map body) { 69 | //uncomment this if you want set idempotency-key 70 | //coreApi.apiConfig().setPaymentIdempotencyKey("123321123312"); 71 | try { 72 | JSONObject result = coreApi.chargeTransaction(body); 73 | return new ResponseEntity<>(result.toString(), HttpStatus.OK); 74 | } catch (MidtransError midtransError) { 75 | midtransError.printStackTrace(); 76 | return new ResponseEntity<>(midtransError.getResponseBody(), HttpStatus.valueOf(midtransError.getStatusCode())); 77 | } 78 | } 79 | 80 | // API `/v2/pay/account/{accountId}` for Tokenization SDK to get account details 81 | @GetMapping(value = "/v2/pay/account/{accountId}/unbind", produces = MediaType.APPLICATION_JSON_VALUE) 82 | public ResponseEntity unlinkPaymentAccount(@PathVariable String accountId) { 83 | try { 84 | JSONObject result = coreApi.unlinkPaymentAccount(accountId); 85 | return new ResponseEntity<>(result.toString(), HttpStatus.OK); 86 | } catch (MidtransError midtransError) { 87 | midtransError.printStackTrace(); 88 | return new ResponseEntity<>(midtransError.getResponseBody(), HttpStatus.valueOf(midtransError.getStatusCode())); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/data/Constant.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample.data; 2 | 3 | public final class Constant { 4 | 5 | public static final String sandboxServerKey = "SB-Mid-server-TOq1a2AVuiyhhOjvfs3U_KeO"; 6 | public static final String sandboxClientKey = "SB-Mid-client-nKsqvar5cn60u2Lv"; 7 | public static final String secondServerKey = "SB-Mid-server-9Nm5c-HJE65AjLNtTX-bRjqm"; 8 | public static final String secondClientKey = "SB-Mid-client-GtbzK39rvs5El-bC"; 9 | 10 | public static final String sandboxCreatorKey = "IRIS-330198f0-e49d-493f-baae-585cfded355d"; 11 | public static final String sandboxApproverKey = "IRIS-1595c12b-6814-4e5a-bbbb-9bc18193f47b"; 12 | 13 | public static boolean isProduction = false; 14 | } 15 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/sample/data/DataMockup.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.sample.data; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.sql.Timestamp; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | @Component 12 | public class DataMockup { 13 | 14 | private List listedPayment; 15 | private Map creditCard; 16 | private String paymentType = ""; 17 | 18 | public void enablePayments(List listPayment) { 19 | listedPayment = new ArrayList<>(); 20 | listedPayment.addAll(listPayment); 21 | } 22 | 23 | public void setPaymentType(String paymentType) { 24 | this.paymentType = paymentType; 25 | } 26 | 27 | public void creditCard(Map params) { 28 | creditCard = new HashMap<>(); 29 | creditCard.putAll(params); 30 | } 31 | 32 | public Map initDataMock() { 33 | Timestamp timestamp = new Timestamp(System.currentTimeMillis()); 34 | 35 | Map transDetail = new HashMap<>(); 36 | transDetail.put("order_id", "MID_JAVA_DEMO_" + timestamp.getTime()); 37 | transDetail.put("gross_amount", "265000"); 38 | 39 | List> items = new ArrayList<>(); 40 | Map item1 = new HashMap<>(); 41 | item1.put("id", "ID001"); 42 | item1.put("price", "15000"); 43 | item1.put("quantity", "1"); 44 | item1.put("name", "Sendal Karet Rumahan"); 45 | item1.put("brand", "Suwaslow"); 46 | item1.put("category", "Sanitasi"); 47 | item1.put("merchant_name", "SnowlID"); 48 | 49 | Map item2 = new HashMap<>(); 50 | item2.put("id", "ID002"); 51 | item2.put("price", "200000"); 52 | item2.put("quantity", "1"); 53 | item2.put("name", "Mantel Hujan"); 54 | item2.put("brand", "Excel"); 55 | item2.put("category", "Sanitasi"); 56 | item2.put("merchant_name", "SnowlID"); 57 | 58 | Map item3 = new HashMap<>(); 59 | item3.put("id", "ID003"); 60 | item3.put("price", "50000"); 61 | item3.put("quantity", "1"); 62 | item3.put("name", "Sarung Tangan Karet"); 63 | item3.put("brand", "Cap Anti Sobek"); 64 | item3.put("category", "Sanitasi"); 65 | item3.put("merchant_name", "SnowlID"); 66 | 67 | items.add(item1); 68 | items.add(item2); 69 | items.add(item3); 70 | 71 | Map billingAddres = new HashMap<>(); 72 | billingAddres.put("first_name", "Zaki"); 73 | billingAddres.put("last_name", "Ibrahim"); 74 | billingAddres.put("email", "midtrans-java@mailnesia.com"); 75 | billingAddres.put("phone", "0928282828"); 76 | billingAddres.put("address", "Jalan Iskandarsyah II"); 77 | billingAddres.put("city", "Jakarta Selatan"); 78 | billingAddres.put("postal_code", "10120"); 79 | billingAddres.put("country_code", "IDN"); 80 | 81 | Map custDetail = new HashMap<>(); 82 | custDetail.put("first_name", "Zaki"); 83 | custDetail.put("last_name", "ibrahim"); 84 | custDetail.put("email", "midtrans-java@mailnesia.com"); 85 | custDetail.put("phone", "62783737373"); 86 | custDetail.put("billing_address", billingAddres); 87 | 88 | Map body = new HashMap<>(); 89 | if (creditCard != null) { 90 | body.put("credit_card", creditCard); 91 | } 92 | body.put("transaction_details", transDetail); 93 | body.put("item_details", items); 94 | body.put("customer_details", custDetail); 95 | if (!paymentType.isEmpty()) { 96 | body.put("payment_type", paymentType); 97 | } 98 | if (listedPayment != null) { 99 | body.put("enabled_payments", listedPayment); 100 | } 101 | 102 | return body; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /example/src/main/java/com/midtrans/snapbi/SnapBiWebhookServer.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.snapbi; 2 | 3 | import com.sun.net.httpserver.HttpExchange; 4 | import com.sun.net.httpserver.HttpHandler; 5 | import com.sun.net.httpserver.HttpServer; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | import java.net.InetSocketAddress; 11 | import java.nio.charset.StandardCharsets; 12 | import java.util.*; 13 | 14 | public class SnapBiWebhookServer { 15 | public static void main(String[] args) throws IOException { 16 | int port = 3000; 17 | HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); 18 | server.createContext("/webhook", new WebhookHandler()); 19 | server.setExecutor(null); 20 | server.start(); 21 | System.out.println("Server started on port " + port); 22 | } 23 | 24 | static class WebhookHandler implements HttpHandler { 25 | @Override 26 | public void handle(HttpExchange exchange) throws IOException { 27 | if ("POST".equals(exchange.getRequestMethod())) { 28 | // Read the request body 29 | InputStream requestBody = exchange.getRequestBody(); 30 | String body = new Scanner(requestBody, StandardCharsets.UTF_8.name()).useDelimiter("\\A").next(); 31 | Map> headers = exchange.getRequestHeaders(); 32 | 33 | // Get specific header values (x-signature and x-timestamp) 34 | String signature = headers.getOrDefault("X-Signature", java.util.Collections.emptyList()).stream().findFirst().orElse(null); 35 | String timestamp = headers.getOrDefault("X-Timestamp", java.util.Collections.emptyList()).stream().findFirst().orElse(null); 36 | 37 | String publicKey = "-----BEGIN PUBLIC KEY-----" 38 | +"ACBDefghijkklmn/fboOoctcthr8aJ5AOEpCFLrsCSgAtmtcHxBHq9miZyHFf4juNBpvvRrVlCLzyhNOkjKDNj9PO/MZabcdefGHIJKLMN" 39 | +"-----END PUBLIC KEY-----"; 40 | 41 | SnapBiConfig.setSnapBiPublicKey(publicKey); 42 | // get the url path that comes after `/webhook` 43 | String requestURI = exchange.getRequestURI().toString(); 44 | String basePath = "/webhook"; 45 | String remainingPath = requestURI.substring(basePath.length()); 46 | 47 | Boolean isVerified = false; 48 | try { 49 | isVerified = 50 | SnapBi.notification() 51 | .withNotificationPayload(body) 52 | .withSignature(signature) 53 | .withTimeStamp(timestamp) 54 | .withNotificationUrlPath(remainingPath) 55 | .isWebhookNotificationVerified(); 56 | } catch (Exception e) { 57 | throw new RuntimeException(e.getMessage()); 58 | } 59 | String response = "Webhook received successfully, its verified = " + isVerified; 60 | exchange.sendResponseHeaders(200, response.length()); 61 | try (OutputStream os = exchange.getResponseBody()) { 62 | os.write(response.getBytes()); 63 | } 64 | } else { 65 | // Method not allowed 66 | exchange.sendResponseHeaders(405, -1); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=7777 2 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/coreapi/core-api.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Midtrans Snap JAVA Springboot Demo 7 | 8 | 9 |
10 | 11 |
12 |

Midtrans CORE API Demo

13 |
14 |
15 |

16 | Your cart 17 | 3 18 |

19 |
    20 |
  • 21 |
    22 |
    Sendal Karet Rumahan
    23 | Ukuran 7 24 |
    25 | Rp.15.0000 26 |
  • 27 |
  • 28 |
    29 |
    Mantel Hujan
    30 | Ukuran XL 31 |
    32 | Rp.200.000 33 |
  • 34 |
  • 35 |
    36 |
    Sarung Tangan Karet
    37 | 1Pack Isi 17Pcs 38 |
    39 | Rp.50.000 40 |
  • 41 |
  • 42 | Total (Rp) 43 | Rp.265.000 44 |
  • 45 |
46 |
47 |
48 | Your billing & Shipping address 49 |
50 |
    51 |
    52 |
    53 |
    54 |
    55 |
    56 |
    57 |
    58 |
    59 |
    60 |
    61 |
    62 |
    63 |
    64 |
    65 | 66 |
    67 |
    68 |
    69 |
    70 |
71 | 72 |
73 |
74 |
75 | 76 |
77 |
78 |
79 |
80 | 81 |
82 |
83 | 84 |
85 |
86 | 87 |
88 |
89 |
90 |
91 |
92 | 93 |
94 | 95 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/fragments/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 53 |
54 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Midtrans API Intergration 5 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 |
16 |
17 |

Midtrans Java Library Demo

18 |

This is java springboot demo app to consume Midtrans API with Midtrans Java Library.

19 |

Please, read Midtrans Docs if you need details 20 | documentation. 21 |

22 | 23 | 24 | 25 |
26 |
27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/iris/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Midtrans API Intergration 5 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 |
16 |
17 |

Iris Disbursement

18 |
Current Balance
19 |

Rp. ,-

20 |
21 | 22 |

Transaction History : -

23 |
24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 36 | 37 |
29 |
35 |
38 |
39 |
40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 14 | 15 | 16 |
17 | 18 | 19 |
20 |

Midtrans SNAP Demo

21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 | 31 | 34 | 37 |
38 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/mobile/mobile-sdk.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Midtrans Snap JAVA Springboot Demo 7 | 8 | 9 |
10 | 11 |
12 |
13 |
14 |

Midtrans Mobile SDK Demo

15 | 17 | 19 |
20 |
21 | 22 |
23 |
24 | 26 |
27 | 28 |
29 |
30 |
31 | 32 |
33 |   Testing cards:
34 | 
35 |     For 3D Secure:
36 |     Visa success              4811 1111 1111 1114
37 |     Visa deny by bank         4711 1111 1111 1115
38 |     Visa deny by FDS          4611 1111 1111 1116
39 | 
40 |     MasterCard success        5211 1111 1111 1117
41 |     MasterCard deny by bank   5111 1111 1111 1118
42 |     MasterCard deny by FDS    5411 1111 1111 1115
43 | 
44 |     Challenge by FDS          4511 1111 1111 1117
45 |     
46 |
47 |
48 |
49 |
50 |

The Sample app Android SDK consume Java sample backend to get Snap token with our Midtrans-Java-Library.

51 |

There is only one endpoint that are required to use Midtrans mobile SDK `/charge`. Sample controller are located in the MobileSdkController

52 |

For more detailed about Midtrans SDK, Please read Midtrans Mobile SDK documentation.

53 |

55 | 57 | 59 |

60 |
61 | 62 |
63 |
64 |
65 | 66 |
67 | 68 | -------------------------------------------------------------------------------- /example/src/main/resources/templates/snap/check-out.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | Midtrans Snap JAVA Springboot Demo 6 | 7 | 8 |
9 | 10 | 11 |
12 |

Midtrans SNAP Demo

13 |
14 |
15 |

16 | Your cart 17 | 3 18 |

19 |
    20 |
  • 21 |
    22 |
    Sendal Karet Rumahan
    23 | Ukuran 7 24 |
    25 | Rp.15.0000 26 |
  • 27 |
  • 28 |
    29 |
    Mantel Hujan
    30 | Ukuran XL 31 |
    32 | Rp.200.000 33 |
  • 34 |
  • 35 |
    36 |
    Sarung Tangan Karet
    37 | 1Pack Isi 17Pcs 38 |
    39 | Rp.50.000 40 |
  • 41 |
  • 42 | Total (Rp) 43 | Rp.265.000 44 |
  • 45 |
46 |
47 |
48 |

Billing & Shipping Address

49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 61 |
62 |
63 |
64 |
65 | 66 |
67 |
68 |
69 |
70 |
71 |
72 | 73 |
74 | 75 |
JSON result will appear here after payment:
76 |
77 |
78 |
79 |
80 |
81 | 82 |
83 | 85 | 116 | 117 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/ConfigFactory.java: -------------------------------------------------------------------------------- 1 | package com.midtrans; 2 | 3 | import com.midtrans.service.MidtransIrisApi; 4 | import com.midtrans.service.impl.MidtransCoreApiImpl; 5 | import com.midtrans.service.impl.MidtransIrisApiImpl; 6 | import com.midtrans.service.impl.MidtransSnapApiImpl; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * Convenience "factory" class to facilitate setup for connection to Midtrans API using SnapAPI or CoreAPI. 11 | */ 12 | public class ConfigFactory { 13 | 14 | private Config config; 15 | 16 | /** 17 | * ConfigFactory constructor 18 | * 19 | * @param config Midtrans {@link Config configuration} (not null) 20 | */ 21 | public ConfigFactory(Config config) { 22 | if (config == null) { 23 | throw new NullPointerException("Config is null"); 24 | } 25 | this.config = config; 26 | } 27 | 28 | /** 29 | * Get CoreAPI gateway 30 | * 31 | * @return {@link MidtransCoreApiImpl MidtransCoreApi} to connecting midtrans gateway CoreAPI 32 | */ 33 | public MidtransCoreApiImpl getCoreApi() { 34 | return new MidtransCoreApiImpl(config); 35 | } 36 | 37 | /** 38 | * Get SnapAPI gateway 39 | * 40 | * @return {@link MidtransSnapApiImpl MidtransSnapApi} to connecting midtrans gateway SnapAPI 41 | */ 42 | public MidtransSnapApiImpl getSnapApi() { 43 | return new MidtransSnapApiImpl(config); 44 | } 45 | 46 | public MidtransIrisApi getIrisApi() { 47 | return new MidtransIrisApiImpl(config); 48 | } 49 | 50 | /** 51 | * Get midtrans config. 52 | * 53 | * @return {@link Config configuration} that will be used by the HTTP Client when sending request to Midtrans API 54 | */ 55 | public Config getConfig() { 56 | return config; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/Midtrans.java: -------------------------------------------------------------------------------- 1 | package com.midtrans; 2 | 3 | import com.midtrans.proxy.ProxyConfig; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class Midtrans { 8 | 9 | public static volatile String serverKey; 10 | public static volatile String clientKey; 11 | 12 | public static volatile boolean isProduction; 13 | public static volatile boolean enableLog; 14 | 15 | private static volatile String paymentAppendNotification; 16 | private static volatile String paymentOverrideNotification; 17 | 18 | private static volatile int connectTimeout = ConfigBuilder.DEFAULT_CONNECT_TIMEOUT; 19 | private static volatile int readTimeout = ConfigBuilder.DEFAULT_READ_TIMEOUT; 20 | private static volatile int maxConnectionPool = ConfigBuilder.DEFAULT_MAX_CONNECTION_POOL_SIZE; 21 | private static volatile int keepAliveDuration = ConfigBuilder.DEFAULT_KEEP_ALIVE_DURATION; 22 | private static volatile int writeTimeout = ConfigBuilder.DEFAULT_WRITE_TIMEOUT; 23 | private static volatile TimeUnit httpClientTimeUnit; 24 | 25 | private static final String SANDBOX_BASE_URL = "https://api.sandbox.midtrans.com/"; 26 | private static final String PRODUCTION_BASE_URL = "https://api.midtrans.com/"; 27 | 28 | private static final String SNAP_PRODUCTION_BASE_URL = "https://app.midtrans.com/snap/v1/transactions"; 29 | private static final String SNAP_SANDBOX_BASE_URL = "https://app.sandbox.midtrans.com/snap/v1/transactions"; 30 | 31 | private static final String IRIS_PRODUCTION_BASE_URL = "https://app.midtrans.com/iris/api/v1/"; 32 | private static final String IRIS_SANDBOX_BASE_URL = "https://app.sandbox.midtrans.com/iris/api/v1/"; 33 | 34 | private static volatile ProxyConfig proxyConfig; 35 | 36 | public static boolean isProduction() { 37 | return isProduction; 38 | } 39 | 40 | public static String getSandboxBaseUrl() { 41 | return SANDBOX_BASE_URL; 42 | } 43 | 44 | public static String getProductionBaseUrl() { 45 | return PRODUCTION_BASE_URL; 46 | } 47 | 48 | public static String getSnapProductionBaseUrl() { 49 | return SNAP_PRODUCTION_BASE_URL; 50 | } 51 | 52 | public static String getSnapSandboxBaseUrl() { 53 | return SNAP_SANDBOX_BASE_URL; 54 | } 55 | 56 | public static String getIrisProductionBaseUrl() { 57 | return IRIS_PRODUCTION_BASE_URL; 58 | } 59 | 60 | public static String getIrisSandboxBaseUrl() { 61 | return IRIS_SANDBOX_BASE_URL; 62 | } 63 | 64 | public static String getPaymentAppendNotification() { 65 | return paymentAppendNotification; 66 | } 67 | 68 | public static String getPaymentOverrideNotification() { 69 | return paymentOverrideNotification; 70 | } 71 | 72 | public static int getConnectTimeout() { 73 | return (connectTimeout < -1) ? ConfigBuilder.DEFAULT_CONNECT_TIMEOUT : connectTimeout; 74 | } 75 | 76 | public static int getReadTimeout() { 77 | return (readTimeout < -1) ? ConfigBuilder.DEFAULT_READ_TIMEOUT : readTimeout; 78 | } 79 | 80 | public static int getMaxConnectionPool() { 81 | return (maxConnectionPool < -1) ? ConfigBuilder.DEFAULT_MAX_CONNECTION_POOL_SIZE : maxConnectionPool; 82 | } 83 | 84 | public static int getKeepAliveDuration() { 85 | return (keepAliveDuration < -1) ? ConfigBuilder.DEFAULT_KEEP_ALIVE_DURATION : keepAliveDuration; 86 | } 87 | 88 | public static int getWriteTimeout() { 89 | return (writeTimeout < -1) ? ConfigBuilder.DEFAULT_WRITE_TIMEOUT : writeTimeout; 90 | } 91 | 92 | public static TimeUnit getHttpClientTimeUnit() { 93 | return (httpClientTimeUnit != null) ? httpClientTimeUnit : TimeUnit.SECONDS; 94 | } 95 | 96 | public static String getServerKey() { 97 | return serverKey; 98 | } 99 | 100 | public static String getClientKey() { 101 | return clientKey; 102 | } 103 | 104 | public static void paymentAppendNotification(String xAppendNotification) { 105 | paymentAppendNotification = xAppendNotification; 106 | } 107 | 108 | public static void paymentOverrideNotification(String xOverrideNotification) { 109 | paymentOverrideNotification = xOverrideNotification; 110 | } 111 | 112 | public static ProxyConfig getProxyConfig() { 113 | return proxyConfig; 114 | } 115 | 116 | public static void setConnectTimeout(int timeout) { 117 | connectTimeout = timeout; 118 | } 119 | 120 | public static void setReadTimeout(int timeout) { 121 | readTimeout = timeout; 122 | } 123 | 124 | public static void setMaxConnectionPool(int connectionPool) { 125 | maxConnectionPool = connectionPool; 126 | } 127 | 128 | public static void setKeepAliveDuration(int aliveDuration) { 129 | keepAliveDuration = aliveDuration; 130 | } 131 | 132 | public static void setWriteTimeout(int timeout) { 133 | writeTimeout = timeout; 134 | } 135 | 136 | public static void setHttpClientTimeUnit(TimeUnit timeUnit) { 137 | httpClientTimeUnit = timeUnit; 138 | } 139 | 140 | public static boolean enableLog() { 141 | return enableLog; 142 | } 143 | 144 | public static void setProxyConfig(ProxyConfig proxyConfig) { 145 | Midtrans.proxyConfig = proxyConfig; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/httpclient/SnapApi.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.httpclient; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.error.MidtransError; 5 | import com.midtrans.utils.Utility; 6 | import org.json.JSONObject; 7 | 8 | import java.util.Map; 9 | 10 | public class SnapApi { 11 | 12 | public static JSONObject createTransaction(Map requestBody, Config configOptions) throws MidtransError { 13 | return new JSONObject((String) APIHttpClient.request( 14 | APIHttpClient.POST, 15 | configOptions.getSnapApiURL(), 16 | configOptions, 17 | requestBody 18 | )); 19 | } 20 | 21 | public static JSONObject createTransaction(Map requestBody) throws MidtransError { 22 | return new JSONObject((String) APIHttpClient.request( 23 | APIHttpClient.POST, 24 | Config.getGlobalConfig().getSnapApiURL(), 25 | Config.getGlobalConfig(), 26 | requestBody 27 | )); 28 | } 29 | 30 | public static String createTransactionToken(Map requestBody) throws MidtransError { 31 | return createTransaction(requestBody).getString("token"); 32 | } 33 | 34 | public static String createTransactionToken(Map requestBody, Config configOptions) throws MidtransError { 35 | return createTransaction(requestBody, configOptions).getString("token"); 36 | } 37 | 38 | public static String createTransactionRedirectUrl(Map requestBody) throws MidtransError { 39 | return createTransaction(requestBody).getString("redirect_url"); 40 | } 41 | 42 | public static String createTransactionRedirectUrl(Map requestBody, Config configOptions) throws MidtransError { 43 | return createTransaction(requestBody, configOptions).getString("redirect_url"); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/httpclient/TransactionApi.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.httpclient; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.error.MidtransError; 5 | import org.json.JSONObject; 6 | 7 | import java.util.Map; 8 | 9 | import static com.midtrans.httpclient.CoreApi.API_VERSION2; 10 | 11 | 12 | public class TransactionApi { 13 | 14 | public static JSONObject checkTransaction(String param, Config configOptions) throws MidtransError { 15 | return new JSONObject((String) APIHttpClient.request( 16 | APIHttpClient.GET, configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/status", 17 | configOptions, 18 | null 19 | )); 20 | } 21 | 22 | public static JSONObject checkTransaction(String param) throws MidtransError { 23 | return checkTransaction(param, Config.getGlobalConfig()); 24 | } 25 | 26 | public static JSONObject approveTransaction(String param, Config configOptions) throws MidtransError { 27 | return new JSONObject((String) APIHttpClient.request( 28 | APIHttpClient.POST, configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/approve", 29 | configOptions, 30 | null 31 | )); 32 | } 33 | 34 | public static JSONObject approveTransaction(String param) throws MidtransError { 35 | return approveTransaction(param, Config.getGlobalConfig()); 36 | } 37 | 38 | public static JSONObject denyTransaction(String param, Config configOptions) throws MidtransError { 39 | return new JSONObject((String) APIHttpClient.request( 40 | APIHttpClient.POST, 41 | configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/deny", 42 | configOptions, 43 | null 44 | )); 45 | } 46 | 47 | public static JSONObject denyTransaction(String param) throws MidtransError { 48 | return denyTransaction(param, Config.getGlobalConfig()); 49 | } 50 | 51 | public static JSONObject cancelTransaction(String param) throws MidtransError { 52 | return cancelTransaction(param, Config.getGlobalConfig()); 53 | } 54 | 55 | public static JSONObject cancelTransaction(String param, Config configOptions) throws MidtransError { 56 | return new JSONObject((String) APIHttpClient.request( 57 | APIHttpClient.POST, 58 | configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/cancel", 59 | configOptions, 60 | null 61 | )); 62 | } 63 | 64 | public static JSONObject expireTransaction(String param, Config configOptions) throws MidtransError { 65 | return new JSONObject((String) APIHttpClient.request( 66 | APIHttpClient.POST, 67 | configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/expire", 68 | configOptions, 69 | null 70 | )); 71 | } 72 | 73 | public static JSONObject expireTransaction(String param) throws MidtransError { 74 | return expireTransaction(param, Config.getGlobalConfig()); 75 | } 76 | 77 | public static JSONObject refundTransaction(String param, Map requestBody, Config configOptions) throws MidtransError { 78 | return new JSONObject((String) APIHttpClient.request( 79 | APIHttpClient.POST, configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/refund", 80 | configOptions, 81 | requestBody 82 | )); 83 | } 84 | 85 | public static JSONObject refundTransaction(String param, Map requestBody) throws MidtransError { 86 | return refundTransaction(param, requestBody, Config.getGlobalConfig()); 87 | } 88 | 89 | public static JSONObject directRefundTransaction(String param, Map requestBody, Config configOptions) throws MidtransError { 90 | return new JSONObject((String) APIHttpClient.request( 91 | APIHttpClient.POST, 92 | configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/refund/online/direct", 93 | configOptions, 94 | requestBody 95 | )); 96 | } 97 | 98 | public static JSONObject directRefundTransaction(String param, Map requestBody) throws MidtransError { 99 | return directRefundTransaction(param, requestBody, Config.getGlobalConfig()); 100 | } 101 | 102 | public static JSONObject captureTransaction(Map requestBody, Config configOptions) throws MidtransError { 103 | return new JSONObject((String) APIHttpClient.request( 104 | APIHttpClient.POST, 105 | configOptions.getCoreApiURL() + API_VERSION2 + "/" + "capture", 106 | configOptions, 107 | requestBody 108 | )); 109 | } 110 | 111 | public static JSONObject captureTransaction(Map requestBody) throws MidtransError { 112 | return captureTransaction(requestBody, Config.getGlobalConfig()); 113 | } 114 | 115 | public static JSONObject getStatusB2b(String param, Config configOptions) throws MidtransError { 116 | return new JSONObject((String) APIHttpClient.request( 117 | APIHttpClient.GET, 118 | configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/status/b2b", 119 | configOptions, 120 | null 121 | )); 122 | } 123 | 124 | public static JSONObject getStatusB2b(String param) throws MidtransError { 125 | return getStatusB2b(param, Config.getGlobalConfig()); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/httpclient/error/MidtransError.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.httpclient.error; 2 | 3 | import lombok.Getter; 4 | import okhttp3.Response; 5 | 6 | /** 7 | * MidtransError class to catch error messages 8 | */ 9 | @Getter 10 | public class MidtransError extends Exception { 11 | 12 | private String message; 13 | private Integer statusCode; 14 | private String responseBody; 15 | private Response response; 16 | 17 | /** 18 | * Constructs a Midtrans exception with the message 19 | * 20 | * @param message 21 | */ 22 | public MidtransError(String message) { 23 | super(message); 24 | this.message = message; 25 | } 26 | 27 | /** 28 | * Constructs a Midtrans exception with the specified cause 29 | * 30 | * @param cause 31 | */ 32 | public MidtransError(Throwable cause) { 33 | super(cause); 34 | } 35 | 36 | /** 37 | * Constructs a Midtrans exception with message and specified cause 38 | * 39 | * @param message 40 | * @param cause 41 | */ 42 | public MidtransError(String message, Throwable cause) { 43 | super(message, cause); 44 | this.message = message; 45 | } 46 | 47 | /** 48 | * Constructs a Midtrans exception with the specified details. 49 | * 50 | * @param message 51 | * @param statusCode 52 | * @param data 53 | * @param response 54 | */ 55 | public MidtransError(String message, Integer statusCode, String data, Response response) { 56 | this(message, statusCode, data, response, null); 57 | } 58 | 59 | /** 60 | * Constructs a Midtrans exception with the specified details. 61 | * 62 | * @param message 63 | * @param statusCode 64 | * @param responseBody 65 | * @param response 66 | * @param e 67 | */ 68 | public MidtransError(String message, Integer statusCode, String responseBody, Response response, Throwable e) { 69 | super(message, e); 70 | this.message = message; 71 | this.statusCode = statusCode; 72 | this.responseBody = responseBody; 73 | this.response = response; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/proxy/ProxyConfig.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.proxy; 2 | 3 | /** 4 | * Merchant proxy configuration 5 | */ 6 | public class ProxyConfig { 7 | 8 | private String host; 9 | private int port; 10 | private String username; 11 | private String password; 12 | 13 | /** 14 | * Proxy config constructor. 15 | * 16 | * @param host the proxy server host address. 17 | * @param port the proxy server listening port. 18 | * @param username the username used to authenticate against the proxy server. 19 | * @param password the password used to authenticate against the proxy server. 20 | */ 21 | public ProxyConfig(String host, int port, String username, String password) { 22 | this.host = host; 23 | this.port = port; 24 | this.username = username; 25 | this.password = password; 26 | } 27 | 28 | /** 29 | * Get merchant proxy host configuration. 30 | * 31 | * @return Merchant proxy host config. 32 | */ 33 | public String getHost() { 34 | return host; 35 | } 36 | 37 | /** 38 | * Get merchant proxy port configuration 39 | * 40 | * @return Merchant proxy port config 41 | */ 42 | public int getPort() { 43 | return port; 44 | } 45 | 46 | /** 47 | * Get proxy username to connect to Veritrans API 48 | * 49 | * @return Merchant proxy username config 50 | */ 51 | public String getUsername() { 52 | return username; 53 | } 54 | 55 | /** 56 | * Get proxy password to connect to Veritrans API 57 | * 58 | * @return Merchant proxy password config 59 | */ 60 | public String getPassword() { 61 | return password; 62 | } 63 | 64 | /** 65 | * Initialize proxy with builder 66 | * 67 | * @return ProxyConfigBuilder 68 | */ 69 | public static ProxyConfigBuilder builder() { 70 | return new ProxyConfigBuilder(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/proxy/ProxyConfigBuilder.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.proxy; 2 | 3 | /** 4 | * Proxy configuration builder 5 | */ 6 | public final class ProxyConfigBuilder { 7 | private String host; 8 | private int port; 9 | private String username; 10 | private String password; 11 | 12 | /** 13 | * Set proxy host config 14 | * @param host Proxy host 15 | * @return ProxyConfigBuilder 16 | */ 17 | public ProxyConfigBuilder setHost(String host) { 18 | this.host = host; 19 | return this; 20 | } 21 | 22 | /** 23 | * Set proxy port config 24 | * @param port Proxy port 25 | * @return ProxyConfigBuilder 26 | */ 27 | public ProxyConfigBuilder setPort(final int port) { 28 | this.port = port; 29 | return this; 30 | } 31 | 32 | /** 33 | * Set proxy username config 34 | * @param username Proxy username config 35 | * @return ProxyConfigBuilder 36 | */ 37 | public ProxyConfigBuilder setUsername(String username) { 38 | this.username = username; 39 | return this; 40 | } 41 | 42 | /** 43 | * Set proxy password config 44 | * @param password Proxy password config 45 | * @return ProxyConfigBuilder 46 | */ 47 | public ProxyConfigBuilder setPassword(String password) { 48 | this.password = password; 49 | return this; 50 | } 51 | 52 | /** 53 | * Create proxy config 54 | * @return {@link com.midtrans.proxy.ProxyConfig Proxy configuration} 55 | */ 56 | public ProxyConfig build() { 57 | return new ProxyConfig(host, port, username, password); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/service/MidtransSnapApi.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.service; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.error.MidtransError; 5 | import org.json.JSONObject; 6 | import java.util.Map; 7 | 8 | /** 9 | * Gateway for midtrans SnapAPI 10 | */ 11 | public interface MidtransSnapApi { 12 | 13 | /** 14 | * Do re-set config Class like clientKey, serverKey, isProduction 15 | * 16 | * @return Config.class 17 | */ 18 | Config apiConfig(); 19 | 20 | /** 21 | * Do `/transactions` API request to SNAP API return RAW JSON with JSONObject 22 | * 23 | * @param params {Map Object} object of Core API JSON body as parameter, will be converted to JSON (more detail refer to: https://snap-docs.midtrans.com) 24 | * @return {JSONObject} - org.json Promise contains Object from JSON decoded response 25 | * @throws MidtransError when an exception was occurred during executing the request. 26 | */ 27 | JSONObject createTransaction(Map params) throws MidtransError; 28 | 29 | /** 30 | * Do `/transactions` API request to SNAP API return String token 31 | * @param params {Map Object} object of Core API JSON body as parameter, will be converted to JSON (more detail refer to: https://snap-docs.midtrans.com) 32 | * @return {String} return tokenId to processing on frontend with Snap.js for transaction with SNAP PopUp 33 | * @throws MidtransError when an exception was occurred during executing the request. 34 | */ 35 | String createTransactionToken(Map params) throws MidtransError; 36 | 37 | /** 38 | * Do `/transactions` API request to SNAP API return String redirectURL 39 | * @param params {Map Object} object of Core API JSON body as parameter, will be converted to JSON (more detail refer to: https://snap-docs.midtrans.com) 40 | * @return {String} - return redirectURL for processing transaction with SNAP Redirect 41 | * @throws MidtransError when an exception was occurred during executing the request. 42 | */ 43 | String createTransactionRedirectUrl(Map params) throws MidtransError; 44 | } -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/service/impl/MidtransCoreApiImpl.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.service.impl; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.CoreApi; 5 | import com.midtrans.httpclient.TransactionApi; 6 | import com.midtrans.httpclient.error.MidtransError; 7 | import com.midtrans.service.MidtransCoreApi; 8 | import org.json.JSONObject; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * Implements from {@link MidtransCoreApi MidtransCoreApi} 14 | */ 15 | public class MidtransCoreApiImpl implements MidtransCoreApi { 16 | 17 | private Config config; 18 | 19 | /** 20 | * CoreAPI constructor 21 | * 22 | * @param config Midtrans {@link Config configuration} 23 | */ 24 | public MidtransCoreApiImpl(Config config) { 25 | this.config = config; 26 | } 27 | 28 | @Override 29 | public Config apiConfig() { 30 | return config; 31 | } 32 | 33 | @Override 34 | public JSONObject chargeTransaction(Map body) throws MidtransError { 35 | return CoreApi.chargeTransaction(body, config); 36 | } 37 | 38 | @Override 39 | public JSONObject checkTransaction(String param) throws MidtransError { 40 | return TransactionApi.checkTransaction(param, config); 41 | } 42 | 43 | @Override 44 | public JSONObject approveTransaction(String param) throws MidtransError { 45 | return TransactionApi.approveTransaction(param, config); 46 | } 47 | 48 | @Override 49 | public JSONObject cancelTransaction(String param) throws MidtransError { 50 | return TransactionApi.cancelTransaction(param, config); 51 | } 52 | 53 | @Override 54 | public JSONObject expireTransaction(String param) throws MidtransError { 55 | return TransactionApi.expireTransaction(param, config); 56 | } 57 | 58 | @Override 59 | public JSONObject refundTransaction(String param, Map body) throws MidtransError { 60 | return TransactionApi.refundTransaction(param, body, config); 61 | } 62 | 63 | @Override 64 | public JSONObject cardToken(Map params) throws MidtransError { 65 | return CoreApi.cardToken(params, config); 66 | } 67 | 68 | @Override 69 | public JSONObject registerCard(Map params) throws MidtransError { 70 | return CoreApi.registerCard(params, config); 71 | } 72 | 73 | @Override 74 | public JSONObject cardPointInquiry(String tokenId) throws MidtransError { 75 | return CoreApi.cardPointInquiry(tokenId, config); 76 | } 77 | 78 | @Override 79 | public JSONObject captureTransaction(Map params) throws MidtransError { 80 | return TransactionApi.captureTransaction(params, config); 81 | } 82 | 83 | @Override 84 | public JSONObject getTransactionStatusB2B(String param) throws MidtransError { 85 | return TransactionApi.getStatusB2b(param, config); 86 | } 87 | 88 | @Override 89 | public JSONObject directRefundTransaction(String param, Map requestBody) throws MidtransError { 90 | return TransactionApi.directRefundTransaction(param, requestBody, config); 91 | } 92 | 93 | @Override 94 | public JSONObject denyTransaction(String param) throws MidtransError { 95 | return TransactionApi.denyTransaction(param, config); 96 | } 97 | 98 | @Override 99 | public JSONObject getBIN(String binNumber) throws MidtransError { 100 | return CoreApi.getBin(binNumber, config); 101 | } 102 | 103 | @Override 104 | public JSONObject createSubscription(Map subscriptionReq) throws MidtransError { 105 | return CoreApi.createSubscription(subscriptionReq, config); 106 | } 107 | 108 | @Override 109 | public JSONObject getSubscription(String subscriptionId) throws MidtransError { 110 | return CoreApi.getSubscription(subscriptionId, config); 111 | } 112 | 113 | @Override 114 | public JSONObject disableSubscription(String subscriptionId) throws MidtransError { 115 | return CoreApi.disableSubscription(subscriptionId, config); 116 | } 117 | 118 | @Override 119 | public JSONObject enableSubscription(String subscriptionId) throws MidtransError { 120 | return CoreApi.enableSubscription(subscriptionId, config); 121 | } 122 | 123 | @Override 124 | public JSONObject updateSubscription(String subscriptionId, Map subscriptionReq) throws MidtransError { 125 | return CoreApi.updateSubscription(subscriptionId, subscriptionReq, config); 126 | } 127 | 128 | @Override 129 | public JSONObject linkPaymentAccount(Map accountRequest) throws MidtransError { 130 | return CoreApi.linkPaymentAccount(accountRequest, config); 131 | } 132 | 133 | @Override 134 | public JSONObject getPaymentAccount(String accountId) throws MidtransError { 135 | return CoreApi.getPaymentAccount(accountId, config); 136 | } 137 | 138 | @Override 139 | public JSONObject unlinkPaymentAccount(String accountId) throws MidtransError { 140 | return CoreApi.unlinkPaymentAccount(accountId, config); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/service/impl/MidtransIrisApiImpl.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.service.impl; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.IrisApi; 5 | import com.midtrans.httpclient.error.MidtransError; 6 | import com.midtrans.service.MidtransIrisApi; 7 | import org.json.JSONArray; 8 | import org.json.JSONObject; 9 | 10 | import java.util.Map; 11 | 12 | public class MidtransIrisApiImpl implements MidtransIrisApi { 13 | private Config config; 14 | 15 | /** 16 | * IrisAPI constructor 17 | * 18 | * @param config Api Config class 19 | */ 20 | public MidtransIrisApiImpl(Config config) { 21 | this.config = config; 22 | } 23 | 24 | @Override 25 | public Config apiConfig() { 26 | return config; 27 | } 28 | 29 | @Override 30 | public String ping() throws MidtransError { 31 | return IrisApi.ping(); 32 | } 33 | 34 | @Override 35 | public JSONObject getBalance() throws MidtransError { 36 | return IrisApi.getBalance(config); 37 | } 38 | 39 | @Override 40 | public JSONObject createBeneficiaries(Map params) throws MidtransError { 41 | 42 | return IrisApi.createBeneficiaries(params, config); 43 | } 44 | 45 | @Override 46 | public JSONObject updateBeneficiaries(String aliasName, Map params) throws MidtransError { 47 | return IrisApi.updateBeneficiaries(aliasName, params, config); 48 | } 49 | 50 | @Override 51 | public JSONArray getBeneficiaries() throws MidtransError { 52 | return IrisApi.getBeneficiaries(config); 53 | } 54 | 55 | @Override 56 | public JSONObject createPayouts(Map params) throws MidtransError { 57 | return IrisApi.createPayouts(params, config); 58 | } 59 | 60 | @Override 61 | public JSONObject approvePayouts(Map requestBody) throws MidtransError { 62 | return IrisApi.approvePayouts(requestBody, config); 63 | 64 | } 65 | 66 | @Override 67 | public JSONObject rejectPayouts(Map requestBody) throws MidtransError { 68 | return IrisApi.rejectPayouts(requestBody, config); 69 | } 70 | 71 | @Override 72 | public JSONObject getPayoutDetails(String referenceNo) throws MidtransError { 73 | return IrisApi.getPayoutDetails(referenceNo, config); 74 | } 75 | 76 | @Override 77 | public JSONArray getTransactionHistory(String fromDate, String toDate) throws MidtransError { 78 | return IrisApi.getTransactionHistory(fromDate, toDate, config); 79 | } 80 | 81 | @Override 82 | public JSONArray getTopUpChannels() throws MidtransError { 83 | return IrisApi.getTopUpChannels(config); 84 | } 85 | 86 | @Override 87 | public JSONArray getBankAccounts() throws MidtransError { 88 | return IrisApi.getBankAccounts(config); 89 | } 90 | 91 | @Override 92 | public JSONObject getFacilitatorBalance(String bankAccountId) throws MidtransError { 93 | return IrisApi.getFacilitatorBalance(bankAccountId, config); 94 | } 95 | 96 | @Override 97 | public JSONObject getBeneficiaryBanks() throws MidtransError { 98 | return IrisApi.getBeneficiaryBanks(config); 99 | } 100 | 101 | @Override 102 | public JSONObject validateBankAccount(String bank, String account) throws MidtransError { 103 | return IrisApi.validateBankAccount(bank, account, config); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/service/impl/MidtransSnapApiImpl.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.service.impl; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.httpclient.SnapApi; 5 | import com.midtrans.httpclient.error.MidtransError; 6 | import com.midtrans.service.MidtransSnapApi; 7 | import org.json.JSONObject; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * Implements from {@link MidtransSnapApi MidtransSnapApi} 13 | */ 14 | public class MidtransSnapApiImpl implements MidtransSnapApi { 15 | private Config config; 16 | 17 | /** 18 | * SnapAPI constructor 19 | * 20 | * @param config Midtrans {@link Config configuration} 21 | */ 22 | public MidtransSnapApiImpl(Config config) { 23 | this.config = config; 24 | } 25 | 26 | @Override 27 | public Config apiConfig() { 28 | return config; 29 | } 30 | 31 | @Override 32 | public JSONObject createTransaction(Map params) throws MidtransError { 33 | return SnapApi.createTransaction(params, config); 34 | } 35 | 36 | @Override 37 | public String createTransactionToken(Map params) throws MidtransError { 38 | return SnapApi.createTransactionToken(params, config); 39 | } 40 | 41 | @Override 42 | public String createTransactionRedirectUrl(Map params) throws MidtransError { 43 | return SnapApi.createTransactionRedirectUrl(params, config); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/snapbi/SnapBiApiRequestor.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.snapbi; 2 | 3 | import okhttp3.*; 4 | import okhttp3.logging.HttpLoggingInterceptor; 5 | import org.json.JSONObject; 6 | import java.io.IOException; 7 | import java.util.Map; 8 | 9 | public class SnapBiApiRequestor { 10 | 11 | private static final OkHttpClient client; 12 | 13 | static { 14 | // Create a logging interceptor 15 | HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); 16 | loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 17 | OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); 18 | if (SnapBiConfig.isEnableLogging()) { 19 | clientBuilder.addInterceptor(loggingInterceptor); 20 | } 21 | client = clientBuilder.build(); 22 | } 23 | 24 | public static JSONObject remoteCall(String url, Map headers, Map body) throws IOException { 25 | 26 | JSONObject jsonBody = new JSONObject(body); 27 | String payloadJson = jsonBody.toString(); 28 | MediaType JSON = MediaType.parse("application/json; charset=utf-8"); 29 | RequestBody requestBody = RequestBody.create(JSON, payloadJson); 30 | 31 | Request.Builder requestBuilder = new Request.Builder().url(url).post(requestBody); 32 | 33 | for (Map.Entry entry : headers.entrySet()) { 34 | requestBuilder.addHeader(entry.getKey(), entry.getValue()); 35 | } 36 | 37 | Request request = requestBuilder.build(); 38 | try (Response response = client.newCall(request).execute()) { 39 | String responseBody = response.body() != null ? response.body().string() : ""; 40 | return new JSONObject(responseBody); 41 | } 42 | } 43 | } 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/snapbi/SnapBiConfig.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.snapbi; 2 | 3 | 4 | /** 5 | * Midtrans Configuration for SnapBi 6 | */ 7 | public class SnapBiConfig { 8 | private static boolean isProduction = false; 9 | private static String snapBiClientId; 10 | private static String snapBiPrivateKey; 11 | private static String snapBiClientSecret; 12 | private static String snapBiPartnerId; 13 | private static String snapBiChannelId; 14 | private static boolean enableLogging = false; 15 | private static String snapBiPublicKey; 16 | public static final String SNAP_BI_SANDBOX_BASE_URL = "https://merchants.sbx.midtrans.com"; 17 | public static final String SNAP_BI_PRODUCTION_BASE_URL = "https://merchants.midtrans.com"; 18 | 19 | public static boolean isProduction() { 20 | return isProduction; 21 | } 22 | 23 | public static void setProduction(boolean isProduction) { 24 | SnapBiConfig.isProduction = isProduction; 25 | } 26 | 27 | public static String getSnapBiClientId() { 28 | return snapBiClientId; 29 | } 30 | public static void setSnapBiClientId(String snapBiClientId) { 31 | SnapBiConfig.snapBiClientId = snapBiClientId; 32 | } 33 | public static String getSnapBiPrivateKey() { 34 | return snapBiPrivateKey; 35 | } 36 | 37 | public static void setSnapBiPrivateKey(String snapBiPrivateKey) { 38 | SnapBiConfig.snapBiPrivateKey = snapBiPrivateKey; 39 | } 40 | public static String getSnapBiClientSecret() { 41 | return snapBiClientSecret; 42 | } 43 | 44 | public static void setSnapBiClientSecret(String snapBiClientSecret) { 45 | SnapBiConfig.snapBiClientSecret = snapBiClientSecret; 46 | } 47 | public static String getSnapBiPartnerId() { 48 | return snapBiPartnerId; 49 | } 50 | 51 | public static void setSnapBiPartnerId(String snapBiPartnerId) { 52 | SnapBiConfig.snapBiPartnerId = snapBiPartnerId; 53 | } 54 | public static String getSnapBiChannelId() { 55 | return snapBiChannelId; 56 | } 57 | 58 | public static void setSnapBiChannelId(String snapBiChannelId) { 59 | SnapBiConfig.snapBiChannelId = snapBiChannelId; 60 | } 61 | public static boolean isEnableLogging() { 62 | return enableLogging; 63 | } 64 | 65 | public static void setEnableLogging(boolean enableLogging) { 66 | SnapBiConfig.enableLogging = enableLogging; 67 | } 68 | public static String getSnapBiPublicKey() { 69 | return snapBiPublicKey; 70 | } 71 | 72 | public static void setSnapBiPublicKey(String snapBiPublicKey) { 73 | SnapBiConfig.snapBiPublicKey = snapBiPublicKey; 74 | } 75 | public static String getSnapBiTransactionBaseUrl() { 76 | return isProduction ? SNAP_BI_PRODUCTION_BASE_URL : SNAP_BI_SANDBOX_BASE_URL; 77 | } 78 | 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /library/src/main/java/com/midtrans/utils/Utility.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.utils; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.nio.charset.StandardCharsets; 9 | import java.util.Base64; 10 | import java.util.Properties; 11 | 12 | public final class Utility { 13 | 14 | /** 15 | * Create basic auth with Encode method is in the Base64.Encoder class that will return Basic auth String 16 | * 17 | * @param serverKey {String} - midtrans server-key/creator-key credential 18 | * @return {String} 19 | */ 20 | public static String encodeBase64(String serverKey) { 21 | return "Basic " + Base64.getEncoder().encodeToString((serverKey + ":").getBytes(StandardCharsets.UTF_8)); 22 | } 23 | 24 | /** 25 | * returns information about the version of Midtrans java library. 26 | * 27 | * @return {String} 28 | */ 29 | public static String getLibraryVersion() { 30 | InputStream resourceAsStream = Utility.class.getResourceAsStream("/version.properties"); 31 | Properties properties = new Properties(); 32 | try { 33 | properties.load(resourceAsStream); 34 | } catch (IOException e) { 35 | return "Unable to reach version"; 36 | } 37 | return (properties.getProperty("version") == null) ? "unable to reach" : properties.getProperty("version"); 38 | } 39 | 40 | /** 41 | * returns a boolean indicating whether the jsonString has the specified key as its own property 42 | * 43 | * @return {boolean} 44 | */ 45 | public static boolean hasOwnProperty(String jsonString, String jsonKey) { 46 | try { 47 | JSONObject jsonObject = new JSONObject(jsonString); 48 | return jsonObject.has(jsonKey); 49 | } catch (JSONException ex) { 50 | return false; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /library/src/main/resources/version.properties: -------------------------------------------------------------------------------- 1 | version=${project.version} -------------------------------------------------------------------------------- /library/src/test/java/com/midtrans/java/ConcurrentTest.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.java; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.Midtrans; 5 | import com.midtrans.httpclient.CoreApi; 6 | import com.midtrans.java.mockupdata.DataMockup; 7 | import org.json.JSONObject; 8 | import org.junit.jupiter.api.BeforeAll; 9 | import org.junit.jupiter.api.Test; 10 | import org.junit.jupiter.api.parallel.Execution; 11 | import org.junit.jupiter.api.parallel.ExecutionMode; 12 | 13 | import java.sql.Timestamp; 14 | 15 | import static com.midtrans.java.mockupdata.Constant.*; 16 | import static org.junit.jupiter.api.Assertions.assertEquals; 17 | 18 | /** 19 | * This is concurrent test to make sure each request is a thread safe, perform multiple request the same action 20 | * at the same time. 21 | */ 22 | @Execution(ExecutionMode.CONCURRENT) 23 | public class ConcurrentTest { 24 | 25 | Timestamp timestamp = new Timestamp(System.currentTimeMillis()); 26 | private final static String WEBHOOK_ENDPOINT = "https://example.com"; 27 | 28 | @BeforeAll 29 | public static void setUp() { 30 | 31 | /* 32 | Set credential-key globally that will be used by {@link #firstRequest() firstRequest} method for initiate 33 | request. 34 | */ 35 | Midtrans.serverKey = mainServerKey; 36 | Midtrans.clientKey = mainClientKey; 37 | Midtrans.isProduction = false; 38 | } 39 | 40 | @Test 41 | public void firstRequest() throws Exception{ 42 | System.out.println("ParallelUnitTest first() start => " + Thread.currentThread().getName()); 43 | 44 | //1. Create order-id with prefix 1 45 | String orderId = "CONCURRENT-TEST-1-" +timestamp.getTime(); 46 | 47 | //2. Create object config as configOptions1 will be used for the first request. We don't set credential-key 48 | // in the config object, will be used credential-key from global config (Midtrans.serverKey) 49 | Config configOptions1 = Config.builder() 50 | .setPaymentOverrideNotification(WEBHOOK_ENDPOINT + "?id=" + orderId) 51 | .build(); 52 | 53 | //3. set thread sleep to interfere the first request 54 | Thread.sleep(500); 55 | 56 | //3. Charge transaction to Midtrans CoreAPI using configOptions1 57 | JSONObject result = CoreApi.chargeTransaction(DataMockup.simpleDataMock(orderId, "gopay"), configOptions1); 58 | 59 | //4. Compare the response to check the value of merchant_id it's expected or not. the expected value merchant_id 60 | // should with merchantId1 61 | assertEquals(merchantId1, result.getString("merchant_id")); 62 | assertEquals(orderId, result.getString("order_id")); 63 | 64 | assertEquals("201", result.getString("status_code")); 65 | assertEquals("gopay", result.getString("payment_type")); 66 | 67 | System.out.println("ParallelUnitTest first() end => " + Thread.currentThread().getName()); 68 | } 69 | 70 | @Test 71 | public void secondRequest() throws Exception { 72 | System.out.println("ParallelUnitTest second() start => " + Thread.currentThread().getName()); 73 | 74 | //1. Create order-id with prefix 2 75 | String orderId = "CONCURRENT-TEST-2-" +timestamp.getTime(); 76 | 77 | //2. Create object config as configOptions2 will be used for the first request. We set the credential-key 78 | // in this config object to simulate the request using multiple Midtrans account 79 | Config configOptions2 = Config.builder() 80 | .setServerKey(secondServerKey) 81 | .setPaymentOverrideNotification(WEBHOOK_ENDPOINT + "?id=" + orderId) 82 | .build(); 83 | 84 | //3. Charge transaction to Midtrans CoreAPI using configOptions2 85 | JSONObject result = CoreApi.chargeTransaction(DataMockup.simpleDataMock(orderId, "gopay"), configOptions2); 86 | 87 | //4. Compare the response to check the value of merchant_id it's expected or not. the expected value merchant_id 88 | // should with merchantId2 89 | assertEquals(merchantId2, result.getString("merchant_id")); 90 | assertEquals(orderId, result.getString("order_id")); 91 | 92 | assertEquals("201", result.getString("status_code")); 93 | assertEquals("gopay", result.getString("payment_type")); 94 | 95 | System.out.println("ParallelUnitTest second() end => " + Thread.currentThread().getName()); 96 | } 97 | } -------------------------------------------------------------------------------- /library/src/test/java/com/midtrans/java/ConfigGlobalTest.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.java; 2 | 3 | import com.midtrans.Config; 4 | import com.midtrans.Midtrans; 5 | import com.midtrans.proxy.ProxyConfig; 6 | import org.junit.jupiter.api.*; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import static com.midtrans.java.mockupdata.Constant.*; 10 | import static org.junit.jupiter.api.Assertions.assertEquals; 11 | import static org.junit.jupiter.api.Assertions.assertNull; 12 | 13 | public class ConfigGlobalTest { 14 | 15 | private static Config config; 16 | 17 | @BeforeAll 18 | public static void setUp() { 19 | ProxyConfig proxyConfig = ProxyConfig.builder() 20 | .setHost(PROXY_HOTS) 21 | .setPort(PROXY_PORT) 22 | .setUsername(PROXY_USERNAME) 23 | .setPassword(PROXY_PASSWORD) 24 | .build(); 25 | 26 | 27 | // set config for global 28 | Midtrans.serverKey = mainServerKey; 29 | Midtrans.clientKey = mainClientKey; 30 | Midtrans.isProduction = true; 31 | Midtrans.enableLog = true; 32 | Midtrans.setReadTimeout(READ_TIMEOUT); 33 | Midtrans.setConnectTimeout(CONNECT_TIMEOUT); 34 | Midtrans.setKeepAliveDuration(KEEP_ALIVE_DURATION); 35 | Midtrans.setMaxConnectionPool(CONNECTION_POOL_SIZE); 36 | Midtrans.setWriteTimeout(WRITE_TIMEOUT); 37 | Midtrans.setHttpClientTimeUnit(TimeUnit.MILLISECONDS); 38 | Midtrans.setProxyConfig(proxyConfig); 39 | Midtrans.paymentAppendNotification(APPEND_NOTIFICATION); 40 | Midtrans.paymentOverrideNotification(OVERRIDE_NOTIFICATION); 41 | 42 | config = Config.builder().build(); 43 | } 44 | 45 | @Test 46 | public void clientKey() { 47 | assertEquals(mainClientKey, config.getClientKey()); 48 | } 49 | 50 | @Test 51 | public void isProduction() { 52 | assertEquals(config.isProduction(), Midtrans.isProduction()); 53 | } 54 | 55 | @Test 56 | public void enableLog() { 57 | assertEquals(config.isEnabledLog(), Midtrans.enableLog()); 58 | } 59 | 60 | @Test 61 | public void idempotencyKey() { 62 | assertNull(config.getPaymentIdempotencyKey()); 63 | assertNull(config.getIrisIdempotencyKey()); 64 | } 65 | 66 | @Test 67 | public void appendOverrideNotification() { 68 | assertEquals(config.getPaymentAppendNotification(), Midtrans.getPaymentAppendNotification()); 69 | assertEquals(config.getPaymentOverrideNotification(), Midtrans.getPaymentOverrideNotification()); 70 | } 71 | 72 | @Test 73 | public void serverKey() { 74 | assertEquals(config.getServerKey(), mainServerKey); 75 | 76 | 77 | assertNull(config.getCustomHeaders()); 78 | assertEquals(config.getProxyConfig(), Midtrans.getProxyConfig()); 79 | } 80 | 81 | 82 | @Test 83 | public void networkPreferences() { 84 | assertEquals(config.getConnectionTimeout(), Midtrans.getConnectTimeout()); 85 | assertEquals(config.getReadTimeout(), Midtrans.getReadTimeout()); 86 | assertEquals(config.getMaxConnectionPool(), Midtrans.getMaxConnectionPool()); 87 | assertEquals(config.getKeepAliveDuration(), Midtrans.getKeepAliveDuration()); 88 | assertEquals(config.getHttpClientTimeUnit(), Midtrans.getHttpClientTimeUnit()); 89 | } 90 | 91 | @Test 92 | public void customHeaders() { 93 | assertNull(config.getCustomHeaders()); 94 | } 95 | 96 | @Test 97 | public void proxy() { 98 | assertEquals(config.getProxyConfig(), Midtrans.getProxyConfig()); 99 | } 100 | 101 | @AfterAll 102 | public static void resetConfig() { 103 | Midtrans.serverKey = mainServerKey; 104 | Midtrans.clientKey = mainClientKey; 105 | Midtrans.isProduction = false; 106 | Midtrans.enableLog = true; 107 | Midtrans.setReadTimeout(READ_TIMEOUT); 108 | Midtrans.setConnectTimeout(CONNECT_TIMEOUT); 109 | Midtrans.setKeepAliveDuration(KEEP_ALIVE_DURATION); 110 | Midtrans.setMaxConnectionPool(CONNECTION_POOL_SIZE); 111 | Midtrans.setWriteTimeout(WRITE_TIMEOUT); 112 | Midtrans.setHttpClientTimeUnit(TimeUnit.SECONDS); 113 | Midtrans.setProxyConfig(null); 114 | 115 | config = Config.builder().build(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /library/src/test/java/com/midtrans/java/MidtransSnapApiTest.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.java; 2 | 3 | import com.midtrans.ConfigBuilder; 4 | import com.midtrans.ConfigFactory; 5 | import com.midtrans.httpclient.error.MidtransError; 6 | import com.midtrans.java.mockupdata.DataMockup; 7 | import com.midtrans.service.MidtransSnapApi; 8 | import org.json.JSONObject; 9 | import org.junit.jupiter.api.*; 10 | 11 | import java.io.IOException; 12 | 13 | import static com.midtrans.java.mockupdata.Constant.*; 14 | import static org.junit.jupiter.api.Assertions.assertEquals; 15 | import static org.junit.jupiter.api.Assertions.assertTrue; 16 | 17 | @TestMethodOrder(MethodOrderer.OrderAnnotation.class) 18 | public class MidtransSnapApiTest { 19 | 20 | private static MidtransSnapApi snapApi; 21 | private static DataMockup dataMockup; 22 | 23 | @BeforeAll 24 | public static void setUp() { 25 | dataMockup = new DataMockup(); 26 | ConfigFactory configFactory = new ConfigFactory(new ConfigBuilder() 27 | .setServerKey(mainServerKey) 28 | .setClientKey(mainClientKey) 29 | .setIsProduction(isProduction) 30 | .build()); 31 | snapApi = configFactory.getSnapApi(); 32 | } 33 | 34 | @Test 35 | @Order(1) 36 | public void createTransactionSimpleParam() { 37 | JSONObject result = null; 38 | try { 39 | result = snapApi.createTransaction(dataMockup.miniDataMockUp()); 40 | } catch (MidtransError midtransError) { 41 | midtransError.printStackTrace(); 42 | } 43 | assertTrue(result.has("token")); 44 | assertTrue(result.has("redirect_url")); 45 | } 46 | 47 | @Test 48 | @Order(2) 49 | public void createTransactionMaxParam() throws IOException, MidtransError { 50 | JSONObject result = snapApi.createTransaction(dataMockup.maxDataMockUp()); 51 | 52 | assertTrue(result.has("token")); 53 | assertTrue(result.has("redirect_url")); 54 | } 55 | 56 | @Test 57 | @Order(3) 58 | public void createTransactionToken() throws MidtransError { 59 | String token = snapApi.createTransactionToken(dataMockup.miniDataMockUp()); 60 | assertTrue(token.matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")); 61 | } 62 | 63 | @Test 64 | @Order(4) 65 | public void createTransactionRedirectUrl() throws MidtransError { 66 | String redirectURL = snapApi.createTransactionRedirectUrl(dataMockup.miniDataMockUp()); 67 | String expected = "https://app.sandbox.midtrans.com/snap/v2/vtweb/"; 68 | assertEquals(expected, redirectURL.substring(0, 47)); 69 | } 70 | 71 | @Test 72 | @Order(5) 73 | public void badRequestBodyOnSnapTrans() { 74 | try { 75 | snapApi.createTransaction(dataMockup.badDataMockUp()); 76 | } catch (MidtransError e) { 77 | assertTrue(e.getMessage().contains("Midtrans API is returning API error. HTTP status code: 400 API response")); 78 | } 79 | } 80 | 81 | @Test 82 | @Order(6) 83 | public void errorServerKey() { 84 | snapApi.apiConfig().setServerKey("dummy"); 85 | try { 86 | snapApi.createTransaction(dataMockup.miniDataMockUp()); 87 | } catch (MidtransError e) { 88 | assertTrue(e.getMessage().contains("unauthorized")); 89 | } 90 | 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /library/src/test/java/com/midtrans/java/mockupdata/Constant.java: -------------------------------------------------------------------------------- 1 | package com.midtrans.java.mockupdata; 2 | 3 | public class Constant { 4 | public static final String mainServerKey = "SB-Mid-server-LDMQH0mOAUofApUWMmXxUIFj"; 5 | public static final String mainClientKey = "SB-Mid-client-_CIibU2GiWPARC2l"; 6 | public static final String merchantId1 = "G331392016"; 7 | public static final String secondServerKey = "SB-Mid-server-9Nm5c-HJE65AjLNtTX-bRjqm"; 8 | public static final String secondClientKey = "SB-Mid-client-GtbzK39rvs5El-bC"; 9 | public static final String merchantId2 = "G902985977"; 10 | 11 | public static boolean isProduction = false; 12 | 13 | public static final String COREAPI_PRODUCTION_BASE_URL = "https://api.midtrans.com/"; 14 | public static final String COREAPI_SANDBOX_BASE_URL = "https://api.sandbox.midtrans.com/"; 15 | public static final String SNAP_PRODUCTION_BASE_URL = "https://app.midtrans.com/snap/v1/transactions"; 16 | public static final String SNAP_SANDBOX_BASE_URL = "https://app.sandbox.midtrans.com/snap/v1/transactions"; 17 | 18 | public static final String creatorKey = "IRIS-330198f0-e49d-493f-baae-585cfded355d"; 19 | public static final String approverKey = "IRIS-1595c12b-6814-4e5a-bbbb-9bc18193f47b"; 20 | 21 | public static final String IRIS_SANDBOX_BASE_URL = "https://app.sandbox.midtrans.com/iris/api/v1/"; 22 | public static final String IRIS_PRODUCTION_BASE_URL = "https://app.midtrans.com/iris/api/v1/"; 23 | 24 | public static final String cardNumberAccept = "4811111111111114"; 25 | public static final String bniCardNumber = "4105 0586 8948 1467"; 26 | public static final String cardNumberFDS = "5510 1111 1111 1115"; 27 | 28 | public static final int DEFAULT_CONNECT_TIMEOUT = 10; //SECOND 29 | public static final int DEFAULT_READ_TIMEOUT = 10; //SECOND 30 | public static final int DEFAULT_WRITE_TIMEOUT = 10; //SECOND 31 | public static final int DEFAULT_MAX_CONNECTION_POOL_SIZE = 16; 32 | public static final int DEFAULT_KEEP_ALIVE_DURATION = 300; //SECOND 33 | 34 | // Dummy for test 35 | public static final int CONNECT_TIMEOUT = 100; 36 | public static final int READ_TIMEOUT = 200; 37 | public static final int WRITE_TIMEOUT = 300; 38 | public static final int CONNECTION_POOL_SIZE = 20; 39 | public static final int KEEP_ALIVE_DURATION = 400; 40 | 41 | public static final String APPEND_NOTIFICATION = "https://example.com/"; 42 | public static final String OVERRIDE_NOTIFICATION = "https://example.com/"; 43 | 44 | public static final String PROXY_HOTS = "http://example.com"; 45 | public static final int PROXY_PORT = 8080; 46 | public static final String PROXY_USERNAME = "user"; 47 | public static final String PROXY_PASSWORD = "password"; 48 | 49 | } -------------------------------------------------------------------------------- /library/src/test/resources/junit-platform.properties: -------------------------------------------------------------------------------- 1 | junit.jupiter.execution.parallel.enabled = true -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% 125 | if ERRORLEVEL 1 goto error 126 | goto end 127 | 128 | :error 129 | set ERROR_CODE=1 130 | 131 | :end 132 | @endlocal & set ERROR_CODE=%ERROR_CODE% 133 | 134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 138 | :skipRcPost 139 | 140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 142 | 143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 144 | 145 | exit /B %ERROR_CODE% -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.midtrans 7 | midtrans-java 8 | 0.0.1 9 | pom 10 | 11 | 12 | library 13 | example 14 | 15 | 16 | --------------------------------------------------------------------------------