1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

WePay process credit/card

This commit is contained in:
David Bomba 2021-06-19 14:58:45 +10:00
parent 3911a58d98
commit d90b884922
2 changed files with 88 additions and 32 deletions

View File

@ -13,6 +13,7 @@
namespace App\PaymentDrivers\WePay;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Models\GatewayType;
use App\PaymentDrivers\WePayPaymentDriver;
@ -98,25 +99,80 @@ class CreditCard
public function paymentResponse(PaymentResponseRequest $request)
{
nlog($request->all());
// // charge the credit card
// $response = $wepay->request('checkout/create', array(
// 'account_id' => $account_id,
// 'amount' => '25.50',
// 'currency' => 'USD',
// 'short_description' => 'A vacation home rental',
// 'type' => 'goods',
// 'payment_method' => array(
// 'type' => 'credit_card',
// 'credit_card' => array(
// 'id' => $credit_card_id
// )
// )
// ));
// USD, CAD, and GBP.
nlog($request->all());
// charge the credit card
$response = $this->wepay_payment_driver->wepay->request('checkout/create', array(
'account_id' => $this->wepay_payment_driver->company_gateway->getConfigField('accountId'),
'amount' => $this->wepay_payment_driver->payment_hash->data->amount_with_fee,
'currency' => $this->wepay_payment_driver->client->getCurrencyCode(),
'short_description' => 'A vacation home rental',
'type' => 'goods',
'payment_method' => array(
'type' => 'credit_card',
'credit_card' => array(
'id' => $data['token']
)
)
));
}
/*
https://developer.wepay.com/api/api-calls/checkout
{
"checkout_id": 649945633,
"account_id": 1548718026,
"type": "donation",
"short_description": "test checkout",
"currency": "USD",
"amount": 20,
"state": "authorized",
"soft_descriptor": "WPY*Wolverine",
"auto_release": true,
"create_time": 1463589958,
"gross": 20.88,
"reference_id": null,
"callback_uri": null,
"long_description": null,
"delivery_type": null,
"initiated_by": "merchant",
"in_review": false,
"fee": {
"app_fee": 0,
"processing_fee": 0.88,
"fee_payer": "payer"
},
"chargeback": {
"amount_charged_back": 0,
"dispute_uri": null
},
"refund": {
"amount_refunded": 0,
"refund_reason": null
},
"payment_method": {
"type": "credit_card",
"credit_card": {
"id": 1684847614,
"data": {
"emv_receipt": null,
"signature_url": null
},
"auto_release": false
}
},
"hosted_checkout": null,
"payer": {
"email": "test@example.com",
"name": "Mr Smith",
"home_address": null
},
"npo_information": null,
"payment_error": null
}
*/
private function storePaymentMethod($response, $payment_method_id)
{

View File

@ -10,13 +10,13 @@
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
@csrf
<input type="hidden" name="gateway_response">
<input type="hidden" name="store_card">
<input type="hidden" name="store_card" id="store_card">
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->getCompanyGatewayId() }}">
<input type="hidden" name="payment_method_id" value="1">
<input type="hidden" name="token">
<input type="hidden" name="token" id="token" value="">
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@ -114,14 +114,6 @@
}
/* handle the switch between token and cc */
/* Attach store card value to form */
let storeCard = document.querySelector('input[name=token-billing-checkbox]:checked');
if (storeCard) {
document.getElementById("store_card").value = storeCard.value;
}
/* Attach store card value to form */
/* Pay Now Button */
let payNowButton = document.getElementById('pay-now');
@ -130,8 +122,16 @@
.addEventListener('click', (e) => {
let token = document.getElementById('token').value;
/* Attach store card value to form */
let storeCard = document.querySelector('input[name=token-billing-checkbox]:checked');
if (storeCard) {
document.getElementById("store_card").value = storeCard.value;
}
/* Attach store card value to form */
if(token){
handleTokenPayment($token)
handleTokenPayment(token)
}
else{
handleCardPayment();
@ -144,11 +144,11 @@
function handleTokenPayment($token)
function handleTokenPayment(token)
{
document.querySelector('input[name="credit_card_id"]').value = token;
document.getElementById('server_response').submit();
document.querySelector('input[name="token"]').value = token;
document.getElementById('server-response').submit();
}
@ -230,8 +230,8 @@
var token = data.credit_card_id;
document.querySelector('input[name="credit_card_id"]').value = token;
document.getElementById('server_response').submit();
document.querySelector('input[name="token"]').value = token;
document.getElementById('server-response').submit();
}
});