mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 08:37:33 -04:00 
			
		
		
		
	Filters for bank accounts
This commit is contained in:
		
							parent
							
								
									50398360b9
								
							
						
					
					
						commit
						ef388a0c77
					
				| @ -115,6 +115,28 @@ class BankTransactionFilters extends QueryFilters | |||||||
|         return $this->builder; |         return $this->builder; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |      | ||||||
|  |     /** | ||||||
|  |      * Filters the list based on Bank Accounts. | ||||||
|  |      * | ||||||
|  |      * @param string $ids Comma Separated List of bank account ids | ||||||
|  |      * @return Builder | ||||||
|  |      */ | ||||||
|  |     public function bank_integration_ids(string $ids = ''): Builder | ||||||
|  |     { | ||||||
|  |         if(strlen($ids) == 0) | ||||||
|  |             return $this->builder; | ||||||
|  | 
 | ||||||
|  |         $ids = $this->transformKeys(explode(",", $ids)); | ||||||
|  |          | ||||||
|  |         $this->builder->where(function ($query) use ($ids) { | ||||||
|  |             $query->whereIn('bank_integration_id', $ids); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         return $this->builder; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Sorts the list based on $sort. |      * Sorts the list based on $sort. | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -94,7 +94,101 @@ | |||||||
|     const clientId = "{{ $client_id }}"; |     const clientId = "{{ $client_id }}"; | ||||||
|     const orderId = "{!! $order_id !!}"; |     const orderId = "{!! $order_id !!}"; | ||||||
| 
 | 
 | ||||||
|     const buttons = paypal.Buttons(); |     const buttons = paypal.Buttons({ | ||||||
|  |         client: clientId, | ||||||
|  |         createOrder: function(data, actions) { | ||||||
|  |             return orderId;   | ||||||
|  |         }, | ||||||
|  |         onApprove: function(data, actions) { | ||||||
|  | 
 | ||||||
|  |             const { liabilityShift, orderID } = data; | ||||||
|  |              if(liabilityShift) { | ||||||
|  |                | ||||||
|  |               /* Handle liability shift. More information in 3D Secure response parameters */ | ||||||
|  |               if(liabilityShift == 'NO') { | ||||||
|  | 
 | ||||||
|  |                 document.getElementById('errors').textContent = `Sorry, your transaction could not be processed, Please try a different payment method.`; | ||||||
|  |                 document.getElementById('errors').hidden = false; | ||||||
|  | 
 | ||||||
|  |                 return; | ||||||
|  |               } | ||||||
|  | 
 | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             let storeCard = document.querySelector('input[name=token-billing-checkbox]:checked'); | ||||||
|  | 
 | ||||||
|  |             if (storeCard) { | ||||||
|  |                 document.getElementById("store_card").value = storeCard.value; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             document.getElementById("gateway_response").value =JSON.stringify( data );   | ||||||
|  |              | ||||||
|  |             formData = JSON.stringify(Object.fromEntries(new FormData(document.getElementById("server_response")))), | ||||||
|  | 
 | ||||||
|  |             fetch('{{ route('client.payments.response') }}', { | ||||||
|  |                 method: 'POST', | ||||||
|  |                 headers: { | ||||||
|  |                     'Content-Type': 'application/json', | ||||||
|  |                     "X-Requested-With": "XMLHttpRequest", | ||||||
|  |                     "X-CSRF-Token": document.querySelector('meta[name="csrf-token"]').content | ||||||
|  |                 }, | ||||||
|  |                 body: formData, | ||||||
|  |             }) | ||||||
|  |             .then(response => { | ||||||
|  |                 if (!response.ok) { | ||||||
|  |                     throw new Error('Network response was not ok ' + response.statusText); | ||||||
|  |                 } | ||||||
|  |                 return response.json(); | ||||||
|  |             }) | ||||||
|  |             .then(data => { | ||||||
|  | 
 | ||||||
|  |                 var errorDetail = Array.isArray(data.details) && data.details[0]; | ||||||
|  | 
 | ||||||
|  |                 if (errorDetail && ['INSTRUMENT_DECLINED', 'PAYER_ACTION_REQUIRED'].includes(errorDetail.issue)) { | ||||||
|  |                     return actions.restart(); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 if(data.redirect){ | ||||||
|  |                     window.location.href = data.redirect; | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 document.getElementById("gateway_response").value =JSON.stringify( data ); | ||||||
|  |                 document.getElementById("server_response").submit(); | ||||||
|  |             }) | ||||||
|  |             .catch(error => { | ||||||
|  |                 console.error('Error:', error); | ||||||
|  |                  | ||||||
|  |                 document.getElementById('errors').textContent = `Sorry, your transaction could not be processed...\n\n${error.message}`; | ||||||
|  |                 document.getElementById('errors').hidden = false; | ||||||
|  | 
 | ||||||
|  |             }); | ||||||
|  | 
 | ||||||
|  |         }, | ||||||
|  |         onCancel: function() { | ||||||
|  | 
 | ||||||
|  |             window.location.href = "/client/invoices/"; | ||||||
|  |         }, | ||||||
|  |         // onError: function(error) {
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         // console.log("submit catch");
 | ||||||
|  |         // const errorM = parseError(error);
 | ||||||
|  | 
 | ||||||
|  |         // console.log(errorM);
 | ||||||
|  | 
 | ||||||
|  |         // const msg = handle422Error(errorM);
 | ||||||
|  | 
 | ||||||
|  |         //     document.getElementById('errors').textContent = `Sorry, your transaction could not be processed...\n\n${msg.description}`;
 | ||||||
|  |         //     document.getElementById('errors').hidden = false;
 | ||||||
|  | 
 | ||||||
|  |         // },
 | ||||||
|  |         onClick: function (){ | ||||||
|  |             | ||||||
|  |         } | ||||||
|  |      | ||||||
|  | 
 | ||||||
|  |     }); | ||||||
|      |      | ||||||
|     @if(strlen($pp_client_reference) > 1) |     @if(strlen($pp_client_reference) > 1) | ||||||
|         buttons.render('#paypal-button-container'); |         buttons.render('#paypal-button-container'); | ||||||
| @ -243,6 +337,8 @@ | |||||||
| 
 | 
 | ||||||
|         }).catch((error) => { |         }).catch((error) => { | ||||||
| 
 | 
 | ||||||
|  |             console.log(error); | ||||||
|  |              | ||||||
|             let msg; |             let msg; | ||||||
| 
 | 
 | ||||||
|             if(!['INVALID_NUMBER','INVALID_CVV','INVALID_EXPIRY'].includes(error.message)) |             if(!['INVALID_NUMBER','INVALID_CVV','INVALID_EXPIRY'].includes(error.message)) | ||||||
|  | |||||||
| @ -40,6 +40,98 @@ class BankTransactionTest extends TestCase | |||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function testBankIntegrationFilters() | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         $bi = BankIntegrationFactory::create($this->company->id, $this->user->id, $this->account->id); | ||||||
|  |         $bi->bank_account_name = "Bank1"; | ||||||
|  |         $bi->save(); | ||||||
|  | 
 | ||||||
|  |         $bt = BankTransactionFactory::create($this->company->id, $this->user->id); | ||||||
|  |         $bt->bank_integration_id = $bi->id; | ||||||
|  |         $bt->status_id = BankTransaction::STATUS_UNMATCHED; | ||||||
|  |         $bt->description = 'Fuel'; | ||||||
|  |         $bt->amount = 10; | ||||||
|  |         $bt->currency_code = $this->client->currency()->code; | ||||||
|  |         $bt->date = now()->format('Y-m-d'); | ||||||
|  |         $bt->transaction_id = 1234567890; | ||||||
|  |         $bt->category_id = 10000003; | ||||||
|  |         $bt->base_type = 'DEBIT'; | ||||||
|  |         $bt->save(); | ||||||
|  | 
 | ||||||
|  |                  | ||||||
|  |         $bi2 = BankIntegrationFactory::create($this->company->id, $this->user->id, $this->account->id); | ||||||
|  |         $bi2->bank_account_name = "Bank2"; | ||||||
|  |         $bi2->save(); | ||||||
|  | 
 | ||||||
|  |         $bt = BankTransactionFactory::create($this->company->id, $this->user->id); | ||||||
|  |         $bt->bank_integration_id = $bi2->id; | ||||||
|  |         $bt->status_id = BankTransaction::STATUS_UNMATCHED; | ||||||
|  |         $bt->description = 'Fuel'; | ||||||
|  |         $bt->amount = 20; | ||||||
|  |         $bt->currency_code = $this->client->currency()->code; | ||||||
|  |         $bt->date = now()->format('Y-m-d'); | ||||||
|  |         $bt->transaction_id = 1234567890; | ||||||
|  |         $bt->category_id = 10000003; | ||||||
|  |         $bt->base_type = 'DEBIT'; | ||||||
|  |         $bt->save(); | ||||||
|  | 
 | ||||||
|  |         $response = $this->withHeaders([ | ||||||
|  |             'X-API-SECRET' => config('ninja.api_secret'), | ||||||
|  |             'X-API-TOKEN' => $this->token, | ||||||
|  |         ])->getJson('/api/v1/bank_transactions'); | ||||||
|  | 
 | ||||||
|  |         $response->assertStatus(200); | ||||||
|  | 
 | ||||||
|  |         $arr = $response->json(); | ||||||
|  | 
 | ||||||
|  |         $transaction_count = count($arr['data']); | ||||||
|  |          | ||||||
|  |         $this->assertGreaterThan(1, $transaction_count); | ||||||
|  | 
 | ||||||
|  |         $response = $this->withHeaders([ | ||||||
|  |             'X-API-SECRET' => config('ninja.api_secret'), | ||||||
|  |             'X-API-TOKEN' => $this->token, | ||||||
|  |         ])->getJson('/api/v1/bank_transactions?bank_integration_ids='.$bi->hashed_id); | ||||||
|  | 
 | ||||||
|  |         $response->assertStatus(200); | ||||||
|  | 
 | ||||||
|  |         $arr = $response->json(); | ||||||
|  | 
 | ||||||
|  |         $transaction_count = count($arr['data']); | ||||||
|  | 
 | ||||||
|  |         $this->assertCount(1, $arr['data']); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         $response = $this->withHeaders([ | ||||||
|  |             'X-API-SECRET' => config('ninja.api_secret'), | ||||||
|  |             'X-API-TOKEN' => $this->token, | ||||||
|  |         ])->getJson('/api/v1/bank_transactions?bank_integration_ids='.$bi2->hashed_id); | ||||||
|  | 
 | ||||||
|  |         $response->assertStatus(200); | ||||||
|  | 
 | ||||||
|  |         $arr = $response->json(); | ||||||
|  | 
 | ||||||
|  |         $transaction_count = count($arr['data']); | ||||||
|  | 
 | ||||||
|  |         $this->assertCount(1, $arr['data']); | ||||||
|  | 
 | ||||||
|  |         $response = $this->withHeaders([ | ||||||
|  |             'X-API-SECRET' => config('ninja.api_secret'), | ||||||
|  |             'X-API-TOKEN' => $this->token, | ||||||
|  |         ])->getJson('/api/v1/bank_transactions?bank_integration_ids='.$bi2->hashed_id.",".$bi->hashed_id); | ||||||
|  | 
 | ||||||
|  |         $response->assertStatus(200); | ||||||
|  | 
 | ||||||
|  |         $arr = $response->json(); | ||||||
|  | 
 | ||||||
|  |         $transaction_count = count($arr['data']); | ||||||
|  | 
 | ||||||
|  |         $this->assertCount(2, $arr['data']); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function testLinkMultipleExpensesWithDeleteToTransaction() |     public function testLinkMultipleExpensesWithDeleteToTransaction() | ||||||
|     { |     { | ||||||
|         $data = []; |         $data = []; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user