Changeset 1965004
- Timestamp:
- 10/29/2018 11:18:47 AM (7 years ago)
- Location:
- coinbase-commerce/trunk
- Files:
-
- 3 edited
-
class-wc-gateway-coinbase.php (modified) (6 diffs)
-
coinbase-commerce.php (modified) (3 diffs)
-
includes/class-coinbase-api-handler.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
coinbase-commerce/trunk/class-wc-gateway-coinbase.php
r1949700 r1965004 86 86 */ 87 87 public function get_icon() { 88 if ( $this->get_option( 'show_icons' ) === 'no' ) { 89 return ''; 90 } 91 88 92 $image_path = plugin_dir_path( __FILE__ ) . 'assets/images'; 89 93 $icon_html = ''; … … 169 173 170 174 ), 175 'show_icons' => array( 176 'title' => __( 'Show icons', 'coinbase' ), 177 'type' => 'checkbox', 178 'label' => __( 'Display currency icons on checkout page.', 'coinbase' ), 179 'default' => 'yes', 180 ), 171 181 'debug' => array( 172 182 'title' => __( 'Debug log', 'woocommerce' ), … … 188 198 $order = wc_get_order( $order_id ); 189 199 200 // Create description for charge based on order's products. Ex: 1 x Product1, 2 x Product2 201 try { 202 $order_items = array_map( function( $item ) { 203 return $item['quantity'] . ' x ' . $item['name']; 204 }, $order->get_items() ); 205 206 $description = mb_substr( implode( ', ', $order_items ), 0, 200 ); 207 } catch ( Exception $e ) { 208 $description = null; 209 } 210 190 211 $this->init_api(); 191 212 … … 197 218 $result = Coinbase_API_Handler::create_charge( 198 219 $order->get_total(), get_woocommerce_currency(), $metadata, 199 $this->get_return_url( $order ) 220 $this->get_return_url( $order ), null, $description, 221 $this->get_cancel_url( $order ) 200 222 ); 201 223 … … 213 235 'redirect' => $charge['hosted_url'], 214 236 ); 237 } 238 239 /** 240 * Get the cancel url. 241 * 242 * @param WC_Order $order Order object. 243 * @return string 244 */ 245 public function get_cancel_url( $order ) { 246 $return_url = $order->get_cancel_order_url(); 247 248 if ( is_ssl() || get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' ) { 249 $return_url = str_replace( 'http:', 'https:', $return_url ); 250 } 251 252 return apply_filters( 'woocommerce_get_cancel_url', $return_url, $order ); 215 253 } 216 254 … … 314 352 if ( 'EXPIRED' === $status ) { 315 353 $order->update_status( 'cancelled', __( 'Coinbase payment expired.', 'coinbase' ) ); 354 } elseif ( 'CANCELED' === $status ) { 355 $order->update_status( 'cancelled', __( 'Coinbase payment cancelled.', 'coinbase' ) ); 316 356 } elseif ( 'UNRESOLVED' === $status ) { 317 357 // translators: Coinbase error status for "unresolved" payment. Includes error status. -
coinbase-commerce/trunk/coinbase-commerce.php
r1949700 r1965004 4 4 Plugin URI: https://github.com/coinbase/coinbase-commerce-woocommerce/ 5 5 Description: A payment gateway that allows your customers to pay with cryptocurrency via Coinbase Commerce (https://commerce.coinbase.com/) 6 Version: 1. 0.16 Version: 1.1.0 7 7 Author: Coinbase Commerce 8 8 Author URI: https://commerce.coinbase.com/ … … 39 39 add_filter( 'woocommerce_payment_gateways', 'cb_wc_add_coinbase_class' ); 40 40 add_filter( 'wc_order_statuses', 'cb_wc_add_status' ); 41 add_action( 'woocommerce_admin_order_data_after_order_details', 'cb_order_meta_general' ); 42 add_action( 'woocommerce_order_details_after_order_table', 'cb_order_meta_general' ); 43 add_filter( 'woocommerce_email_order_meta_fields', 'cb_custom_woocommerce_email_order_meta_fields', 10, 3 ); 41 44 } 42 45 } … … 110 113 return $new_statuses_arr; 111 114 } 115 116 117 /** 118 * Add order Coinbase meta after General and before Billing 119 * 120 * @see: https://rudrastyh.com/woocommerce/customize-order-details.html 121 * 122 * @param WC_Order $order WC order instance 123 */ 124 function cb_order_meta_general( $order ){ ?> 125 126 <br class="clear" /> 127 <h3>Coinbase Commerce Data</h3> 128 <div class=""> 129 <p>Coinbase Commerce Reference # <?php echo esc_html( $order->get_meta( '_coinbase_charge_id' ) ); ?></p> 130 </div> 131 132 <?php 133 } 134 135 136 /** 137 * Add Coinbase meta to WC emails 138 * 139 * @see https://docs.woocommerce.com/document/add-a-custom-field-in-an-order-to-the-emails/ 140 * 141 * @param array $fields indexed list of existing additional fields. 142 * @param bool $sent_to_admin If should sent to admin. 143 * @param WC_Order $order WC order instance 144 * 145 */ 146 function cb_custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) { 147 $fields['coinbase_commerce_reference'] = array( 148 'label' => __( 'Coinbase Commerce Reference #' ), 149 'value' => $order->get_meta( '_coinbase_charge_id' ), 150 ); 151 152 return $fields; 153 } -
coinbase-commerce/trunk/includes/class-coinbase-api-handler.php
r1949700 r1965004 35 35 * Get the response from an API request. 36 36 * @param string $endpoint 37 * @param array $ args37 * @param array $params 38 38 * @param string $method 39 39 * @return array 40 40 */ 41 public static function send_request( $endpoint, $args = array(), $method = 'GET' ) { 42 $url = esc_url_raw( add_query_arg( $args, self::$api_url . $endpoint ) ); 41 public static function send_request( $endpoint, $params = array(), $method = 'GET' ) { 43 42 // phpcs:ignore 44 self::log( 'Coinbase Request Args for ' . $endpoint . ': ' . print_r( $ args, true ) );43 self::log( 'Coinbase Request Args for ' . $endpoint . ': ' . print_r( $params, true ) ); 45 44 $args = array( 46 45 'method' => $method, … … 48 47 'X-CC-Api-Key' => self::$api_key, 49 48 'X-CC-Version' => self::$api_version, 50 ), 49 'Content-Type' => 'application/json' 50 ) 51 51 ); 52 52 53 $response = wp_remote_request( $url, $args ); 53 $url = self::$api_url . $endpoint; 54 55 if ( in_array( $method, array( 'POST', 'PUT' ) ) ) { 56 $args['body'] = json_encode( $params ); 57 } else { 58 $url = add_query_arg( $params, $url ); 59 } 60 $response = wp_remote_request( esc_url_raw( $url ), $args ); 54 61 55 62 if ( is_wp_error( $response ) ) { … … 110 117 * @param string $name 111 118 * @param string $desc 119 * @param string $cancel 112 120 * @return array 113 121 */ 114 122 public static function create_charge( $amount = null, $currency = null, $metadata = null, 115 $redirect = null, $name = null, $desc = null ) { 123 $redirect = null, $name = null, $desc = null, 124 $cancel = null ) { 116 125 $args = array( 117 126 'name' => is_null( $name ) ? get_bloginfo( 'name' ) : $name, 118 127 'description' => is_null( $desc ) ? get_bloginfo( 'description' ) : $desc, 119 128 ); 129 $args['name'] = sanitize_text_field( $args['name'] ); 130 $args['description'] = sanitize_text_field( $args['description'] ); 120 131 121 132 if ( is_null( $amount ) ) { 122 133 $args['pricing_type'] = 'no_price'; 123 134 } elseif ( is_null( $currency ) ) { 124 self::log( 'Error: if amount i fgiven, currency must be given (in create_charge()).', 'error' );135 self::log( 'Error: if amount is given, currency must be given (in create_charge()).', 'error' ); 125 136 return array( false, 'Missing currency.' ); 126 137 } else { … … 137 148 if ( ! is_null( $redirect ) ) { 138 149 $args['redirect_url'] = $redirect; 150 } 151 if ( ! is_null( $cancel ) ) { 152 $args['cancel_url'] = $cancel; 139 153 } 140 154
Note: See TracChangeset
for help on using the changeset viewer.