Skip to content

Commit

Permalink
commit files.
Browse files Browse the repository at this point in the history
  • Loading branch information
pannanxu committed Oct 13, 2024
1 parent 8e02a50 commit 26f89db
Show file tree
Hide file tree
Showing 10 changed files with 1,106 additions and 948 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tasks.withType(JavaCompile).configureEach {
}

node {
download = true
nodeProjectDir = file("${project.projectDir}/ui")
}

Expand All @@ -55,4 +56,12 @@ build {

halo {
version = '2.17'
superAdminUsername = 'admin'
superAdminPassword = '123123'
externalUrl = 'http://localhost:8090'

port = 8090
debug = true
debugPort = 5005

}
Empty file modified gradlew
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ pluginManagement {
gradlePluginPortal()
}
}
rootProject.name = 'plugin-starter'
rootProject.name = 'payment'

5 changes: 5 additions & 0 deletions src/main/java/net/nanxu/StarterPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.nanxu.order.Order;
import net.nanxu.payment.DispatcherPayment;
import net.nanxu.payment.Payment;
import net.nanxu.payment.impl.AliPayment;
import net.nanxu.payment.impl.WeChatPayment;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import run.halo.app.extension.SchemeManager;
Expand Down Expand Up @@ -38,6 +40,9 @@ public Payment payment() {
public void start() {
System.out.println("插件启动成功!");
schemeManager.register(Order.class);

dispatcher.register(new WeChatPayment());
dispatcher.register(new AliPayment());
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/nanxu/order/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.math.BigDecimal;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK;

Expand All @@ -12,6 +13,7 @@
* @author: P
**/
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@GVK(kind = "Order", group = "order.payment.plugin.nanxu.net", version = "v1alpha1", singular = "order", plural = "orders")
public class Order extends AbstractExtension {
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/net/nanxu/payment/endpoint/PaymentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.nanxu.payment.endpoint;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.nanxu.order.Order;
import net.nanxu.payment.Payment;
import net.nanxu.payment.PaymentOrder;
import net.nanxu.payment.core.IPayment;
import net.nanxu.payment.core.PaymentProfile;
import net.nanxu.payment.core.model.CallbackRequest;
import net.nanxu.payment.core.model.CallbackResult;
import net.nanxu.payment.impl.WeChatPayment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.server.ServerRequest;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.ApiVersion;
import run.halo.app.theme.TemplateNameResolver;

/**
* PaymentController.
*
* @author: pan
**/
@ApiVersion("fake.halo.run/v1alpha1")
@RequestMapping("/payment")
@RestController
@RequiredArgsConstructor
@Slf4j
public class PaymentController {
private final TemplateNameResolver templateNameResolver;
private final Payment payment;

@GetMapping("/test")
public Mono<String> test() {
return Mono.just("test");
}

// /apis/fake.halo.run/v1alpha1/payment/profiles?orderId=123
@GetMapping("/profiles")
public Flux<PaymentProfile> renderPaymentPage() {
Flux<PaymentProfile> profiles = payment.getPaymentProfiles(PaymentOrder.builder()
.userAgent("")
.request(null)
.order(new Order().setPayType(WeChatPayment.NAME))
.build());

return profiles;
// return templateNameResolver.resolveTemplateNameOrDefault(request.exchange(), "payment")
// .flatMap(templateName -> profiles.collectList()
// .flatMap(e -> {
// var model = new HashMap<String, Object>();
// model.put("orderId", orderId);
// model.put("profiles", e);
// return ServerResponse.ok().render(templateName, model);
// }));
}

@PostMapping("/{orderId}/callback/{paymentType}")
public Mono<Object> callback(@PathVariable String paymentType, @PathVariable String orderId,
ServerRequest request) {
return payment.getPayment(paymentType)
.map(IPayment::getCallback)
.flatMap(callback -> callback.call(CallbackRequest.builder()
.order(null)
.request(request)
.build()))
.map(CallbackResult::getRender);
}

}
6 changes: 2 additions & 4 deletions src/main/java/net/nanxu/payment/endpoint/PaymentEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import net.nanxu.payment.core.model.CallbackRequest;
import net.nanxu.payment.core.model.CallbackResult;
import org.springdoc.core.fn.builders.operation.Builder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
Expand All @@ -26,12 +24,12 @@
* @author: P
**/
@RequiredArgsConstructor
@Component
// @Component
public class PaymentEndpoint {
private final TemplateNameResolver templateNameResolver;
private final Payment payment;

@Bean
// @Bean
public RouterFunction<ServerResponse> paymentRouter() {
return route()
// // 获取订单所有可以使用的支付渠道
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: plugin.halo.run/v1alpha1
kind: Plugin
metadata:
# The name defines how the plugin is invoked, A unique name
name: starter
name: payment
spec:
enabled: true
requires: ">=2.11.0"
Expand All @@ -15,8 +15,8 @@ spec:
homepage: https://github.com/halo-dev/plugin-starter#readme
repo: https://github.com/halo-dev/plugin-starter
issues: https://github.com/halo-dev/plugin-starter/issues
displayName: "插件快速开始模板"
description: "这是一个插件快速开始模板"
displayName: "Payment Core"
description: "Payment Core."
license:
- name: "GPL-3.0"
url: "https://github.com/halo-dev/plugin-starter/blob/main/LICENSE"
2 changes: 2 additions & 0 deletions test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GET http://localhost:8090/apis/fake.halo.run/v1alpha1/payment/profiles?orderId=123
Content-Type: application/json
Loading

0 comments on commit 26f89db

Please sign in to comment.