Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Commit b1e10e8

Browse files
committed
SSL, paypals webhook added
1 parent 09e6375 commit b1e10e8

File tree

8 files changed

+63
-31
lines changed

8 files changed

+63
-31
lines changed

src/main/java/pl/simplemethod/codebin/CodebinApplication.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
public class CodebinApplication {
1414

1515
public static void main(String[] args) {
16-
SpringApplication.run(CodebinApplication.class, args);
16+
SpringApplication application = new SpringApplication(CodebinApplication.class);
17+
application.setAdditionalProfiles("ssl");
18+
application.run(args);
1719
}
1820

1921
@Bean

src/main/java/pl/simplemethod/codebin/SecurityConfig.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ protected void configure(HttpSecurity http) throws Exception {
1919
http.csrf().disable();
2020
http.cors().disable();
2121

22-
/* http.authorizeRequests()
23-
.antMatchers("/", "/**", "/postlogin", "/v1.0/**", "/404", "/logowanie/github")
24-
.permitAll()
25-
.anyRequest().fullyAuthenticated()
26-
.and()
27-
.oauth2Login();
28-
/*
29-
*/
30-
// http://localhost/logowanie/github
3122
http.oauth2Login()
3223
.authorizationEndpoint()
3324
.baseUri("/oauth")

src/main/java/pl/simplemethod/codebin/paypal/PayPalBillingPlan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public PayPalBillingPlan(APIContext apiContext) {
2121
this.apiContext = apiContext;
2222
}
2323

24-
private static final String CANCEL_URL = "http://127.0.0.1/dashboard.html#!/payment-error";
25-
private static final String PROCESS_URL = "http://127.0.0.1/paypal/payment-success";
24+
private static final String CANCEL_URL = "https://127.0.0.1/dashboard.html#!/payment-error";
25+
private static final String PROCESS_URL = "https://127.0.0.1/paypal/payment-success";
2626

2727
/**
2828
* Creates a plan to billing plan

src/main/java/pl/simplemethod/codebin/paypal/PayPalController.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import com.paypal.api.payments.Agreement;
44
import com.paypal.api.payments.Plan;
5+
import com.paypal.base.Constants;
6+
import com.paypal.base.rest.APIContext;
57
import com.paypal.base.rest.PayPalRESTException;
8+
import org.json.JSONObject;
69
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.MediaType;
12+
import org.springframework.http.ResponseEntity;
713
import org.springframework.web.bind.annotation.*;
814
import pl.simplemethod.codebin.model.Users;
915
import pl.simplemethod.codebin.repository.UsersRepository;
@@ -19,15 +25,19 @@ public class PayPalController {
1925

2026
private UsersRepository usersRepository;
2127

28+
private APIContext apiContext;
2229
private PayPalBillingPlan payPalBillingPlan;
2330
private PayPalBillingAgreement payPalBillingAgreement;
2431

32+
private static final String WEBHOOK_ID = "5D129190NJ603512E";
33+
2534
private static String planId;
26-
private static final String PAYMENT_ACCEPT_URL = "http://127.0.0.1/dashboard.html#!/payment-accept";
35+
private static final String PAYMENT_ACCEPT_URL = "https://127.0.0.1/dashboard.html#!/payment-accept";
2736

2837
@Autowired
29-
public PayPalController(PayPalBillingPlan payPalBillingPlan, PayPalBillingAgreement payPalBillingAgreement,
30-
UsersRepository usersRepository) {
38+
public PayPalController(APIContext apiContext, PayPalBillingPlan payPalBillingPlan,
39+
PayPalBillingAgreement payPalBillingAgreement, UsersRepository usersRepository) {
40+
this.apiContext = apiContext;
3141
this.payPalBillingPlan = payPalBillingPlan;
3242
this.payPalBillingAgreement = payPalBillingAgreement;
3343
this.usersRepository = usersRepository;
@@ -76,4 +86,20 @@ public void success(HttpServletResponse response, @RequestParam String token, @C
7686
e.printStackTrace();
7787
}
7888
}
89+
90+
@PostMapping(path = "/webhook", consumes = MediaType.APPLICATION_JSON_VALUE)
91+
public @ResponseBody ResponseEntity getInfo(@RequestBody String payload) {
92+
apiContext.addConfiguration(Constants.PAYPAL_WEBHOOK_ID, WEBHOOK_ID);
93+
94+
JSONObject jsonObject = new JSONObject(payload);
95+
if (jsonObject.getString("event_type").equals("BILLING.SUBSCRIPTION.CANCELLED")) {
96+
JSONObject resource = (JSONObject) jsonObject.get("resource");
97+
usersRepository.updatePlan(resource.getString("plan_id"));
98+
System.err.println(resource.getString("plan_id") + " - subscription cancelled");
99+
} else {
100+
return new ResponseEntity<>("", null, HttpStatus.BAD_REQUEST);
101+
}
102+
103+
return new ResponseEntity<>("", null, HttpStatus.OK);
104+
}
79105
}

src/main/java/pl/simplemethod/codebin/repository/UsersRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pl.simplemethod.codebin.repository;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Modifying;
45
import org.springframework.data.jpa.repository.Query;
56
import org.springframework.data.repository.query.Param;
67
import org.springframework.stereotype.Repository;
@@ -24,4 +25,8 @@ public interface UsersRepository extends JpaRepository<Users, Long> {
2425

2526
@Query(value = "SELECT u.subscription FROM Users u WHERE u.id = :id")
2627
String getSubscription(@Param("id") Integer id);
28+
29+
@Modifying(clearAutomatically = true)
30+
@Query(value = "UPDATE users SET subscription = NULL WHERE subscription = :planId", nativeQuery = true)
31+
void updatePlan(@Param("planId") String planId);
2732
}

src/main/resources/application.properties

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPRING PROPERTIES
33
#---------------------------------------------------
44
spring.main.allow-bean-definition-overriding=true
5-
server.port=80
5+
server.port=443
66
spring.jmx.unique-names=true
77
#---------------------------------------------------
88
# OAUTH2 PROPERTIES
@@ -39,4 +39,12 @@ spring.jpa.show-sql=true
3939
#---------------------------------------------------
4040
paypal.client.app=Aa8pCy_73bPjrlYGnFvAoxcqrL-7CGkiLKvQyXa3YsfWz1FlamqVXr5Uwynf-fnor10r5qquqbTgOjOi
4141
paypal.client.secret=EJ4V-JLYv_g26ppiFraOCq2s88ytpJgk2bVhTAMHIax6f0E1zodxY4LyC1bAPG6cXalJTF2gIPlS0XfE
42-
paypal.mode=sandbox
42+
paypal.mode=sandbox
43+
44+
#---------------------------------------------------
45+
# HTTPS PROPERTIES
46+
#---------------------------------------------------
47+
server.ssl.key-store-type=PKCS12
48+
server.ssl.key-store=classpath:keystore/key.p12
49+
server.ssl.key-store-password=chardonnay71
50+
server.ssl.key-alias=key

src/main/resources/keystore/key.p12

2.52 KB
Binary file not shown.

src/main/resources/public/app.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ app.controller('ContainersCreateController', ['$filter', '$routeParams', '$scope
6262

6363

6464
$http({
65-
url: 'http://127.0.0.1/github/user/repos/' + $routeParams.id,
65+
url: 'https://127.0.0.1/github/user/repos/' + $routeParams.id,
6666
method: 'GET'
6767
}).then(
6868
function (response) {
@@ -78,7 +78,7 @@ app.controller('ContainersCreateController', ['$filter', '$routeParams', '$scope
7878
if ($scope.supportedPlatforms.indexOf(response.data.language) !== -1) {
7979
$scope.progressBar = 40;
8080
$http({
81-
url: 'http://127.0.0.1/github/local',
81+
url: 'https://127.0.0.1/github/local',
8282
method: 'GET'
8383
}).then(
8484
function (local) {
@@ -131,7 +131,7 @@ app.controller('ContainersCreateController', ['$filter', '$routeParams', '$scope
131131
console.log("Nazwa dokeru:" + $scope.id);
132132
console.log("Ilość pamięci ram: " + $scope.rammemory + " i dysku: " + $scope.diskquota);
133133
$http({
134-
url: 'http://127.0.0.1/srv/container/create',
134+
url: 'https://127.0.0.1/srv/container/create',
135135
method: 'POST',
136136
params: {
137137
dockerimage: $scope.dockerImages,
@@ -185,7 +185,7 @@ app.controller('ContainersCreateController', ['$filter', '$routeParams', '$scope
185185

186186
app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$http', function ($filter, $routeParams, $scope, $http, $window) {
187187
$http({
188-
url: 'http://127.0.0.1/srv/user/container/info',
188+
url: 'https://127.0.0.1/srv/user/container/info',
189189
method: 'GET',
190190
params: {dockergithubid: $routeParams.id}
191191
}).then(
@@ -204,7 +204,7 @@ app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$h
204204
}
205205
$scope.dockerRestart = function () {
206206
$http({
207-
url: 'http://127.0.0.1/srv/container/' + $scope.containersId + '/restart',
207+
url: 'https://127.0.0.1/srv/container/' + $scope.containersId + '/restart',
208208
method: 'POST'
209209
}).then(
210210
function (response) {
@@ -216,7 +216,7 @@ app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$h
216216
};
217217
$scope.dockerRemove = function () {
218218
$http({
219-
url: 'http://127.0.0.1/srv/container/' + $scope.containersId + '/delete',
219+
url: 'https://127.0.0.1/srv/container/' + $scope.containersId + '/delete',
220220
method: 'DELETE'
221221
}).then(
222222
function () {
@@ -231,7 +231,7 @@ app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$h
231231

232232
$scope.execCommands = function (path, args) {
233233
$http({
234-
url: 'http://127.0.0.1/srv/container/' + $scope.containersId + '/exec',
234+
url: 'https://127.0.0.1/srv/container/' + $scope.containersId + '/exec',
235235
method: 'POST',
236236
params: {
237237
path: path,
@@ -246,7 +246,7 @@ app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$h
246246
};
247247

248248
$http({
249-
url: 'http://127.0.0.1/srv/container/' + $scope.containersId + '/logs',
249+
url: 'https://127.0.0.1/srv/container/' + $scope.containersId + '/logs',
250250
method: 'GET'
251251
}).then(
252252
function (logGet) {
@@ -257,7 +257,7 @@ app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$h
257257
}
258258
);
259259
$http({
260-
url: 'http://127.0.0.1/srv/container/' + $scope.containersId + '/top',
260+
url: 'https://127.0.0.1/srv/container/' + $scope.containersId + '/top',
261261
method: 'GET'
262262
}).then(
263263
function (response) {
@@ -279,7 +279,7 @@ app.controller('ContainersController', ['$filter', '$routeParams', '$scope', '$h
279279
app.controller('HomeController', function ($scope, $http, $cookies) {
280280
$scope.lastVal = $cookies.get('token');
281281
$http({
282-
url: 'http://127.0.0.1/github/user',
282+
url: 'https://127.0.0.1/github/user',
283283
method: 'GET'
284284
}).then(
285285
function (response) {
@@ -300,7 +300,7 @@ app.controller('ProjectsController', function ($scope, $http) {
300300
$scope.supportedPlatforms = ["Java", "HTML", "C", "C++", "JavaScript", "CSS"];
301301

302302
$http({
303-
url: 'http://127.0.0.1/github/user/repos/public',
303+
url: 'https://127.0.0.1/github/user/repos/public',
304304
method: 'GET'
305305
}).then(
306306
function (response) {
@@ -325,7 +325,7 @@ app.controller('VersionController', function ($scope) {
325325
app.controller('CheckLoginStatus', function ($scope, $http, $cookies) {
326326
$scope.lastVal = $cookies.get('token');
327327
$http({
328-
url: 'http://127.0.0.1/github/user/checktoken',
328+
url: 'https://127.0.0.1/github/user/checktoken',
329329
method: 'GET',
330330
params: {token: $scope.lastVal}
331331
}).then(
@@ -342,7 +342,7 @@ app.controller('CheckLoginStatus', function ($scope, $http, $cookies) {
342342
app.controller('dashboardGithub', function ($scope, $http, $cookies) {
343343
$scope.lastVal = $cookies.get('token');
344344
$http({
345-
url: 'http://127.0.0.1/github/user',
345+
url: 'https://127.0.0.1/github/user',
346346
method: 'GET'
347347
}).then(
348348
function (response) {
@@ -363,7 +363,7 @@ app.controller('dashboardGithub', function ($scope, $http, $cookies) {
363363
});
364364

365365
app.controller('ProfileController', function ($scope, $http) {
366-
$http.get('http://127.0.0.1/github/user/subscription').then(
366+
$http.get('https://127.0.0.1/github/user/subscription').then(
367367
function (response) {
368368
$scope.subscriber = response.data.subscriber;
369369
}, function () {

0 commit comments

Comments
 (0)