mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 07:07:31 -04:00 
			
		
		
		
	WePay ACH / Credit card Token billing
This commit is contained in:
		
							parent
							
								
									4ca034c9f6
								
							
						
					
					
						commit
						003f326f8d
					
				| @ -271,4 +271,66 @@ class ACH | ||||
|         $this->wepay_payment_driver->storeGatewayToken($data); | ||||
| 
 | ||||
|     }      | ||||
| 
 | ||||
| 
 | ||||
|     public function tokenBilling($token, $payment_hash) | ||||
|     { | ||||
|          | ||||
|         $token_meta = $token->meta; | ||||
| 
 | ||||
|         if(!property_exists($token_meta, 'state') || $token_meta->state != "authorized") | ||||
|             return redirect()->route('client.payment_methods.verification', ['payment_method' => $token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); | ||||
| 
 | ||||
|         $app_fee = (config('ninja.wepay.fee_ach_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed'); | ||||
| 
 | ||||
|         $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( | ||||
|             'unique_id'           => Str::random(40), | ||||
|             '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'   => 'Goods and Services', | ||||
|             'type'                => 'goods', | ||||
|             'fee'                 => [ | ||||
|                 'fee_payer' => config('ninja.wepay.fee_payer'), | ||||
|                 'app_fee' => $app_fee, | ||||
|             ], | ||||
|             'payment_method'      => array( | ||||
|                 'type'            => 'payment_bank', | ||||
|                 'payment_bank'     => array( | ||||
|                     'id'          => $token->token | ||||
|                 ) | ||||
|             ) | ||||
|         )); | ||||
| 
 | ||||
|                 /* Merge all data and store in the payment hash*/ | ||||
|         $state = [ | ||||
|             'server_response' => $response, | ||||
|             'payment_hash' => $this->wepay_payment_driver->payment_hash, | ||||
|         ]; | ||||
| 
 | ||||
|         $this->wepay_payment_driver->payment_hash->data = array_merge((array) $this->wepay_payment_driver->payment_hash->data, $state);  | ||||
|         $this->wepay_payment_driver->payment_hash->save(); | ||||
| 
 | ||||
|         if(in_array($response->state, ['authorized', 'captured'])){ | ||||
|             //success
 | ||||
|             nlog("success"); | ||||
|             $payment_status = $response->state == 'authorized' ? Payment::STATUS_COMPLETED : Payment::STATUS_PENDING; | ||||
| 
 | ||||
|             return $this->processSuccessfulPayment($response, $payment_status, GatewayType::BANK_TRANSFER, true); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array($response->state, ['released', 'cancelled', 'failed', 'expired'])){ | ||||
|             //some type of failure
 | ||||
|             nlog("failure"); | ||||
| 
 | ||||
|             $payment_status = $response->state == 'cancelled' ? Payment::STATUS_CANCELLED : Payment::STATUS_FAILED; | ||||
| 
 | ||||
|             $this->processUnSuccessfulPayment($response, $payment_status); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -261,7 +261,8 @@ https://developer.wepay.com/api/api-calls/checkout | ||||
| 
 | ||||
|     private function storePaymentMethod($response, $payment_method_id) | ||||
|     { | ||||
| nlog("storing card"); | ||||
|         nlog("storing card"); | ||||
| 
 | ||||
|         $payment_meta = new \stdClass; | ||||
|         $payment_meta->exp_month = (string) $response->expiration_month; | ||||
|         $payment_meta->exp_year = (string) $response->expiration_year; | ||||
| @ -281,5 +282,57 @@ nlog("storing card"); | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     public function tokenBilling($cgt, $payment_hash) | ||||
|     { | ||||
| 
 | ||||
|         $app_fee = (config('ninja.wepay.fee_cc_multiplier') * $this->wepay_payment_driver->payment_hash->data->amount_with_fee) + config('ninja.wepay.fee_fixed'); | ||||
|         // charge the credit card
 | ||||
|         $response = $this->wepay_payment_driver->wepay->request('checkout/create', array( | ||||
|             'unique_id'           => Str::random(40), | ||||
|             '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'   => 'Goods and services', | ||||
|             'type'                => 'goods', | ||||
|             'fee'                 => [ | ||||
|                 'fee_payer' => config('ninja.wepay.fee_payer'), | ||||
|                 'app_fee' => $app_fee, | ||||
|             ], | ||||
|             'payment_method'      => array( | ||||
|                 'type'            => 'credit_card', | ||||
|                 'credit_card'     => array( | ||||
|                     'id'          => $cgt->token | ||||
|                 ) | ||||
|             ) | ||||
|         )); | ||||
| 
 | ||||
|         /* Merge all data and store in the payment hash*/ | ||||
|         $state = [ | ||||
|             'server_response' => $response, | ||||
|             'payment_hash' => $payment_hash, | ||||
|         ]; | ||||
| 
 | ||||
|         $this->wepay_payment_driver->payment_hash->data = array_merge((array) $this->wepay_payment_driver->payment_hash->data, $state);  | ||||
|         $this->wepay_payment_driver->payment_hash->save(); | ||||
| 
 | ||||
| 
 | ||||
|         if(in_array($response->state, ['authorized', 'captured'])){ | ||||
|             //success
 | ||||
|             nlog("success"); | ||||
|             $payment_status = $response->state == 'authorized' ? Payment::STATUS_COMPLETED : Payment::STATUS_PENDING; | ||||
| 
 | ||||
|             return $this->processSuccessfulPayment($response, $payment_status, GatewayType::CREDIT_CARD, true); | ||||
|         } | ||||
| 
 | ||||
|         if(in_array($response->state, ['released', 'cancelled', 'failed', 'expired'])){ | ||||
|             //some type of failure
 | ||||
|             nlog("failure"); | ||||
| 
 | ||||
|             $payment_status = $response->state == 'cancelled' ? Payment::STATUS_CANCELLED : Payment::STATUS_FAILED; | ||||
| 
 | ||||
|             $this->processUnSuccessfulPayment($response, $payment_status); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -22,7 +22,7 @@ trait WePayCommon | ||||
| { | ||||
| 
 | ||||
| 
 | ||||
|     private function processSuccessfulPayment($response, $payment_status, $gateway_type) | ||||
|     private function processSuccessfulPayment($response, $payment_status, $gateway_type, $return_payment = false) | ||||
|     { | ||||
| 
 | ||||
|         if($gateway_type == GatewayType::BANK_TRANSFER) | ||||
| @ -48,6 +48,9 @@ trait WePayCommon | ||||
|             $this->wepay_payment_driver->client->company, | ||||
|         ); | ||||
| 
 | ||||
|          if($return_payment) | ||||
|             return $payment; | ||||
| 
 | ||||
|         return redirect()->route('client.payments.show', ['payment' => $this->wepay_payment_driver->encodePrimaryKey($payment->id)]); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -119,14 +119,14 @@ class WePayPaymentDriver extends BaseDriver | ||||
|         $contact = $client->primary_contact()->first() ? $client->primary_contact()->first() : $lient->contacts->first(); | ||||
|         $data['contact'] = $contact; | ||||
| 
 | ||||
|         return $this->payment_method->authorizeView($data); //this is your custom implementation from here
 | ||||
|         return $this->payment_method->authorizeView($data); | ||||
|     } | ||||
| 
 | ||||
|     public function authorizeResponse($request) | ||||
|     { | ||||
|         $this->init(); | ||||
|          | ||||
|         return $this->payment_method->authorizeResponse($request);  //this is your custom implementation from here
 | ||||
|         return $this->payment_method->authorizeResponse($request);   | ||||
|     } | ||||
| 
 | ||||
|     public function verificationView(ClientGatewayToken $cgt) | ||||
| @ -147,19 +147,22 @@ class WePayPaymentDriver extends BaseDriver | ||||
|     { | ||||
|         $this->init(); | ||||
| 
 | ||||
|         return $this->payment_method->paymentView($data);  //this is your custom implementation from here
 | ||||
|         return $this->payment_method->paymentView($data);   | ||||
|     } | ||||
| 
 | ||||
|     public function processPaymentResponse($request) | ||||
|     { | ||||
|         $this->init(); | ||||
| 
 | ||||
|         return $this->payment_method->paymentResponse($request); //this is your custom implementation from here
 | ||||
|         return $this->payment_method->paymentResponse($request);  | ||||
|     } | ||||
| 
 | ||||
|     public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) | ||||
|     { | ||||
|         return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here
 | ||||
|         $this->setPaymentMethod($cgt->gateway_type_id); | ||||
|         $this->setPaymentHash($payment_hash); | ||||
| 
 | ||||
|         return $this->payment_method->tokenBilling($cgt, $payment_hash);  | ||||
|     } | ||||
| 
 | ||||
|     public function processWebhookRequest(PaymentWebhookRequest $request, Payment $payment = null) | ||||
|  | ||||
| @ -47,8 +47,9 @@ trait Inviteable | ||||
|     { | ||||
|         $entity_type = Str::snake(class_basename($this->entityType())); | ||||
| 
 | ||||
|         if(Ninja::isHosted()) | ||||
|         if(Ninja::isHosted()){ | ||||
|             $domain = isset($this->company->portal_domain) ? $this->company->portal_domain : $this->company->domain(); | ||||
|         } | ||||
|         else | ||||
|             $domain = config('ninja.app_url'); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user