1515use App \Events \PaymentSummitRegistrationOrderConfirmed ;
1616use App \libs \Utils \PunnyCodeHelper ;
1717use App \Models \Utils \Traits \FinancialTrait ;
18+ use App \Services \Apis \IPaymentGatewayAPI ;
1819use Doctrine \Common \Collections \Criteria ;
1920use Illuminate \Support \Facades \Config ;
2021use Illuminate \Support \Facades \Event ;
2627use models \utils \SilverstripeBaseModel ;
2728use Doctrine \Common \Collections \ArrayCollection ;
2829use Doctrine \ORM \Mapping as ORM ;
30+ use function Psy \debug ;
2931
3032/**
3133 * @package models\summit
@@ -214,6 +216,19 @@ class SummitOrder extends SilverstripeBaseModel implements IQREntity
214216 #[ORM \Column(name: 'CreditCard4Numbers ' , type: 'string ' )]
215217 private $ credit_card_4numbers ;
216218
219+ /**
220+ * @var string
221+ */
222+ #[ORM \Column(name: 'PaymentInfoType ' , type: 'string ' )]
223+ private $ payment_info_type ;
224+
225+ /**
226+ * @var array
227+ */
228+ #[ORM \Column(name: 'PaymentInfoDetails ' , type: 'json ' )]
229+ private $ payment_info_details ;
230+
231+
217232 /**
218233 * SummitOrder constructor.
219234 */
@@ -224,6 +239,8 @@ public function __construct()
224239 $ this ->extra_question_answers = new ArrayCollection ();
225240 $ this ->status = IOrderConstants::ReservedStatus;
226241 $ this ->payment_method = IOrderConstants::OnlinePaymentMethod;
242+ $ this ->payment_info_details = [];
243+ $ this ->payment_info_type = null ;
227244 }
228245
229246 public function setPaymentMethodOffline ()
@@ -304,13 +321,17 @@ public function getStatus(): string
304321 return $ this ->status ;
305322 }
306323
307- public function setPaidStatus ()
324+ public function setPaidStatus (): void
308325 {
309326 $ this ->status = IOrderConstants::PaidStatus;
310327 $ this ->approved_payment_date = new \DateTime ('now ' , new \DateTimeZone ('UTC ' ));
311328 }
312329
313- public function setPaid (array $ payload = null )
330+ /**
331+ * @param array|null $payload
332+ * @return void
333+ */
334+ public function setPaid (array $ payload = null ):void
314335 {
315336 Log::debug (sprintf ("SummitOrder::setPaid order %s " , $ this ->id ));
316337 if ($ this ->isPaid ()) {
@@ -324,21 +345,7 @@ public function setPaid(array $payload = null)
324345 $ ticket ->setPaid ();
325346 }
326347
327- if (!is_null ($ payload ) && isset ($ payload ['order_credit_card_type ' ]) && isset ($ payload ['order_credit_card_4numbers ' ])) {
328-
329- Log::debug
330- (
331- sprintf
332- (
333- "SummitOrder::setPaid order %s setting credit card info %s " ,
334- $ this ->id ,
335- json_encode ($ payload )
336- )
337- );
338-
339- $ this ->credit_card_type = $ payload ['order_credit_card_type ' ];
340- $ this ->credit_card_4numbers = $ payload ['order_credit_card_4numbers ' ];
341- }
348+ $ this ->setPaymentInfo ($ payload );
342349
343350 Event::dispatch (new PaymentSummitRegistrationOrderConfirmed ($ this ->getId ()));
344351 }
@@ -1245,4 +1252,43 @@ public function getCreditCard4Number():?string
12451252 {
12461253 return $ this ->credit_card_4numbers ;
12471254 }
1255+
1256+ public function getPaymentInfoType (): ?string
1257+ {
1258+ return $ this ->payment_info_type ;
1259+ }
1260+
1261+
1262+ public function getPaymentInfoDetails (): ?array
1263+ {
1264+ return $ this ->payment_info_details ;
1265+ }
1266+
1267+ /**
1268+ * @param array|null $payment_info
1269+ * @return void
1270+ */
1271+ public function setPaymentInfo (array $ payment_info = null ): void {
1272+ if (!is_null ($ payment_info ) && isset ($ payment_info [IPaymentGatewayAPI::PaymentInfo])) {
1273+
1274+ Log::debug
1275+ (
1276+ sprintf
1277+ (
1278+ "SummitOrder::setPaymentInfo order %s setting payment info %s " ,
1279+ $ this ->id ,
1280+ json_encode ($ payment_info )
1281+ )
1282+ );
1283+
1284+ $ this ->payment_info_type = $ payment_info [IPaymentGatewayAPI::PaymentInfo][IPaymentGatewayAPI::PaymentInfo_Type] ?? null ;
1285+ $ this ->payment_info_details = $ payment_info [IPaymentGatewayAPI::PaymentInfo][IPaymentGatewayAPI::PaymentInfo_Details] ?? [];
1286+
1287+ if ($ this ->payment_info_type === IPaymentGatewayAPI::PaymentInfo_Type_Card){
1288+ // back compat
1289+ $ this ->credit_card_type = $ this ->payment_info_details [IPaymentGatewayAPI::PaymentInfo_Type_Card_Brand] ?? null ;
1290+ $ this ->credit_card_4numbers = $ this ->payment_info_details [IPaymentGatewayAPI::PaymentInfo_Type_Card_Last4] ?? null ;
1291+ }
1292+ }
1293+ }
12481294}
0 commit comments