Testing WePay payment with Credit Card

This commit is contained in:
David Bomba 2021-06-20 13:36:58 +10:00
parent 1cea863e77
commit 2075c4e8c1
2 changed files with 10 additions and 7 deletions

View File

@ -120,6 +120,9 @@ class CreditCard
$credit_card_id = (int)$response->credit_card_id; $credit_card_id = (int)$response->credit_card_id;
nlog($response->state);
nlog(boolval($request->input('store_card')));
if(in_array($response->state, ['new', 'authorized']) && boolval($request->input('store_card'))){ if(in_array($response->state, ['new', 'authorized']) && boolval($request->input('store_card'))){
$this->storePaymentMethod($response, GatewayType::CREDIT_CARD); $this->storePaymentMethod($response, GatewayType::CREDIT_CARD);
@ -164,16 +167,16 @@ class CreditCard
if(in_array($response->state, ['authorized', 'captured'])){ if(in_array($response->state, ['authorized', 'captured'])){
//success //success
nlog("success"); nlog("success");
$payment_status = $response->status == 'authorized' ? Payment::STATUS_COMPLETED : Payment::STATUS_PENDING; $payment_status = $response->state == 'authorized' ? Payment::STATUS_COMPLETED : Payment::STATUS_PENDING;
$this->processSuccessfulPayment($response, $payment_status); return $this->processSuccessfulPayment($response, $payment_status);
} }
if(in_array($response->state, ['released', 'cancelled', 'failed', 'expired'])){ if(in_array($response->state, ['released', 'cancelled', 'failed', 'expired'])){
//some type of failure //some type of failure
nlog("failure"); nlog("failure");
$payment_status = $response->status == 'cancelled' ? Payment::STATUS_CANCELLED : Payment::STATUS_FAILED; $payment_status = $response->state == 'cancelled' ? Payment::STATUS_CANCELLED : Payment::STATUS_FAILED;
$this->processUnSuccessfulPayment($response, $payment_status); $this->processUnSuccessfulPayment($response, $payment_status);
} }
@ -252,7 +255,7 @@ https://developer.wepay.com/api/api-calls/checkout
$data = [ $data = [
'payment_type' => PaymentType::CREDIT_CARD_OTHER, 'payment_type' => PaymentType::CREDIT_CARD_OTHER,
'amount' => $response->gross, 'amount' => $response->amount,
'transaction_reference' => $response->checkout_id, 'transaction_reference' => $response->checkout_id,
'gateway_type_id' => GatewayType::CREDIT_CARD, 'gateway_type_id' => GatewayType::CREDIT_CARD,
]; ];
@ -301,7 +304,7 @@ https://developer.wepay.com/api/api-calls/checkout
private function storePaymentMethod($response, $payment_method_id) private function storePaymentMethod($response, $payment_method_id)
{ {
nlog("storing card");
$payment_meta = new \stdClass; $payment_meta = new \stdClass;
$payment_meta->exp_month = (string) $response->expiration_month; $payment_meta->exp_month = (string) $response->expiration_month;
$payment_meta->exp_year = (string) $response->expiration_year; $payment_meta->exp_year = (string) $response->expiration_year;

View File

@ -236,8 +236,8 @@
var token = data.credit_card_id; var token = data.credit_card_id;
document.querySelector('input[name="credit_card_id"]').value = null; document.querySelector('input[name="credit_card_id"]').value = token;
document.querySelector('input[name="token"]').value = token; document.querySelector('input[name="token"]').value = null;
document.getElementById('server-response').submit(); document.getElementById('server-response').submit();
} }