-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04448d7
commit 5f09b7c
Showing
12 changed files
with
204 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/asd/vinted/Controller/CreditCardPaymentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package asd.vinted.Controller; | ||
|
||
import asd.vinted.data.dto.OrderDto; | ||
import asd.vinted.data.entity.Order; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import asd.vinted.data.payment.CreditCardPaymentResponse; | ||
import asd.vinted.data.service.CreditCardPaymentService; | ||
import asd.vinted.data.service.PaypalPaymentService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping(value = "/") | ||
@CrossOrigin(origins = "http://localhost:4200") | ||
public class CreditCardPaymentController{ | ||
@Autowired | ||
CreditCardPaymentService ccPaymentService; | ||
|
||
//CommonConstant.PAYMENT_CREATE_STRIPE | ||
@PostMapping("/CreditCard") | ||
public ResponseEntity<CreditCardPaymentResponse> stripePaymentCreate(@RequestBody OrderDto createPayment){ | ||
return ResponseEntity.ok().body(ccPaymentService.CreatCreditCardPayment(createPayment)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/asd/vinted/data/payment/CreditCardConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package asd.vinted.data.payment; | ||
|
||
import org.springframework.beans.factory.annotation.Configurable; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class CreditCardConfig { | ||
@Value("${Stripe.apiKey}") | ||
private String apiKey; | ||
|
||
public String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
public void setApiKey(String apiKey) { | ||
this.apiKey = apiKey; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/asd/vinted/data/payment/CreditCardPaymentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package asd.vinted.data.payment; | ||
|
||
public class CreditCardPaymentResponse { | ||
private String status; | ||
private Long amount; | ||
private String paymentID; | ||
|
||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(String status) { | ||
this.status = status; | ||
} | ||
|
||
public Long getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(Long amount) { | ||
this.amount = amount; | ||
} | ||
|
||
public String getPaymentID() { | ||
return paymentID; | ||
} | ||
|
||
public void setPaymentID(String paymentID) { | ||
this.paymentID = paymentID; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/asd/vinted/data/service/CreditCardPaymentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package asd.vinted.data.service; | ||
|
||
import asd.vinted.data.dto.OrderDto; | ||
import asd.vinted.data.payment.CreditCardPaymentResponse; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public interface CreditCardPaymentService { | ||
|
||
public CreditCardPaymentResponse CreatCreditCardPayment(OrderDto createPayment); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/asd/vinted/data/service/impl/CreditCardPaymentServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package asd.vinted.data.service.impl; | ||
|
||
import asd.vinted.data.dto.OrderDto; | ||
import asd.vinted.data.payment.CreditCardConfig; | ||
import asd.vinted.data.payment.CreditCardPaymentResponse; | ||
import asd.vinted.data.service.CreditCardPaymentService; | ||
import com.stripe.Stripe; | ||
import com.stripe.model.Charge; | ||
import com.stripe.param.ChargeCreateParams; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class CreditCardPaymentServiceImpl implements CreditCardPaymentService { | ||
@Autowired | ||
private CreditCardConfig config; | ||
|
||
@Override | ||
public CreditCardPaymentResponse CreatCreditCardPayment(OrderDto createPayment) { | ||
|
||
CreditCardPaymentResponse response = null; | ||
try { | ||
//Stripe.apiKey = config.getApiKey(); | ||
Stripe.apiKey = "sk_test_51KJQYrGYh3JcLLFyylP8w7TExdqsgiuPvCHt3LUi5m1ZTpotdGHQZpLLkmddpl1QEOOuE2uXvFkFRfZmE087K7uS00oAYjE0Ef"; | ||
|
||
ChargeCreateParams params = | ||
ChargeCreateParams.builder() | ||
.setAmount((long) (createPayment.getPrice()*100L)) | ||
.setCurrency("EUR") | ||
.setDescription(createPayment.getDescription()) | ||
.setSource(createPayment.getStripeToken()) | ||
.build(); | ||
|
||
Charge charge = Charge.create(params); | ||
if (charge.getStatus().equals("succeeded")){ | ||
response = new CreditCardPaymentResponse(); | ||
response.setStatus(charge.getStatus()); | ||
response.setAmount(charge.getAmount()/100); | ||
response.setPaymentID(charge.getId()); | ||
return response; | ||
} | ||
|
||
}catch (Exception ex){ | ||
System.out.println(ex.getMessage()); | ||
} | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters