У меня есть угловое приложение с Laravel API на сервере. Я пытаюсь создать форму оплаты. Данные отправляются. Я вижу это в консоли, когда я отправляю форму. Но я получаю ошибку 422 - Необработанный объект. Правила проверки не действительны для города, округа и адреса выставления счетов. Но они есть в консоли.
Компонент оплаты
export class AdvertPaymentComponent implements OnInit {
advertPaymentForm: FormGroup;
model: any;
payment: Payment;
constructor(private advertService: AdvertService, private alertify: AlertifyService, public authService: AuthService,
private formBuilder: FormBuilder) { }
ngOnInit() {
this.createAdvertPaymentForm();
}
createAdvertPaymentForm() {
this.advertPaymentForm = this.formBuilder.group({
town: ['', Validators.required],
county: ['', Validators.required],
billing_address: ['', Validators.required],
cardnumber: ['', Validators.required],
month: ['', Validators.required],
year: ['', Validators.required],
cvv: ['', Validators.required],
});
}
submitPayment() {
if (this.advertPaymentForm.value) {
this.payment = (Object.assign({}, this.advertPaymentForm.value));
console.log(this.payment);
this.advertService.createAdvertPayment(2, this.payment).subscribe(data => {
this.alertify.success('Success');
}, error => {
this.alertify.error(error);
});
}
}
}
Оплата HTML
<form [formGroup]="advertPaymentForm" (ngSubmit)="submitPayment()">
<ng-template matStepLabel>Enter Card Details</ng-template>
<div class="form-group">
<input type="text" class="form-control" formControlName="billing_address" placeholder="Billing Address">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="town" placeholder="town">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="county" placeholder="county">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="cardnumber" placeholder="4111111111111111">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="month" placeholder="05">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="year" placeholder="19">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="cvv" placeholder="cvv">
</div>
<div class="form-group">
<input type="text" class="form-control" formControlName="county" placeholder="county">
</div>
<button mat-button matStepperNext>Next</button>
</form>
Метод Advert Serice, вызываемый в компоненте оплаты.
createAdvertPayment(propertyId: number, payment: Payment) {
return this.http.post(this.baseUrl + propertyId + '/payment', {payment});
}
Это модель оплаты
export interface Payment {
town?: string;
county?: string;
billing_address: string;
cardnumber: string;
month: string;
year: string;
cvv: string;
}
Это функция laravel, которая вызывается из конечной точки.
публичная функция 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('cardnumber'), 'expirationDate' => request('month') . '/' . request('year'), "cvv" => request('cvv')],
]);
if($payment->success)
{
$property->payment()->create(['amount' => $payment->transaction->amount, 'braintree_transaction_id' => $payment->transaction->id, 'billing_address' => request(['property']->billing_address), 'town' => request('town'), 'county' => request('county')]);
return response()->json($payment);
}
return response()->json(['error' => 'Payment Failed. Please try again or contact your payment provider for further help.'], 400);
}
Это изображение полезной нагрузки