@@ -55,21 +55,40 @@ protected function requestToken()
5555 throw new Exception ('larapay::larapay.could_not_request_payment ' );
5656 }
5757
58+
5859 $ this ->checkRequiredParameters ([
5960 'pin ' ,
6061 'order_id ' ,
6162 'amount ' ,
6263 'redirect_url ' ,
6364 ]);
6465
66+
6567 $ sendParams = [
6668 'LoginAccount ' => $ this ->pin ,
6769 'Amount ' => intval ($ this ->amount ),
6870 'OrderId ' => intval ($ this ->order_id ),
6971 'CallBackUrl ' => $ this ->redirect_url ,
70- 'AdditionalData ' => $ this ->additional_data ? $ this ->additional_data : '' ,
72+ 'AdditionalData ' => $ this ->additional_data ?? '' ,
73+ 'Originator ' => $ this ->originator ?? '' ,
7174 ];
7275
76+
77+ if (is_array ($ this ->sharing ) && !empty ($ this ->sharing )) {
78+ return $ this ->requestTokenWithoutSharing ($ sendParams );
79+ } else {
80+ return $ this ->requestTokenWithSharing ($ sendParams );
81+ }
82+ }
83+
84+ /**
85+ * @param array $sendParams
86+ *
87+ * @return mixed
88+ * @throws Exception
89+ */
90+ private function requestTokenWithoutSharing ($ sendParams )
91+ {
7392 try {
7493 $ this ->requestType = 'request ' ;
7594 $ soapClient = $ this ->getSoapClient ();
@@ -96,6 +115,60 @@ protected function requestToken()
96115 }
97116 }
98117
118+ /**
119+ * @param array $sendParams
120+ *
121+ * @return mixed
122+ * @throws Exception
123+ */
124+ private function requestTokenWithSharing ($ sendParams )
125+ {
126+ foreach ($ this ->sharing as $ item ) {
127+ if (isset ($ item ->IBAN )) {
128+ // dynamic sharing
129+ $ method = 'MultiplexedSaleWithIBANPaymentRequest ' ;
130+ $ respo = 'MultiplexedSaleWithIBANPaymentResult ' ;
131+ $ sendParams ['MultiplexedAccounts ' ]['Account ' ][] = [
132+ 'Amount ' => $ item ->share ,
133+ 'PayId ' => $ item ->pay_id ?? '' ,
134+ 'IBAN ' => $ item ->iban
135+ ];
136+ } else {
137+ // fix sharing
138+ $ method = 'MultiplexedSalePaymentRequest ' ;
139+ $ respo = 'MultiplexedSalePaymentResult ' ;
140+ $ sendParams ['MultiplexedAccounts ' ]['Account ' ][] = [
141+ 'Amount ' => $ item ->share ,
142+ 'PayId ' => $ item ->pay_id ?? '' ,
143+ ];
144+ }
145+ }
146+
147+ try {
148+ $ this ->requestType = 'request ' ;
149+ $ soapClient = $ this ->getSoapClient ();
150+
151+ XLog::debug ("{$ method } call " , $ sendParams );
152+
153+ $ response = $ soapClient ->$ method (array ("requestData " => $ sendParams ));
154+
155+ XLog::debug ("{$ method } response " , $ this ->obj2array ($ response ));
156+
157+ if (isset ($ response ->$ respo ->Status , $ response ->$ respo ->Token )) {
158+ if ($ response ->$ respo ->Status == 0 ) {
159+ $ this ->getTransaction ()->setGatewayToken (strval ($ response ->$ respo ->Token )); // update transaction reference id
160+
161+ return $ response ->$ respo ->Token ;
162+ } else {
163+ throw new Exception ($ this ->$ respo ->Status );
164+ }
165+ } else {
166+ throw new Exception ('larapay::parsian.errors.invalid_response ' );
167+ }
168+ } catch (SoapFault $ e ) {
169+ throw new Exception ('SoapFault: ' . $ e ->getMessage () . ' # ' . $ e ->getCode (), $ e ->getCode ());
170+ }
171+ }
99172 /**
100173 * @return mixed
101174 * @throws Exception
0 commit comments