PluginProbe
Pay with Vipps and MobilePay for WooCommerce / 6.2.5
Pay with Vipps and MobilePay for WooCommerce v6.2.5
6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.10 6.1.9 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1.0 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 6.0.0 5.4.3 5.4.2 All 187 releases
← All changes | payment/VippsApi.class.php +12 -142 6.0.0 → 6.2.5 View file →
@@ -738,9 +738,9 @@
738 738 return $res;
739 739 }
740 740
741 741
742 - // This is Vipps Checkout IOK 2021-06-19
742 + // This is Checkout IOK 2021-06-19
743 743 // Updated for V3 2023-01-09
744 744 public function initiate_checkout($customerinfo,$order,$returnurl,$authtoken,$idempotency_key=null) {
745 745 $command = 'checkout/v3/session';
746 746 $static_shipping = $order->get_meta('_vipps_static_shipping');
@@ -814,9 +814,9 @@
814 814 $transaction['paymentDescription'] = substr($transaction['paymentDescription'],0,90); // Add some slack if this happens. IOK 2019-10-17
815 815 }
816 816
817 817
818 - ## Vipps Checkout Shipping
818 + ## Checkout Shipping
819 819 $shippingcallback = $this->gateway->shipping_details_callback_url($authtoken, $orderid);
820 820 $shippingcallback .= "/v3/checkout/" . $vippsorderid . "/shippingDetails"; # because this is how eCom v2 does it.
821 821 $gw = $this->gateway;
822 822 if ($needs_shipping) {
@@ -888,9 +888,9 @@
888 888 $configuration['elements'] = "Full";
889 889 $configuration['customerInteraction'] = apply_filters('woo_vipps_checkout_customerInteraction', 'CUSTOMER_NOT_PRESENT', $orderid);
890 890 $configuration['userFlow'] = "WEB_REDIRECT"; // Change to NATIVE_REDIRECT for apps in below filter
891 891 // Require consent of email and openid sub - really for login
892 - $configuration['requireUserInfo'] = apply_filters('woo_vipps_checkout_requireUserInfo', $gw->get_option('requireUserInfo_checkout') == 'yes' , $orderid);
892 + $configuration['requireUserInfo'] = (bool) apply_filters('woo_vipps_checkout_requireUserInfo', $gw->get_option('requireUserInfo_checkout') == 'yes' , $orderid);
893 893
894 894
895 895 // IOK 2023-12-22 and we can add an order summary, so do so by default
896 896 $summarize = apply_filters('woo_vipps_checkout_show_order_summary', true, $order);
@@ -927,11 +927,12 @@
927 927 // Should return a map from other_method => ['gw'=>'gateway key or any or empty string]
928 928 $other_payment_methods = apply_filters('woo_vipps_checkout_external_payment_methods', VippsCheckout::instance()->external_payment_methods(), $order);
929 929 if (!empty($other_payment_methods)) {
930 930 $others = [];
931 + $cb = wp_create_nonce('vipps_gw_' . $orderid);
931 932 foreach ($other_payment_methods as $methodkey => $methoddata) {
932 933 $chooseanother = ['action'=>'vipps_gw', 'o'=>$orderid];
933 - $chooseanother['cb'] = wp_create_nonce('vipps_gw');
934 + $chooseanother['cb'] = $cb;
934 935 $chooseanother['gw'] = ($methoddata['gw'] ?? "");
935 936 $others[] = ['paymentMethod' => $methodkey, 'redirectUrl'=> add_query_arg($chooseanother,admin_url("admin-post.php")) ];
936 937 }
937 938 if (!empty($others)) {
@@ -949,10 +950,10 @@
949 950 $configuration['customConsent'] = $customconsent;
950 951 }
951 952
952 953 if (!$needs_shipping) {
953 - $nocontacts = $this->gateway->get_option('noContactFields') == 'yes';
954 - $noaddress = $this->gateway->get_option('noAddressFields') == 'yes';
954 + $nocontacts = (bool) ($this->gateway->get_option('noContactFields') == 'yes');
955 + $noaddress = (bool) ($this->gateway->get_option('noAddressFields') == 'yes');
955 956 if ($noaddress) {
956 957 $configuration['elements'] = "PaymentAndContactInfo";
957 958 }
958 959 // AddressFields cannot be enabled while ContactFields is disabled
@@ -1074,143 +1075,9 @@
1074 1075 }
1075 1076 return $res;
1076 1077 }
1077 1078
1078 - // Capture a payment made. Amount is in cents and required. IOK 2018-05-07
1079 - public function capture_payment($order,$amount,$requestid=1) {
1080 - $orderid = $order->get_meta('_vipps_orderid');
1081 1079
1082 - $command = 'Ecomm/v2/payments/'.$orderid.'/capture';
1083 - $msn = $this->get_merchant_serial();
1084 - $subkey = $this->get_key($msn);
1085 - if (!$subkey) {
1086 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1087 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1088 - }
1089 - if (!$msn) {
1090 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1091 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1092 - }
1093 - $headers = $this->get_headers($msn);
1094 - $headers['X-Request-Id'] = $requestid;
1095 -
1096 - $transaction = array();
1097 - // Ignore refOrderId - for child-transactions
1098 - $transaction['amount'] = round($amount);
1099 -
1100 - $shop_identification = apply_filters('woo_vipps_transaction_text_shop_id', home_url());
1101 -
1102 - $transaction['transactionText'] = __('Order capture for order','woo-vipps') . ' ' . $orderid . ' ' . $shop_identification;
1103 -
1104 - // The limit for the transaction text is 100. Ensure we don't go over. Thanks to Marco1970 on wp.org for reporting this. IOK 2019-10-17
1105 - $length = strlen($transaction['transactionText']);
1106 - if ($length>99) {
1107 - $this->log(__('The transaction text is too long! We are using a shorter transaction text to allow the transaction text to go through, but please check the \'woo_vipps_transaction_text_shop_id\' filter so that you can use a shorter name for your store', 'woo-vipps'));
1108 - $transaction['transactionText'] = __('Order capture for order','woo-vipps') . ' ' . $orderid;
1109 - $transaction['transactionText'] = substr($transaction['transactionText'],0,90); // Add some slack if this happens. IOK 2019-10-17
1110 - }
1111 -
1112 -
1113 -
1114 - $data = array();
1115 - $data['merchantInfo'] = array('merchantSerialNumber' => $msn);
1116 - $data['transaction'] = $transaction;
1117 -
1118 - $res = $this->http_call($msn,$command,$data,'POST',$headers,'json');
1119 - return $res;
1120 - }
1121 -
1122 - // Cancel a reserved but not captured payment IOK 2018-05-07
1123 - public function cancel_payment($order,$requestid=1) {
1124 - $orderid = $order->get_meta('_vipps_orderid');
1125 -
1126 - $command = 'Ecomm/v2/payments/'.$orderid.'/cancel';
1127 - $msn = $this->get_merchant_serial();
1128 - $subkey = $this->get_key($msn);
1129 - if (!$subkey) {
1130 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1131 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1132 - }
1133 - if (!$msn) {
1134 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1135 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1136 - }
1137 - $headers = $this->get_headers($msn);
1138 - $headers['X-Request-Id'] = $requestid;
1139 -
1140 - $transaction = array();
1141 - $transaction['transactionText'] = __('Order cancel for order','woo-vipps') . ' ' . $orderid . ' ';
1142 -
1143 - $data = array();
1144 - $data['merchantInfo'] = array('merchantSerialNumber' => $msn);
1145 - $data['transaction'] = $transaction;
1146 -
1147 - $res = $this->http_call($msn,$command,$data,'PUT',$headers,'json');
1148 - return $res;
1149 - }
1150 -
1151 - // Refund a captured payment. IOK 2018-05-08
1152 - public function refund_payment($order,$requestid=1,$amount=0,$cents=false) {
1153 - $orderid = $order->get_meta('_vipps_orderid');
1154 - $amount = $amount ? $amount : wc_format_decimal($order->get_total(),'');
1155 -
1156 - $command = 'Ecomm/v2/payments/'.$orderid.'/refund';
1157 - $msn = $this->get_merchant_serial();
1158 - $subkey = $this->get_key($msn);
1159 - if (!$subkey) {
1160 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1161 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1162 - }
1163 - if (!$msn) {
1164 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1165 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1166 - }
1167 - $headers = $this->get_headers($msn);
1168 - $headers['X-Request-Id'] = $requestid;
1169 -
1170 - // Ignore refOrderId - for child-transactions
1171 - $transaction = array();
1172 - // If we have passed the value as 'øre' we don't need to calculate any more.
1173 - if ($cents) {
1174 - $transaction['amount'] = $amount;
1175 - } else {
1176 - $transaction['amount'] = round($amount * 100);
1177 - }
1178 - $transaction['transactionText'] = __('Refund for order','woo-vipps') . ' ' . $orderid;
1179 -
1180 -
1181 - $data = array();
1182 - $data['merchantInfo'] = array('merchantSerialNumber' => $msn);
1183 - $data['transaction'] = $transaction;
1184 -
1185 - $res = $this->http_call($msn,$command,$data,'POST',$headers,'json');
1186 - return $res;
1187 - }
1188 -
1189 - // Used to retrieve shipping and user details for express checkout orders where relevant and the callback isn't coming.
1190 - public function payment_details ($order) {
1191 - $requestid=0;
1192 - $orderid = $order->get_meta('_vipps_orderid');
1193 - $command = 'Ecomm/v2/payments/'.$orderid.'/details';
1194 - $msn = $this->get_merchant_serial();
1195 - $subkey = $this->get_key($msn);
1196 - if (!$subkey) {
1197 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1198 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1199 - }
1200 - if (!$msn) {
1201 - throw new VippsAPIConfigurationException(__('The Vipps gateway is not correctly configured.','woo-vipps'));
1202 - $this->log(__('The Vipps gateway is not correctly configured.','woo-vipps'),'error');
1203 - }
1204 - $headers = $this->get_headers($msn);
1205 - $headers['X-Request-Id'] = $requestid;
1206 -
1207 - $data = array();
1208 -
1209 - $res = $this->http_call($msn,$command,$data,'GET',$headers,'json');
1210 - return $res;
1211 - }
1212 -
1213 1080 // Support for then new epayment API, which is also used by Checkout
1214 1081 // Cancel a reserved but not captured payment IOK 2018-05-07
1215 1082 // Currently must cancel the entire amount, but partial cancel will be possible.
1216 1083 public function epayment_cancel_payment($order,$requestid=1) {
@@ -1363,9 +1230,12 @@
1363 1230 return $res;
1364 1231 }
1365 1232
1366 1233 // Implement part of the userInfo api, just to be able to get user data from Express Orders that aren't express
1367 - // orders (because they didn't need shipping). In the future, will probably be used more + for integration with Login With Vipps
1234 + // orders (because they didn't need shipping).
1235 + // If a user has a sub, it is because we've added a scope to the epayment call, or because of integration with login.
1236 + // This is not used as of 2026-08-18, because we do not need to call this to retreive user details any more with ecom -
1237 + // we get that by just calling the payment details. Still may be useful in the future without depending on login integration. IOK 2026-08-18
1368 1238 public function get_userinfo($sub) {
1369 1239 $command = "vipps-userinfo-api/userinfo" . "/" . $sub;
1370 1240 $msn = $this->get_merchant_serial();
1371 1241 $subkey = $this->get_key($msn);
@@ -1402,9 +1272,9 @@
1402 1272 return $this->call_qr_merchant_redirect($action, $id, $url);
1403 1273 }
1404 1274 public function delete_merchant_redirect_qr ($id) {
1405 1275 $action = "DELETE";
1406 - return $this->call_qr_merchant_redirect($action, $id, $url);
1276 + return $this->call_qr_merchant_redirect($action, $id);
1407 1277 }
1408 1278 private function call_qr_merchant_redirect($action, $id, $url=null, $accept='image/svg+xml') {
1409 1279 $command = 'qr/v1/merchant-redirect/';
1410 1280 if ($action != "POST") $command .= $id;