Changeset 1895913
- Timestamp:
- 06/20/2018 03:21:51 PM (8 years ago)
- Location:
- fermopoint-for-woocommerce/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (2 diffs)
-
admin/class-fermopoint-admin.php (modified) (2 diffs)
-
admin/includes/settings-fermopoint.php (modified) (4 diffs)
-
admin/includes/settings-general-fermopoint.php (modified) (4 diffs)
-
fermopoint-for-woocommerce.php (modified) (1 diff)
-
function.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fermopoint-for-woocommerce/trunk/README.txt
r1811711 r1895913 5 5 Tags: woocommerce, fermopoint, shipping 6 6 7 Version: 1.3 7 Version: 1.3.1 8 8 9 9 Requires at least: 3.0.1 10 10 11 Tested up to:4. 7.411 Tested up to:4.9.6 12 12 13 Stable tag: 4. 7.413 Stable tag: 4.9.6 14 14 15 15 License: GPLv2 or later … … 142 142 * Migliorata la gestione della creazione Ticket 143 143 144 = 1.3.1 = 145 146 * Controllo per verificare la correttezza dei dati inseriti e la visibilità dei messaggi di errore. 147 * Eliminati i messaggi di warning in php 148 -
fermopoint-for-woocommerce/trunk/admin/class-fermopoint-admin.php
r1811711 r1895913 450 450 451 451 452 453 452 $this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled 454 453 … … 501 500 $this->cost = $this->get_option( 'cost' ); 502 501 502 503 503 504 $this->enabled = $this->get_option( 'enabled' ); 504 505 506 505 507 $this->visibile = $this->get_option( 'FERMOPOINT_MODALITAVISIBILE' ); 506 508 -
fermopoint-for-woocommerce/trunk/admin/includes/settings-fermopoint.php
r1811711 r1895913 1 1 <?php 2 3 2 4 3 5 … … 5 7 if ( ! defined( 'ABSPATH' ) ) { 6 8 9 7 10 exit; 11 8 12 9 13 } … … 15 19 16 20 21 22 23 24 17 25 /** 26 18 27 19 28 * Settings for flat rate shipping. 20 29 30 21 31 */ 32 22 33 23 34 $settings = array( 24 35 36 25 37 'enabled' => array( 38 26 39 27 40 'title' => __( 'Enable/Disable', 'fermopoint' ), 28 41 42 29 43 'type' => 'checkbox', 44 30 45 31 46 'label' => __( 'Enable Fermo!Point', 'fermopoint' ), 32 47 33 'default' => 'yes' 48 49 'default' => 'false' 50 34 51 35 52 ), 36 53 54 37 55 56 38 57 39 58 'title' => array( 40 59 60 41 61 'title' => __( 'Title', 'fermopoint' ), 62 42 63 43 64 'type' => 'text', 44 65 66 45 67 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 68 46 69 47 70 'default' => __( 'Fermo!Point', 'fermopoint' ) 48 71 72 49 73 ), 74 50 75 51 76 52 77 78 53 79 'description' => array( 80 54 81 55 82 'title' => __( 'Description', 'fermopoint' ), 56 83 84 57 85 'type' => 'textarea', 86 58 87 59 88 'description' => __( 'This controls the description which the user sees during checkout.', 'fermopoint' ), 60 89 90 61 91 'default' => __("Ricevi il tuo acquisto in uno dei punti di ritiro Fermo!Point (www.fermopoint.it)", 'fermopoint') 92 62 93 63 94 ), 64 95 96 65 97 98 66 99 67 100 'cost' => array( 68 101 102 69 103 'title' => __( 'Cost per order', 'fermopoint' ), 104 70 105 71 106 'type' => 'price', 72 107 108 73 109 110 74 111 75 112 'description' => __( 'Enter a cost (excluding tax) per order, e.g. 5.00. Default is 0.', 'fermopoint' ), 76 113 114 77 115 'default' => '0', 116 78 117 79 118 'desc_tip' => true, 80 119 120 81 121 'placeholder' => wc_format_localized_price( 2.50 ), 122 82 123 83 124 ), 84 125 85 86 126 87 127 88 128 129 89 130 131 132 133 134 90 135 91 136 92 137 138 93 139 140 94 141 95 142 ); … … 99 146 100 147 148 149 150 101 151 return $settings; 102 152 153 -
fermopoint-for-woocommerce/trunk/admin/includes/settings-general-fermopoint.php
r1811711 r1895913 1 1 <?php 2 2 3 4 3 5 add_action( 'admin_menu', 'FERMOPOINT_add_admin_menu' ); 4 6 7 8 5 9 add_action( 'admin_init', 'FERMOPOINT_settings_init' ); 6 10 11 12 7 13 add_action( 'admin_init', 'fermopoint_mysettings' ); 8 14 … … 11 17 12 18 19 20 21 22 23 24 13 25 function fermopoint_add_admin_menu( ) { 14 26 15 27 16 17 28 add_submenu_page( 'woocommerce', 'Fermo!Point', 'Fermo!Point', 'manage_options', 'fermopoint_settings_init', 'fermopoint_options_page' ); 18 29 30 31 19 32 } 20 33 … … 23 36 24 37 38 39 40 41 42 43 25 44 function fermopoint_settings_init( ) { 26 45 27 46 47 48 49 50 28 51 29 52 add_option( 'FERMOPOINT_ACCOUNT_ID', "" ); 30 53 54 55 31 56 add_option( 'FERMOPOINT_ACCOUNT_SECRET', "" ); 32 57 58 59 33 60 add_option( 'FERMOPOINT_ACCOUNT_NICKNAME', "" ); 34 61 62 63 35 64 add_option( 'FERMOPOINT_ACCOUNT_BORNDATE', "" ); 36 65 37 38 39 /*RECUPERO I DATI DELLA VERSIONE 1.0 del PLUGIN*/ 40 41 $shippings_wc = new WC_Shipping ; 42 43 $shippings = $shippings_wc->load_shipping_methods(); 44 45 46 47 $fermopoint = $shippings["Fermo!Point"]; 48 49 if (isset($fermopoint)){ 50 51 $fermopoint_settings = $fermopoint->settings; 66 67 68 69 70 71 72 add_settings_section( 73 74 75 76 'fermopoint_pluginPage_section', 77 78 79 80 __( 'Configura Fermo!Point', 'fermopoint' ), 81 82 83 84 'fermopoint_settings_section_callback', 85 86 87 88 'pluginPage' 89 90 91 92 ); 93 94 95 96 97 98 99 100 101 102 103 104 add_settings_field( 105 106 107 108 'fermopoint_sandbox', '', 109 110 111 112 'fermopoint_hidden_field_0_render', 113 114 115 116 'pluginPage', 117 118 119 120 'fermopoint_pluginPage_section' 121 122 123 124 ); 125 126 127 128 129 130 131 132 add_settings_field( 133 134 135 136 'FERMOPOINT_ACCOUNT_ID', 137 138 139 140 __( 'Client ID', 'fermopoint' ) . ":" . __( 'The user code received at the time of the service', 'fermopoint' ), 141 142 143 144 'fermopoint_text_field_2_render', 145 146 147 148 'pluginPage', 149 150 151 152 'fermopoint_pluginPage_section' 153 154 155 156 ); 157 158 159 160 161 162 163 164 add_settings_field( 165 166 167 168 'FERMOPOINT_ACCOUNT_SECRET', 169 170 171 172 __( 'Client Secret', 'fermopoint' ) . ":" . __( 'The password received when registering for the service', 'fermopoint' ), 173 174 175 176 'fermopoint_text_field_3_render', 177 178 179 180 'pluginPage', 181 182 183 184 'fermopoint_pluginPage_section' 185 186 187 188 ); 189 190 191 192 193 194 195 196 197 198 199 200 add_settings_field( 201 202 203 204 'FERMOPOINT_ACCOUNT_NICKNAME', 205 206 207 208 __( 'Nickname merchant', 'fermopoint' ), 209 210 211 212 'fermopoint_text_field_4_render', 213 214 215 216 'pluginPage', 217 218 219 220 'fermopoint_pluginPage_section' 221 222 223 224 ); 225 226 227 228 229 230 231 232 233 234 235 236 add_settings_field( 237 238 239 240 'FERMOPOINT_ACCOUNT_BORNDATE', 241 242 243 244 __( 'Date', 'fermopoint' ), 245 246 247 248 'fermopoint_text_field_5_render', 249 250 251 252 'pluginPage', 253 254 255 256 'fermopoint_pluginPage_section' 257 258 259 260 ); 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 } 289 290 291 292 293 294 295 296 function fermopoint_hidden_field_0_render( ) { 297 298 299 300 301 302 303 304 $options = get_option( 'fermopoint_sandbox' ); 305 306 307 308 ?> 309 310 311 312 <input type='hidden' name='fermopoint_sandbox' value='<?php echo $options; ?>' /> 313 314 315 316 <?php 317 318 319 320 321 322 323 324 } 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 function fermopoint_text_field_2_render( ) { 341 342 343 344 345 346 347 348 $options = get_option( 'FERMOPOINT_ACCOUNT_ID' ); 349 350 351 352 ?> 353 354 355 356 <input type='text' name='FERMOPOINT_ACCOUNT_ID' value='<?php echo $options; ?>' style='width: 40%' /> 357 358 359 360 <?php 361 362 363 364 365 366 367 368 } 369 370 371 372 373 374 375 376 377 378 379 380 function fermopoint_text_field_3_render( ) { 381 382 383 384 385 386 387 388 $options = get_option( 'FERMOPOINT_ACCOUNT_SECRET' ); 389 390 391 392 ?> 393 394 395 396 <input type='text' name='FERMOPOINT_ACCOUNT_SECRET' value='<?php echo $options; ?>' style='width: 40%' /> 397 398 399 400 <?php 401 402 403 404 405 406 407 408 } 409 410 411 412 413 414 415 416 417 418 419 420 function fermopoint_text_field_4_render( ) { 421 422 423 424 425 426 427 428 $options = get_option( 'FERMOPOINT_ACCOUNT_NICKNAME' ); 429 430 431 432 ?> 433 434 435 436 <input type='text' name='FERMOPOINT_ACCOUNT_NICKNAME' value='<?php echo $options; ?>' style='width: 40%' /> 437 438 439 440 <?php 441 442 443 444 445 446 447 448 } 449 450 451 452 453 454 455 456 function fermopoint_text_field_5_render( ) { 457 458 459 460 461 462 463 464 $options = get_option( 'FERMOPOINT_ACCOUNT_BORNDATE' ); 465 466 467 468 ?> 469 470 471 472 <input type='text' name='FERMOPOINT_ACCOUNT_BORNDATE' value='<?php echo $options; ?>' style='width: 40%' /> 473 474 475 476 <?php 477 478 479 480 481 482 483 484 } 485 486 487 488 489 490 491 492 function fermopoint_settings_section_callback( ) { 493 494 495 496 497 498 499 500 echo "<a href='https://www.fermopoint.it/contatti-ecommerce' target='new'>" . __( 'Iscriviti a Fermo!Point se non lo hai ancora fatto', 'fermopoint' ) . "</a> | <a href='https://www.fermopoint.it/business/vantaggi-ecommerce' target='new'>" . __( 'Scropri i vantaggi', 'fermopoint' ) . "</a>"; 501 502 503 504 505 506 507 508 } 509 510 511 512 513 514 515 516 517 518 519 520 function fermopoint_mysettings() { // whitelist options 521 522 523 524 register_setting( 'pluginPage', 'fermopoint_sandbox' ); 525 526 527 528 register_setting( 'pluginPage', 'FERMOPOINT_MODALITAVISIBILE' ); 529 530 531 532 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_ID' ); 533 534 535 536 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_SECRET' ); 537 538 539 540 541 542 543 544 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_NICKNAME' ); 545 546 547 548 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_BORNDATE' ); 549 550 551 552 553 554 555 556 } 557 558 559 560 561 562 563 564 565 566 567 568 function fermopoint_options_page( ) { 569 570 571 572 573 574 575 576 $array = array("nickname"=> get_option("FERMOPOINT_ACCOUNT_NICKNAME"), "born_date"=> get_option("FERMOPOINT_ACCOUNT_BORNDATE"). "T00:00:00"); 577 578 579 580 $verify= callfermopointcurl("/public/users/check",$array); 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 echo "<a href='https://www.fermopoint.it/' target='new'><img src='https://www.fermopoint.it/Content/images/logo/logo.png'/></a>"; 601 602 603 604 echo "<hr/>"; 605 606 607 608 609 610 611 612 if (!$verify){?> 613 614 615 616 <div class="notice notice-error"> 617 618 619 620 <h2>FERMO!POINT: Attenzione! L'utente è inesistente, verificare correttamente i dati, il metodo di pagamento Fermo!Point non funzionerà sul sito</h2> 621 622 623 624 </div> 625 626 627 628 629 630 631 632 <?php 633 634 635 636 637 638 639 640 641 642 } ?> 643 644 645 646 <form action='options.php' method='post'> 647 648 649 650 <?php 651 652 653 654 settings_fields( 'pluginPage' ); 655 656 657 658 do_settings_sections( 'pluginPage' ); 659 660 661 662 submit_button(); 663 664 665 666 ?> 667 668 669 670 </form> 671 672 673 674 675 676 677 678 <?php 679 680 681 682 683 684 52 685 53 686 54 687 55 //Check if is correct 688 56 689 57 690 58 691 59 $account_id = get_option("FERMOPOINT_ACCOUNT_ID"); 60 61 $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET"); 692 693 694 if ($verify){ 695 696 697 698 699 700 701 702 echo "<hr/><h2>Riepilogo ticket Fermo!Point</h2>"; 703 704 705 706 707 708 global $wpdb; 709 710 $return_array = array(); 711 712 $total_discount = 0; 62 713 63 714 64 715 65 $request = json_encode(array( 66 67 "client_id" => $account_id, 68 69 "auth_token" =>$auth_token, 70 71 "ts" => $ts, 72 73 )); 74 75 $ret= callfermopointcurl("/merchant",$request); 716 $query = "SELECT 717 718 p.ID AS order_id 719 720 FROM 721 722 {$wpdb->prefix}posts AS p 723 724 INNER JOIN {$wpdb->prefix}woocommerce_order_items AS woi ON p.ID = woi.order_id 725 726 WHERE 727 728 p.post_type = 'shop_order' AND 729 730 p.post_status IN ('" . implode("','", array_keys(wc_get_order_statuses())) . "')"; 76 731 77 732 78 733 79 //if ()734 $orders = $wpdb->get_results($query); 80 735 81 736 82 737 83 $account_id = $fermopoint_settings["FERMOPOINT_ACCOUNT_ID"]; 84 85 $account_secret = $fermopoint_settings["FERMOPOINT_ACCOUNT_SECRET"]; 86 87 if (get_option( 'FERMOPOINT_ACCOUNT_ID' )=="") update_option( 'FERMOPOINT_ACCOUNT_ID', $account_id ); 88 738 if (!empty($orders)) { 739 740 $dp = ( isset($filter['dp']) ? intval($filter['dp']) : 2 ); 741 742 //looping throught all the order_id 743 744 foreach ($orders as $key => $order) { 745 746 $order_id = $order->order_id; 747 748 //getting order object 749 750 $objOrder = wc_get_order($order_id); 751 752 $idpoint = get_post_custom_values("idpoint",$order_id); 753 754 $fermopoint_ticketid = get_post_custom_values("fermopoint_ticketid",$order_id); 755 756 757 758 if ($idpoint && ((!$fermopoint_ticketid))){ 759 760 $fermopointorder[$order_id] = $idpoint[0]; 761 762 } 763 764 765 766 if ($idpoint && (($fermopoint_ticketid==""))){ 767 768 $fermopointorder[$order_id] = $idpoint[0]; 769 770 } 771 772 773 774 } 775 776 // echo '<pre>'; 777 778 // print_r($return_array); 779 780 } 781 782 //var_dump($fermopointorder); 89 783 90 91 if (get_option( 'FERMOPOINT_ACCOUNT_SECRET' )=="") update_option( 'FERMOPOINT_ACCOUNT_SECRET', $account_secret );92 93 784 785 if (isset($fermopointorder)){ 786 foreach ($fermopointorder as $order_id=>$idpoint){ 787 788 789 790 791 792 $order = new WC_Order($order_id); 793 794 $email=$order->get_billing_email(); 795 796 $phone_number=$order->get_billing_phone(); 797 798 799 800 $customer = new WC_Customer ($order->user_id); 801 802 803 804 805 806 $account_id = get_option("FERMOPOINT_ACCOUNT_ID"); 807 808 809 810 $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET"); 811 812 813 814 815 816 817 818 $nickname = get_option("FERMOPOINT_ACCOUNT_NICKNAME"); 819 820 821 822 $borndate = get_option("FERMOPOINT_ACCOUNT_BORNDATE"); 823 824 825 826 827 828 829 830 $sandbox =get_option('fermopoint_sandbox'); 831 832 833 834 835 836 837 838 $url = API_SERVER_PRODUCTION . "/booking/book"; 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 $request = json_encode(array( 859 860 861 862 "client_id" => $account_id, 863 864 865 866 "auth_token" =>$auth_token, 867 868 869 870 "ts" => $ts, 871 872 873 874 "data" => array( 875 876 877 878 "point_id" => $idpoint, 879 880 881 882 "merchant_id" =>$order_id, 883 884 885 886 "merchant_notes" => 'Ordine web n.' . $order_id, 887 888 889 890 "existing_user" => true, 891 892 893 894 "nickname" =>trim($nickname), 895 896 897 898 "born_date" =>trim($borndate) . "T00:00:00", 899 900 901 902 "email" => $email, 903 904 905 906 "phone_number" =>$phone_number 907 908 909 910 ) 911 912 913 914 )); 915 916 917 918 919 920 921 922 $httpHeader = array( 923 924 925 926 "Content-Type: application/json; charset=\"utf-8\"", 927 928 929 930 "Accept: text/json" 931 932 933 934 ); 935 936 937 938 939 940 941 942 $ch = curl_init(); 943 944 945 946 $url = API_SERVER_PRODUCTION . "/booking/book"; 947 948 949 950 curl_setopt($ch, CURLOPT_URL, $url ); 951 952 953 954 955 956 957 958 curl_setopt($ch, CURLOPT_POST, 1); 959 960 961 962 curl_setopt($ch, CURLOPT_POSTFIELDS, $request ); 963 964 965 966 967 968 969 970 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 971 972 973 974 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 975 976 977 978 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);rl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 979 980 981 982 curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 $result = curl_exec($ch); 1001 1002 1003 1004 $info = curl_getinfo($ch); 1005 1006 1007 1008 if (!isset($info['http_code'])) { 1009 1010 1011 1012 $info['http_code'] = ''; 1013 1014 1015 1016 } 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 if (curl_errno($ch)) { 1029 1030 1031 1032 $result= array( 1033 1034 1035 1036 'http_code' => $info['http_code'], 1037 1038 1039 1040 'status' => 'ERROR1', 1041 1042 1043 1044 'errno' => $curl_errno, 1045 1046 1047 1048 'error' => $curl_error, 1049 1050 1051 1052 'result' => NULL 1053 1054 1055 1056 ); 1057 1058 1059 1060 } else { 1061 1062 1063 1064 $ret = json_decode($result); 1065 1066 1067 1068 1069 1070 1071 1072 $ticketid = $ret->ticketId; 1073 1074 1075 1076 update_post_meta( $order_id, 'fermopoint_ticketid', $ticketid ); 1077 1078 1079 1080 update_post_meta( $order_id, 'fermopoint_state',"NEW"); 1081 1082 1083 1084 update_post_meta( $order_id, '_shipping_first_name',trim($nickname)); 1085 1086 1087 1088 echo 'Ordine web n.' . $order_id . ") id POINT " . $idpoint . " TICKET GENERATO:" . $ticketid; 1089 1090 $order= callfermopointcurl("/booking/approve/" . $ticketid , "base"); 1091 1092 echo "<br/>"; 1093 1094 1095 1096 } 1097 1098 1099 1100 1101 1102 } 1103 1104 } 1105 1106 $ch3 = curl_init(); 1107 1108 1109 1110 1111 $orders = callfermopointcurl("/orders/last?take=100","base"); 1112 1113 1114 1115 $ret = callfermopointcurl("/merchant","base"); 1116 1117 ?> 94 1118 95 1119 96 1120 97 $nickname = $fermopoint_settings["FERMOPOINT_ACCOUNT_NICKNAME"]; 98 99 $borndate = $fermopoint_settings["FERMOPOINT_ACCOUNT_BORNDATE"]; 100 101 if (get_option( 'FERMOPOINT_ACCOUNT_NICKNAME' )=="") update_option( 'FERMOPOINT_ACCOUNT_NICKNAME', $nickname ); 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 <h2>Crediti restati: <?php echo $ret->credits;?></h2> 1132 1133 1134 1135 <h2>Ordini totali: <?php echo $ret->orders_count;?></h2> 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 <table> 1148 1149 1150 1151 1152 1153 1154 1155 <?php 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 foreach ($orders as $order){ 1166 1167 1168 1169 1170 1171 1172 1173 ?><hr/> 1174 1175 <h3><?php echo $order->ticketId;?></h3> 1176 1177 <table> 1178 1179 1180 1181 <tr> 1182 1183 1184 1185 <td><b><?php echo $order->merchant_id;?></b></td> 1186 1187 <td><?php echo $order->merchant_notes;?></td> 1188 1189 <td><?php echo $order->email;?></td> 1190 1191 <td><?php echo $order->phone_number;?></td> 1192 1193 1194 1195 1196 1197 1198 1199 </tr> 1200 1201 1202 1203 <?php foreach ($order->notes as $note){?> 1204 1205 <tr> 1206 1207 <td><?php echo $note->date;?></td> 1208 1209 <td><?php echo $note->note;?></td> 1210 1211 </tr> 1212 1213 <?php }?> 1214 1215 1216 1217 <?php //$cancellaticket = /booking/cancel/{ticketId} ?> 1218 1219 1220 1221 </table> 1222 1223 <?php 1224 1225 1226 1227 1228 1229 1230 1231 } 1232 1233 1234 1235 1236 1237 1238 1239 ?> 1240 1241 1242 1243 1244 1245 102 1246 103 1247 104 1248 105 if (get_option( 'FERMOPOINT_ACCOUNT_BORNDATE' )=="") update_option( 'FERMOPOINT_ACCOUNT_BORNDATE', $borndate ); 106 107 108 109 } 110 111 /**/ 112 113 114 115 register_setting( 'fermopointoption', 'fermopoint_settings' ); 116 117 118 119 add_settings_section( 120 121 'fermopoint_pluginPage_section', 122 123 __( 'Configura Fermo!Point', 'fermopoint' ), 124 125 'fermopoint_settings_section_callback', 126 127 'pluginPage' 128 129 ); 130 131 132 133 134 135 add_settings_field( 136 137 'fermopoint_sandbox', '', 138 139 'fermopoint_hidden_field_0_render', 140 141 'pluginPage', 142 143 'fermopoint_pluginPage_section' 144 145 ); 146 147 148 149 add_settings_field( 150 151 'FERMOPOINT_ACCOUNT_ID', 152 153 __( 'Client ID', 'fermopoint' ) . ":" . __( 'The user code received at the time of the service', 'fermopoint' ), 154 155 'fermopoint_text_field_2_render', 156 157 'pluginPage', 158 159 'fermopoint_pluginPage_section' 160 161 ); 162 163 164 165 add_settings_field( 166 167 'FERMOPOINT_ACCOUNT_SECRET', 168 169 __( 'Client Secret', 'fermopoint' ) . ":" . __( 'The password received when registering for the service', 'fermopoint' ), 170 171 'fermopoint_text_field_3_render', 172 173 'pluginPage', 174 175 'fermopoint_pluginPage_section' 176 177 ); 178 179 180 181 182 183 add_settings_field( 184 185 'FERMOPOINT_ACCOUNT_NICKNAME', 186 187 __( 'Nickname merchant', 'fermopoint' ), 188 189 'fermopoint_text_field_4_render', 190 191 'pluginPage', 192 193 'fermopoint_pluginPage_section' 194 195 ); 196 197 198 199 200 201 add_settings_field( 202 203 'FERMOPOINT_ACCOUNT_BORNDATE', 204 205 __( 'Date', 'fermopoint' ), 206 207 'fermopoint_text_field_5_render', 208 209 'pluginPage', 210 211 'fermopoint_pluginPage_section' 212 213 ); 214 215 216 217 218 219 220 221 1249 1250 1251 <?php 1252 1253 1254 1255 } 1256 1257 222 1258 223 1259 … … 229 1265 230 1266 231 function fermopoint_hidden_field_0_render( ) { 232 233 234 235 $options = get_option( 'fermopoint_sandbox' ); 236 237 ?> 238 239 <input type='hidden' name='fermopoint_sandbox' value='<?php echo $options; ?>' /> 240 241 <?php 242 243 244 245 } 246 247 248 249 250 251 252 253 function fermopoint_text_field_2_render( ) { 254 255 256 257 $options = get_option( 'FERMOPOINT_ACCOUNT_ID' ); 258 259 ?> 260 261 <input type='text' name='FERMOPOINT_ACCOUNT_ID' value='<?php echo $options; ?>' style='width: 40%' /> 262 263 <?php 264 265 266 267 } 268 269 270 271 272 273 function fermopoint_text_field_3_render( ) { 274 275 276 277 $options = get_option( 'FERMOPOINT_ACCOUNT_SECRET' ); 278 279 ?> 280 281 <input type='text' name='FERMOPOINT_ACCOUNT_SECRET' value='<?php echo $options; ?>' style='width: 40%' /> 282 283 <?php 284 285 286 287 } 288 289 290 291 292 293 function fermopoint_text_field_4_render( ) { 294 295 296 297 $options = get_option( 'FERMOPOINT_ACCOUNT_NICKNAME' ); 298 299 ?> 300 301 <input type='text' name='FERMOPOINT_ACCOUNT_NICKNAME' value='<?php echo $options; ?>' style='width: 40%' /> 302 303 <?php 304 305 306 307 } 308 309 310 311 function fermopoint_text_field_5_render( ) { 312 313 314 315 $options = get_option( 'FERMOPOINT_ACCOUNT_BORNDATE' ); 316 317 ?> 318 319 <input type='text' name='FERMOPOINT_ACCOUNT_BORNDATE' value='<?php echo $options; ?>' style='width: 40%' /> 320 321 <?php 322 323 324 325 } 326 327 328 329 function fermopoint_settings_section_callback( ) { 330 331 332 333 echo "<a href='https://www.fermopoint.it/contatti-ecommerce' target='new'>" . __( 'Iscriviti a Fermo!Point se non lo hai ancora fatto', 'fermopoint' ) . "</a> | <a href='https://www.fermopoint.it/business/vantaggi-ecommerce' target='new'>" . __( 'Scropri i vantaggi', 'fermopoint' ) . "</a>"; 334 335 336 337 } 338 339 340 341 342 343 function fermopoint_mysettings() { // whitelist options 344 345 register_setting( 'pluginPage', 'fermopoint_sandbox' ); 346 347 register_setting( 'pluginPage', 'FERMOPOINT_MODALITAVISIBILE' ); 348 349 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_ID' ); 350 351 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_SECRET' ); 352 353 354 355 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_NICKNAME' ); 356 357 register_setting( 'pluginPage', 'FERMOPOINT_ACCOUNT_BORNDATE' ); 358 359 360 361 } 362 363 364 365 366 367 function fermopoint_options_page( ) { 368 369 370 371 $array = array("nickname"=> get_option("FERMOPOINT_ACCOUNT_NICKNAME"), "born_date"=> get_option("FERMOPOINT_ACCOUNT_BORNDATE"). "T00:00:00"); 372 373 $verify= callfermopointcurl("/public/users/check",$array); 374 375 376 377 378 379 380 381 382 383 echo "<a href='https://www.fermopoint.it/' target='new'><img src='https://www.fermopoint.it/Content/images/logo/logo.png'/></a>"; 384 385 echo "<hr/>"; 386 387 388 389 if (!$verify){?> 390 391 <div class="notice notice-error is-dismissible"> 392 393 <p>FERMO!POINT: Attenzione! L'utente è inesistente, verificare correttamente i dati</p> 394 395 </div> 396 397 398 399 <?php 400 401 402 403 } ?> 404 405 <form action='options.php' method='post'> 406 407 <?php 408 409 settings_fields( 'pluginPage' ); 410 411 do_settings_sections( 'pluginPage' ); 412 413 submit_button(); 414 415 ?> 416 417 </form> 418 419 420 421 <?php 422 423 424 425 426 427 428 429 if ($verify){ 430 431 432 433 echo "<hr/><h2>Riepilogo ticket Fermo!Point</h2>"; 434 435 436 global $wpdb; 437 $return_array = array(); 438 $total_discount = 0; 439 440 $query = "SELECT 441 p.ID AS order_id 442 FROM 443 {$wpdb->prefix}posts AS p 444 INNER JOIN {$wpdb->prefix}woocommerce_order_items AS woi ON p.ID = woi.order_id 445 WHERE 446 p.post_type = 'shop_order' AND 447 p.post_status IN ('" . implode("','", array_keys(wc_get_order_statuses())) . "')"; 448 449 $orders = $wpdb->get_results($query); 450 451 if (!empty($orders)) { 452 $dp = ( isset($filter['dp']) ? intval($filter['dp']) : 2 ); 453 //looping throught all the order_id 454 foreach ($orders as $key => $order) { 455 $order_id = $order->order_id; 456 //getting order object 457 $objOrder = wc_get_order($order_id); 458 $idpoint = get_post_custom_values("idpoint",$order_id); 459 $fermopoint_ticketid = get_post_custom_values("fermopoint_ticketid",$order_id); 460 461 if ($idpoint && ((!$fermopoint_ticketid))){ 462 $fermopointorder[$order_id] = $idpoint[0]; 463 } 464 465 if ($idpoint && (($fermopoint_ticketid==""))){ 466 $fermopointorder[$order_id] = $idpoint[0]; 467 } 468 469 } 470 // echo '<pre>'; 471 // print_r($return_array); 472 } 473 //var_dump($fermopointorder); 474 foreach ($fermopointorder as $order_id=>$idpoint){ 475 476 477 $order = new WC_Order($order_id); 478 $email=$order->get_billing_email(); 479 $phone_number=$order->get_billing_phone(); 480 481 $customer = new WC_Customer ($order->user_id); 482 483 484 $account_id = get_option("FERMOPOINT_ACCOUNT_ID"); 485 486 $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET"); 487 488 489 490 $nickname = get_option("FERMOPOINT_ACCOUNT_NICKNAME"); 491 492 $borndate = get_option("FERMOPOINT_ACCOUNT_BORNDATE"); 493 494 495 496 $sandbox =get_option('fermopoint_sandbox'); 497 498 499 500 $url = API_SERVER_PRODUCTION . "/booking/book"; 501 502 503 504 $ts = gmdate('Y-m-d\TH:i:s.u\Z'); 505 506 507 508 $auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false); 509 510 $request = json_encode(array( 511 512 "client_id" => $account_id, 513 514 "auth_token" =>$auth_token, 515 516 "ts" => $ts, 517 518 "data" => array( 519 520 "point_id" => $idpoint, 521 522 "merchant_id" =>$order_id, 523 524 "merchant_notes" => 'Ordine web n.' . $order_id, 525 526 "existing_user" => true, 527 528 "nickname" =>trim($nickname), 529 530 "born_date" =>trim($borndate) . "T00:00:00", 531 532 "email" => $email, 533 534 "phone_number" =>$phone_number 535 536 ) 537 538 )); 539 540 541 542 $httpHeader = array( 543 544 "Content-Type: application/json; charset=\"utf-8\"", 545 546 "Accept: text/json" 547 548 ); 549 550 551 552 $ch = curl_init(); 553 554 $url = API_SERVER_PRODUCTION . "/booking/book"; 555 556 curl_setopt($ch, CURLOPT_URL, $url ); 557 558 559 560 curl_setopt($ch, CURLOPT_POST, 1); 561 562 curl_setopt($ch, CURLOPT_POSTFIELDS, $request ); 563 564 565 566 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 567 568 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 569 570 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);rl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 571 572 curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); 573 574 575 576 577 578 579 580 581 $result = curl_exec($ch); 582 583 $info = curl_getinfo($ch); 584 585 if (!isset($info['http_code'])) { 586 587 $info['http_code'] = ''; 588 589 } 590 591 592 593 594 595 if (curl_errno($ch)) { 596 597 $result= array( 598 599 'http_code' => $info['http_code'], 600 601 'status' => 'ERROR1', 602 603 'errno' => $curl_errno, 604 605 'error' => $curl_error, 606 607 'result' => NULL 608 609 ); 610 611 } else { 612 613 $ret = json_decode($result); 614 615 616 617 $ticketid = $ret->ticketId; 618 619 update_post_meta( $order_id, 'fermopoint_ticketid', $ticketid ); 620 621 update_post_meta( $order_id, 'fermopoint_state',"NEW"); 622 623 update_post_meta( $order_id, '_shipping_first_name',trim($nickname)); 624 625 echo 'Ordine web n.' . $order_id . ") id POINT " . $idpoint . " TICKET GENERATO:" . $ticketid; 626 $order= callfermopointcurl("/booking/approve/" . $ticketid , "base"); 627 echo "<br/>"; 628 629 } 630 631 632 } 633 634 $ch3 = curl_init(); 635 636 $fermopoint = $shippings["Fermo!Point"]; 637 638 639 640 $orders = callfermopointcurl("/orders/last?take=100","base"); 641 642 $ret = callfermopointcurl("/merchant","base"); 643 ?> 644 645 646 647 648 649 650 <h2>Crediti restati: <?php echo $ret->credits;?></h2> 651 652 <h2>Ordini totali: <?php echo $ret->orders_count;?></h2> 653 654 655 656 657 658 <table> 659 660 661 662 <?php 663 664 665 666 667 foreach ($orders as $order){ 668 669 670 671 ?><hr/> 672 <h3><?php echo $order->ticketId;?></h3> 673 <table> 674 675 <tr> 676 677 <td><b><?php echo $order->merchant_id;?></b></td> 678 <td><?php echo $order->merchant_notes;?></td> 679 <td><?php echo $order->email;?></td> 680 <td><?php echo $order->phone_number;?></td> 681 682 683 684 </tr> 685 686 <?php foreach ($order->notes as $note){?> 687 <tr> 688 <td><?php echo $note->date;?></td> 689 <td><?php echo $note->note;?></td> 690 </tr> 691 <?php }?> 692 693 <?php //$cancellaticket = /booking/cancel/{ticketId} ?> 694 695 </table> 696 <?php 697 698 699 700 } 701 702 703 704 ?> 705 706 707 708 709 710 <?php 711 712 } 713 714 715 716 } 1267 1268 1269 717 1270 718 1271 -
fermopoint-for-woocommerce/trunk/fermopoint-for-woocommerce.php
r1811711 r1895913 43 43 44 44 45 * @since 1.3. 045 * @since 1.3.1 46 46 47 47 -
fermopoint-for-woocommerce/trunk/function.php
r1811711 r1895913 7 7 8 8 9 10 11 12 13 14 15 16 9 17 // Add scripts to wp_head() 10 18 19 20 11 21 /* 12 22 23 24 13 25 add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); 14 26 27 28 15 29 16 30 31 32 17 33 function custom_override_checkout_fields( $fields ) { 18 34 35 36 19 37 $current_shipping_fermopoint = currentmethodshipping(); 20 38 39 40 21 41 if ($current_shipping_fermopoint !== false) { 22 42 43 44 23 45 add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' ); 24 46 47 48 25 49 } 26 50 51 52 27 53 return $fields; 28 54 55 56 29 57 } 30 58 59 60 31 61 */ 32 62 33 63 34 64 65 66 67 68 35 69 add_action( 'woocommerce_before_order_notes', 'fermopoint_maps_cart' ); 36 70 71 72 37 73 function fermopoint_maps_cart( $checkout ) { 38 74 39 75 76 $array = array("nickname"=> get_option("FERMOPOINT_ACCOUNT_NICKNAME"), "born_date"=> get_option("FERMOPOINT_ACCOUNT_BORNDATE"). "T00:00:00"); 77 78 79 80 $verify= callfermopointcurl("/public/users/check",$array); 81 82 83 if ($verify){ 84 40 85 41 86 $current_shipping_fermopoint = currentmethodshipping(); 42 87 88 89 43 90 echo '<div class="fermopointchoise"><h4>' . __('Cerca un punto ritiro Fermo!Point') . '</h4>'; 44 91 92 93 45 94 echo '<div id="fp-map" style="width: 100%; height: 400px; overflow: hidden;"></div>'; 46 95 96 97 47 98 echo '<div id="result"></div>'; 48 99 49 100 101 102 103 104 50 105 51 106 echo woocommerce_form_field( 'idpoint', array( 52 107 108 109 53 110 'type' => 'text', 54 111 112 113 55 114 'class' => array('hidden') 56 115 116 117 57 118 ), $checkout->get_value( 'idpoint' )); 58 119 59 60 61 120 121 122 123 124 125 126 127 128 62 129 63 130 echo '</div>'; … … 65 132 66 133 134 135 136 137 67 138 echo '<script src="//embed.fermopoint.it/embeds/1.0/jquery/search-map.js?clientId=' . get_option( 'FERMOPOINT_ACCOUNT_ID') . '"></script>'; 68 139 140 141 69 142 echo '<script> 70 143 144 145 71 146 jQuery( function( $ ) { 72 147 148 149 73 150 '; 74 151 152 153 75 154 if ($current_shipping_fermopoint !== false) { 76 155 156 157 77 158 echo ' $("#woocommerce-shipping-fields").hide(); 78 159 160 161 79 162 $(".woocommerce-shipping-fields").hide(); 80 163 164 165 81 166 setVisible();'; 82 167 168 169 83 170 84 171 172 173 85 174 } else { 86 175 176 177 87 178 echo ' $("#woocommerce-shipping-fields").show(); 88 179 180 181 89 182 $(".woocommerce-shipping-fields").show(); 90 183 184 185 91 186 $(".fermopointchoise").hide();'; 92 187 188 189 93 190 } 94 191 192 193 95 194 96 195 196 197 97 198 echo ' 98 199 200 201 99 202 100 203 204 205 101 206 102 207 208 209 103 210 function setVisible() { 104 211 212 213 105 214 106 215 216 217 107 218 var $pnlFP = $(".fermopointchoise"); 108 219 220 221 109 222 var $fpmap = $pnlFP.find("#fp-map"); 110 223 224 225 111 226 112 227 228 229 113 230 var $result = $pnlFP.find("#result"); 114 231 232 233 115 234 var $differentAddress = $("#ship-to-different-address-checkbox"); 116 235 236 237 117 238 var $pnlAddress = $(".woocommerce-shipping-fields"); 118 239 240 241 119 242 120 243 244 245 121 246 // reset 122 247 248 249 123 250 $pnlAddress.find("#shipping_first_name").val(""); 124 251 252 253 125 254 $pnlAddress.find("#shipping_last_name").val(""); 126 255 256 257 127 258 $pnlAddress.find("#shipping_company").val(""); 128 259 260 261 129 262 $pnlAddress.find("#shipping_address_1").val(""); 130 263 264 265 131 266 $pnlAddress.find("#shipping_postcode").val(""); 132 267 268 269 133 270 $pnlAddress.find("#shipping_state").val(null); 134 271 272 273 135 274 $pnlAddress.find("#shipping_city").val(""); 136 275 137 276 277 278 279 280 138 281 139 282 var centerAddress = null; 140 283 284 285 141 286 if ($("#billing_address_1").val().length != 0) { 142 287 288 289 143 290 centerAddress = { 144 291 292 293 145 294 s: $("#billing_address_1").val(), 146 295 296 297 147 298 z: $("#billing_postcode").val(), 148 299 300 301 149 302 p: $("#billing_state").val(), 150 303 304 305 151 306 c: $("#billing_city").val() 152 307 308 309 153 310 }; 154 311 312 313 155 314 } 156 315 157 316 317 318 319 320 158 321 159 322 160 323 324 325 161 326 $differentAddress.prop("checked", true); 162 327 328 329 163 330 164 331 165 332 333 334 335 336 166 337 167 338 $result.html(""); 168 339 340 341 169 342 $fpmap.html(""); 170 343 171 344 345 346 347 348 172 349 173 350 $fpmap.fpmap({ 174 351 352 353 175 354 width: "100%", 176 355 356 357 177 358 height: "400px", 178 359 360 361 179 362 centerAddress: centerAddress, 180 363 364 365 181 366 hideButtons: false, 182 367 368 369 183 370 success: function (p) { 184 371 372 373 185 374 console.log(p.id); 186 375 376 377 187 378 $pnlAddress.find("#shipping_first_name").val("Ospite"); 188 379 380 381 189 382 $pnlAddress.find("#shipping_last_name").val(p.n + " - FP"); 190 383 384 385 191 386 $pnlAddress.find("#shipping_company").val(); 192 387 388 389 193 390 $pnlAddress.find("#shipping_address_1").val(p.a.s); 194 391 392 393 195 394 $pnlAddress.find("#shipping_postcode").val(p.a.z); 196 395 396 397 197 398 $pnlAddress.find("#shipping_state").val(p.a.p); 198 399 400 401 199 402 $pnlAddress.find("#shipping_city").val(p.a.c); 200 403 404 405 201 406 202 407 408 409 203 410 jQuery("#idpoint").val(p.id); 204 411 412 413 205 414 415 206 416 $result.html("<b>Fermo!Point Selezionato: </b>" + p.n + "<br/>" + p.a.s + " " + p.a.c + " (" + p.a.c + ") " + p.a.z); 207 417 418 419 208 420 }, 209 421 422 423 210 424 error: function (err) { 211 425 426 427 212 428 alert("ERROR: "+ err); 213 429 430 431 214 432 } 215 433 434 435 216 436 }); 217 437 438 439 218 440 219 441 442 443 220 444 }; 221 445 222 223 224 446 447 448 449 450 451 452 453 454 225 455 226 456 $(document).on("change", "#shipping_method input:radio", function() { 227 457 458 459 228 460 val = $(this).val(); 229 461 462 463 230 464 console.log(val); 231 465 466 467 232 468 if (val.indexOf("Fermo!Point") >= 0) { 233 469 470 471 234 472 $("#woocommerce-shipping-fields").hide(); 235 473 474 475 236 476 $(".woocommerce-shipping-fields").hide(); 237 477 478 479 238 480 $(".fermopointchoise").show(); 239 481 482 483 240 484 setVisible(); 241 485 486 487 242 488 } else { 243 489 490 491 244 492 // reset 245 493 494 495 246 496 var $pnlAddress = $(".woocommerce-shipping-fields"); 247 497 498 499 248 500 $pnlAddress.find("#shipping_first_name").val(""); 249 501 502 503 250 504 $pnlAddress.find("#shipping_last_name").val(""); 251 505 506 507 252 508 $pnlAddress.find("#shipping_company").val(""); 253 509 510 511 254 512 $pnlAddress.find("#shipping_address_1").val(""); 255 513 514 515 256 516 $pnlAddress.find("#shipping_postcode").val(""); 257 517 518 519 258 520 $("#idpoint").val(""); 259 521 522 523 260 524 $pnlAddress.find("#shipping_state").val(null); 261 525 526 527 262 528 $pnlAddress.find("#shipping_city").val(""); 263 529 530 531 264 532 $("#woocommerce-shipping-fields").show(); 265 533 534 535 266 536 $(".woocommerce-shipping-fields").show(); 267 537 538 539 268 540 $(".fermopointchoise").hide(); 269 541 542 543 270 544 } 271 545 546 547 272 548 }); 273 549 550 551 274 552 275 553 554 555 276 556 277 557 558 559 278 560 279 561 562 563 280 564 281 565 566 567 282 568 283 569 570 571 284 572 }); 285 573 574 575 286 576 </script>'; 287 577 578 579 288 580 //$return = fp_curl_call("/points/search"); 289 581 582 583 290 584 //var_dump ($return); 291 585 … … 294 588 295 589 296 590 591 592 593 } else { 594 595 596 echo " <div class='notice notice-error'><h2>Fermo!Point non avviato, impostazioni del negozio non corrette. Scegliere un altro metodo di spedizioni. Ci scusiamo per il disagio.</h2></div>"; 597 598 } 599 600 601 602 603 297 604 298 605 } … … 300 607 301 608 609 610 611 612 302 613 function currentmethodshipping(){ 303 614 615 616 304 617 $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ); 305 618 619 620 306 621 $method_shipping = $chosen_shipping_methods[0]; 307 622 623 624 308 625 return strpos($method_shipping, 'Fermo!Point'); 309 626 627 628 310 629 } 311 630 … … 314 633 315 634 635 636 637 638 639 640 316 641 function callfermopointcurl($url,$array){ 317 642 318 643 644 645 646 647 319 648 320 649 $url = API_SERVER_PRODUCTION . $url; 321 650 651 652 322 653 $account_id = get_option("FERMOPOINT_ACCOUNT_ID"); 323 654 655 656 324 657 $account_secret = get_option("FERMOPOINT_ACCOUNT_SECRET"); 325 658 659 660 326 661 $ts = gmdate('Y-m-d\TH:i:s.u\Z'); 327 662 663 664 328 665 $auth_token = hash_hmac("sha256", (string) $ts, (string) $account_id . $account_secret, false); 329 666 330 331 332 667 668 669 670 671 672 673 674 675 333 676 334 677 if (is_array($array)){ 335 678 679 680 336 681 $request = $array; 337 682 683 684 338 685 } else{ 339 686 687 688 340 689 if ($array=="base"){ 341 690 691 692 342 693 $request = array( 343 694 695 696 344 697 "client_id" => $account_id, 345 698 699 700 346 701 "auth_token" =>$auth_token, 347 702 703 704 348 705 "ts" => $ts, 349 706 707 708 350 709 ); 351 710 711 712 352 713 } else { 353 714 715 716 354 717 $request =""; 355 718 719 720 356 721 } 357 722 723 724 358 725 359 726 727 728 360 729 } 361 730 362 731 732 733 734 735 363 736 364 737 $httpHeader = array( 365 738 739 740 366 741 "Content-Type: application/json; charset=\"utf-8\"", 367 742 743 744 368 745 "Accept: text/json" 369 746 747 748 370 749 ); 371 750 372 751 752 753 754 755 373 756 374 757 $ch = curl_init(); … … 376 759 377 760 761 762 763 764 378 765 curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); 379 766 767 768 380 769 curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); 381 770 771 772 382 773 curl_setopt($ch, CURLOPT_URL, $url ); 383 774 384 775 776 777 778 779 385 780 386 781 if (is_array($request)){ 387 782 783 784 388 785 curl_setopt($ch, CURLOPT_POST, 1); 389 786 787 788 390 789 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request) ); 391 790 791 792 392 793 } 393 794 795 796 394 797 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 395 798 799 800 396 801 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 397 802 803 804 398 805 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 399 806 400 807 401 808 809 810 811 812 402 813 $result = curl_exec($ch); 403 814 815 816 404 817 $info = curl_getinfo($ch); 405 818 819 820 406 821 if (!isset($info['http_code'])) { 407 822 823 824 408 825 $info['http_code'] = ''; 409 826 827 828 410 829 } 411 830 412 831 413 832 833 834 835 836 414 837 if (curl_errno($ch)) { 415 838 839 840 416 841 $result= array( 417 842 843 844 418 845 'http_code' => $info['http_code'], 419 846 847 848 420 849 'status' => 'ERROR1', 421 850 851 852 422 853 'errno' => $curl_errno, 423 854 855 856 424 857 'error' => $curl_error, 425 858 859 860 426 861 'result' => NULL 427 862 863 864 428 865 ); 429 866 867 868 430 869 431 870 871 872 432 873 } else { 433 874 875 876 434 877 $ret = json_decode($result); 435 878 879 880 436 881 } 437 882 438 883 439 884 885 886 887 888 440 889 return $ret; 441 890 891 892 442 893 curl_close($ch); 443 894 895 896 444 897 } 445 898 446 899 447 900 901 902 903 904 448 905 ?>
Note: See TracChangeset
for help on using the changeset viewer.