I'm wondering how I validate my json data in Laravel.
I have my data like this
In the controller I request like this
request('payment')['cardnumber']
How do I validate this.
Currently I have a RequestValidator class like this
public function rules()
{
return [
'billing_address' => 'required',
'town' => 'required',
'county' => 'required',
];
}
This is my controller
public function ProcessAdvertPayment(Property $property, Request $request, PropertyPaymentRequest $propertyPaymentRequest)
{
$payload = $request->input('payload', false);
$nonce = $payload['nonce'];
$payment = Braintree_Transaction::sale([
'amount' => 1,
'paymentMethodNonce' => $nonce,
'creditCard' => ['number' => request('payment')['cardnumber'], 'expirationDate' => request('payment')['month'] . '/' . request('payment')['year'], "cvv" => request('payment')['cvv']],
]);
if($payment->success)
{
$property->payment()->create(['amount' => $payment->transaction->amount, 'braintree_transaction_id' => $payment->transaction->id, 'billing_address' => request('payment')['billing_address'], 'town' => request('payment')['town'], 'county' => request('payment')['county']]);
return response()->json($payment);
}
return response()->json(['error' => 'Payment Failed. Please try again or contact your payment provider for further help.'], 400);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire