/** * Creates or updates a single coupon on Stripe. * * This function is called when the gateway is activated and after a * coupon was saved to database. * * @since 1.0.0 */ public function update_stripe_data_coupon($coupon) { if (!$this->active) { return false; } $this->_api->set_gateway($this); $settings = MS_Plugin::instance()->settings; $duration = 'once'; $percent_off = null; $amount_off = null; if (MS_Addon_Coupon_Model::TYPE_VALUE == $coupon->discount_type) { $amount_off = absint($coupon->discount * 100); } else { $percent_off = $coupon->discount; } $coupon_data = array('id' => self::get_the_id($coupon->id, 'coupon'), 'duration' => $duration, 'amount_off' => $amount_off, 'percent_off' => $percent_off, 'currency' => $settings->currency); // Check if the plan needs to be updated. $serialized_data = json_encode($coupon_data); $temp_key = substr('ms-stripe-' . $coupon_data['id'], 0, 45); $temp_data = MS_Factory::get_transient($temp_key); if ($temp_data != $serialized_data) { MS_Factory::set_transient($temp_key, $serialized_data, HOUR_IN_SECONDS); $this->_api->create_or_update_coupon($coupon_data); } }