@@ -3,9 +3,11 @@ package orders
3
3
import (
4
4
"fmt"
5
5
"net/http"
6
+ "strconv"
6
7
7
8
"github.com/gorilla/schema"
8
9
amazonpay "github.com/qor/amazon-pay-sdk-go"
10
+ "github.com/qor/gomerchant"
9
11
"github.com/qor/qor-example/config"
10
12
"github.com/qor/qor-example/models/orders"
11
13
"github.com/qor/qor-example/utils"
@@ -62,8 +64,20 @@ func (ctrl Controller) CompleteCreditCard(w http.ResponseWriter, req *http.Reque
62
64
req .ParseForm ()
63
65
64
66
order := getCurrentOrder (w , req )
65
- if order .AmazonOrderReferenceID = req .Form .Get ("amazon_order_reference_id" ); order .AmazonOrderReferenceID != "" {
66
- order .AmazonAddressAccessToken = req .Form .Get ("amazon_address_access_token" )
67
+
68
+ expMonth , _ := strconv .Atoi (req .Form .Get ("exp_month" ))
69
+ expYear , _ := strconv .Atoi (req .Form .Get ("exp_year" ))
70
+
71
+ creditCard := gomerchant.CreditCard {
72
+ Name : req .Form .Get ("name" ),
73
+ Number : req .Form .Get ("creditcard" ),
74
+ CVC : req .Form .Get ("cvv" ),
75
+ ExpYear : uint (expYear ),
76
+ ExpMonth : uint (expMonth ),
77
+ }
78
+
79
+ if creditCard .ValidNumber () {
80
+ // TODO integrate with https://github.com/qor/gomerchant to handle those information
67
81
tx := utils .GetDB (req )
68
82
err := orders .OrderState .Trigger ("checkout" , order , tx , "" )
69
83
@@ -72,11 +86,9 @@ func (ctrl Controller) CompleteCreditCard(w http.ResponseWriter, req *http.Reque
72
86
http .Redirect (w , req , "/cart/success" , http .StatusFound )
73
87
return
74
88
}
75
- utils .AddFlashMessage (w , req , err .Error (), "error" )
76
- } else {
77
- utils .AddFlashMessage (w , req , "Order Reference ID not Found" , "error" )
78
89
}
79
90
91
+ utils .AddFlashMessage (w , req , "Invalid Credit Card" , "error" )
80
92
http .Redirect (w , req , "/cart" , http .StatusFound )
81
93
}
82
94
0 commit comments