本文整理汇总了PHP中Stripe\Customer::retrieve方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::retrieve方法的具体用法?PHP Customer::retrieve怎么用?PHP Customer::retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stripe\Customer
的用法示例。
在下文中一共展示了Customer::retrieve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSave
public function testSave()
{
$customer = self::createTestCustomer();
$customer->email = 'gdb@stripe.com';
$customer->save();
$this->assertEqual($customer->email, 'gdb@stripe.com');
$customer2 = Customer::retrieve($customer->id);
$this->assertEqual($customer->email, $customer2->email);
}
示例2: addCard
/**
* @param User $user
* @param $request
* @return boolean
*/
public function addCard(User $user, $request)
{
$stripeToken = $request->request->get('token');
if ($stripeToken) {
$customer = StripeCustomer::retrieve($this->getCustomerId($user));
$card = $customer->sources->create(['source' => $stripeToken]);
return $card instanceof StripeCard;
}
return false;
}
示例3: getCards
public static function getCards($customerId)
{
$customer = \Stripe\Customer::retrieve($customerId);
$cardsCollection = \Stripe\Customer::retrieve($customerId)->sources->all(['object' => 'card']);
$cards = [];
foreach ($cardsCollection['data'] as $card) {
$cards[] = ['cardId' => $card->id, 'last4' => $card->last4, 'expMonth' => $card->exp_month, 'expYear' => $card->exp_year];
}
return $cards;
}
示例4: do_charge
public function do_charge()
{
if (wp_verify_nonce($_POST['wp-simple-pay-pro-nonce'], 'charge_card')) {
global $sc_options;
$query_args = array();
// Set redirect
$redirect = $_POST['sc-redirect'];
$fail_redirect = $_POST['sc-redirect-fail'];
$failed = null;
$message = '';
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$amount = $_POST['sc-amount'];
$description = $_POST['sc-description'];
$store_name = $_POST['sc-name'];
$currency = $_POST['sc-currency'];
$details_placement = $_POST['sc-details-placement'];
$charge = null;
$sub = isset($_POST['sc_sub_id']);
$interval = isset($_POST['sc_sub_interval']) ? $_POST['sc_sub_interval'] : 'month';
$interval_count = isset($_POST['sc_sub_interval_count']) ? $_POST['sc_sub_interval_count'] : 1;
$statement_description = isset($_POST['sc_sub_statement_description']) ? $_POST['sc_sub_statement_description'] : '';
$setup_fee = isset($_POST['sc_sub_setup_fee']) ? $_POST['sc_sub_setup_fee'] : 0;
$coupon = isset($_POST['sc_coup_coupon_code']) ? $_POST['sc_coup_coupon_code'] : '';
$test_mode = isset($_POST['sc_test_mode']) ? $_POST['sc_test_mode'] : 'false';
if ($sub) {
$sub = !empty($_POST['sc_sub_id']) ? $_POST['sc_sub_id'] : 'custom';
}
Stripe_Checkout_Functions::set_key($test_mode);
$meta = array();
if (!empty($setup_fee)) {
$meta['Setup Fee'] = Stripe_Checkout_Misc::to_formatted_amount($setup_fee, $currency);
}
$meta = apply_filters('sc_meta_values', $meta);
try {
if ($sub == 'custom') {
$timestamp = time();
$plan_id = $_POST['stripeEmail'] . '_' . $amount . '_' . $timestamp;
$name = __('Subscription:', 'sc_sub') . ' ' . Stripe_Checkout_Misc::to_formatted_amount($amount, $currency) . ' ' . strtoupper($currency) . '/' . $interval;
// Create a plan
$plan_args = array('amount' => $amount, 'interval' => $interval, 'name' => $name, 'currency' => $currency, 'id' => $plan_id, 'interval_count' => $interval_count);
if (!empty($statement_description)) {
$plan_args['statement_descriptor'] = $statement_description;
}
$new_plan = \Stripe\Plan::create($plan_args);
// Create a customer and charge
$new_customer = \Stripe\Customer::create(array('email' => $_POST['stripeEmail'], 'card' => $token, 'plan' => $plan_id, 'metadata' => $meta, 'account_balance' => $setup_fee));
} else {
// Create new customer
$cust_args = array('email' => $_POST['stripeEmail'], 'card' => $token, 'plan' => $sub, 'metadata' => $meta, 'account_balance' => $setup_fee);
if (!empty($coupon)) {
$cust_args['coupon'] = $coupon;
}
$new_customer = \Stripe\Customer::create($cust_args);
// Set currency based on sub
$plan = \Stripe\Plan::retrieve($sub);
//echo $subscription . '<Br>';
$currency = strtoupper($plan->currency);
}
// We want to add the meta data and description to the actual charge so that users can still view the meta sent with a subscription + custom fields
// the same way that they would normally view it without subscriptions installed.
// We need the steps below to do this
// First we get the latest invoice based on the customer ID
$invoice = \Stripe\Invoice::all(array('customer' => $new_customer->id, 'limit' => 1));
// If this is a trial we need to skip this part since a charge is not made
$trial = $invoice->data[0]->lines->data[0]->plan->trial_period_days;
if (empty($trial) || !empty($setup_fee)) {
// Now that we have the invoice object we can get the charge ID
$inv_charge = $invoice->data[0]->charge;
// Finally, with the charge ID we can update the specific charge and inject our meta data sent from Stripe Custom Fields
$ch = \Stripe\Charge::retrieve($inv_charge);
$charge = $ch;
if (!empty($meta)) {
$ch->metadata = $meta;
}
if (!empty($description)) {
$ch->description = $description;
}
$ch->save();
$query_args = array('charge' => $ch->id, 'store_name' => urlencode($store_name));
$failed = false;
} else {
$sub_id = $invoice->data[0]->subscription;
if (!empty($description)) {
$customer = \Stripe\Customer::retrieve($new_customer->id);
$subscription = $customer->subscriptions->retrieve($sub_id);
$subscription->metadata = array('product' => $description);
$subscription->save();
}
$query_args = array('cust_id' => $new_customer->id, 'sub_id' => $sub_id, 'store_name' => urlencode($store_name));
$failed = false;
}
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
$redirect = $fail_redirect;
$failed = true;
$e = $e->getJsonBody();
$query_args = array('sub' => true, 'error_code' => $e['error']['type'], 'charge_failed' => true);
}
unset($_POST['stripeToken']);
//.........这里部分代码省略.........
示例5: updateSubscriptions
/**
* updateSubscriptions
* --------------------------------------------------
* Updating the StripeSubscriptions.
* @returns The stripe plans.
* @throws StripeNotConnected
* --------------------------------------------------
*/
public function updateSubscriptions()
{
// Connecting to stripe.
// Deleting all subscription to avoid constraints.
$this->updatePlans();
$subscriptions = array();
foreach ($this->getCustomers() as $customer) {
$decodedData = json_decode($this->loadJSON(\Stripe\Customer::retrieve($customer['id'])->subscriptions->all()), TRUE);
foreach ($decodedData['data'] as $subscription) {
$new_subscription = new StripeSubscription(array('subscription_id' => $subscription['id'], 'start' => $subscription['start'], 'status' => $subscription['status'], 'customer' => $subscription['customer'], 'ended_at' => $subscription['ended_at'], 'canceled_at' => $subscription['canceled_at'], 'quantity' => $subscription['quantity'], 'discount' => $subscription['discount'], 'trial_start' => $subscription['trial_start'], 'trial_end' => $subscription['trial_start'], 'discount' => $subscription['discount']));
$plan = StripePlan::where('plan_id', $subscription['plan']['id'])->first();
if ($plan === null) {
// Stripe integrity error, link to a non-existing plan.
return array();
}
$new_subscription->plan()->associate($plan);
array_push($subscriptions, $new_subscription);
}
}
// Save new.
foreach ($subscriptions as $subscription) {
$subscription->save();
}
return $subscriptions;
}
示例6: stripeCustomer
/**
* Attempts to create or retrieve the Stripe Customer for this model.
*
* @return Customer|false
*/
public function stripeCustomer()
{
$app = $this->getApp();
$apiKey = $app['config']->get('stripe.secret');
// attempt to retreive the customer on stripe
try {
if ($custId = $this->stripe_customer) {
return Customer::retrieve($custId, $apiKey);
}
} catch (StripeError $e) {
$app['logger']->debug($e);
$app['errors']->push(['error' => 'stripe_error', 'message' => $e->getMessage()]);
return false;
}
// create the customer on stripe
try {
// This is necessary because save() on stripe objects does
// not accept an API key or save one from the retrieve() request
Stripe::setApiKey($app['config']->get('stripe.secret'));
$customer = Customer::create($this->stripeCustomerData(), $apiKey);
// save the new customer id on the model
$this->stripe_customer = $customer->id;
$this->grantAllPermissions()->save();
$this->enforcePermissions();
return $customer;
} catch (StripeError $e) {
// log any errors not related to invalid cards
if (!$e instanceof StripeCardError) {
$app['logger']->error($e);
}
$app['errors']->push(['error' => 'stripe_error', 'message' => $e->getMessage()]);
}
return false;
}
示例7: run
/**
* Check stripe data.
*
* @access public
* @return void
*/
public function run()
{
$paymentGateway = Payment_gateways::findOneActiveBySlug('stripe');
if ($paymentGateway->exists()) {
\Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey'));
$subscriptions = new Subscription();
$allSubscriptions = $subscriptions->where('status', Subscription::STATUS_ACTIVE)->get();
/* @var Subscription $_subscription */
foreach ($allSubscriptions as $_subscription) {
$end = DateTime::createFromFormat('Y-m-d', $_subscription->end_date);
if ($end->getTimestamp() > strtotime('now')) {
$paymentTransaction = $_subscription->payment_transaction->get();
if ($paymentTransaction->system == 'stripe') {
$user = new User($_subscription->user_id);
try {
$customer = \Stripe\Customer::retrieve($user->stripe_id);
$subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id);
} catch (Exception $e) {
log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
}
if (!isset($subscription) || $subscription->status != 'active') {
$_subscription->deactivate();
$_subscription->save();
}
}
}
}
log_message('CRON_SUCCESS', __FUNCTION__);
}
}
示例8: onPostDispatchCheckout
/**
* @param \Enlight_Controller_ActionEventArgs $args
*/
public function onPostDispatchCheckout($args)
{
$action = $args->getSubject();
$request = $action->Request();
$view = $action->View();
$apiKey = $this->bootstrap->Config()->get('stripeSecretKey');
\Stripe\Stripe::setApiKey($apiKey);
$token = $request->getPost('stripeToken');
if (!empty($token)) {
try {
$this->onStripeToken($request);
} catch (\Stripe\Error\Card $e) {
$eJson = $e->getJsonBody();
$error = $eJson['error'];
$view->assign('sErrorMessages', [$error['message']]);
if ($request->getControllerName() == 'checkout') {
$action->forward('shippingPayment');
} else {
$action->forward('payment');
}
$request->setPost('stripeToken', null);
$action->Response()->clearHeader('Location')->setHttpResponseCode(200);
return;
}
}
if (!empty($view->sPayments) && !empty($view->sUserData['additional']['user']['viisonStripeCustomerId'])) {
$customerId = $view->sUserData['additional']['user']['viisonStripeCustomerId'];
$customer = \Stripe\Customer::retrieve($customerId);
$view->stripeSources = $this->convertCards($customer['sources']['data']);
}
}
示例9: run
/**
* Check stripe data.
*
* @access public
* @return void
*/
public function run()
{
try {
$paymentGateway = Payment_gateways::findOneActiveBySlug('stripe');
if ($paymentGateway->exists()) {
\Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey'));
$subscriptions = new Subscription();
$allSubscriptions = $subscriptions->get();
/* @var Subscription $_subscription */
foreach ($allSubscriptions as $_subscription) {
if ($_subscription->end_date <= strtotime('now')) {
$paymentTransaction = $_subscription->payment_transaction->get();
if ($paymentTransaction->system == 'stripe') {
$user = new User($_subscription->user_id);
$customer = \Stripe\Customer::retrieve($user->stripe_id);
$subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id);
if ($subscription->status == 'active') {
$date = new DateTime();
$date->setTimestamp($subscription->current_period_end);
$_subscription->end_date = $date->format('Y-m-d');
$_subscription->activate();
$_subscription->save();
}
}
}
}
log_message('CRON_SUCCESS', __FUNCTION__);
} else {
log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No Stripe Api key.');
}
} catch (Exception $e) {
log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
}
}
示例10: __construct
function __construct()
{
\Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
$order_items = array();
$user = getLoggedInUser();
$stripe_cust = $user->stripe_cust;
$cart = Cache::get("cart", "session");
if (!$stripe_cust) {
try {
$cu = \Stripe\Customer::create(array("description" => $user->email, "source" => getInput("stripeToken")));
} catch (Exception $e) {
new SystemMessage("There has been an error. Please contact us.");
forward("home");
}
$user->stripe_cust = $cu->id;
$user->save();
} else {
$cu = \Stripe\Customer::retrieve($stripe_cust);
try {
$cu->source = getInput("stripeToken");
} catch (Exception $e) {
new SystemMessage("There has been an error. Please contact us.");
forward("home");
}
$cu->save();
}
foreach ($cart as $guid => $details) {
$product = getEntity($guid);
if ($product->interval == "one_time") {
$order_item = array("type" => "sku", "parent" => $product->stripe_sku, "description" => $product->description . $details);
$order_items[] = $order_item;
} else {
try {
$cu->subscriptions->create(array("plan" => $guid));
} catch (Exception $e) {
new SystemMessage("There has been an error. Please contact us.");
forward("home");
}
}
}
if (!empty($order_items)) {
try {
$order = \Stripe\Order::create(array("items" => $order_items, "currency" => "usd", "customer" => $cu->id));
$order->pay(array("customer" => $cu->id, "email" => $user->email));
} catch (Exception $e) {
new SystemMessage("There has been an error. Please contact us.");
forward("home");
}
}
$invoice = new Invoice();
$invoice->items = $cart;
$invoice->status = "paid";
$invoice->owner_guid = getLoggedInUserGuid();
$invoice->stripe_order = $order->id;
$invoice->save();
Cache::delete("cart", "session");
new SystemMessage("Your purchase is complete.");
forward("billing");
}
示例11: testInvalidObject
public function testInvalidObject()
{
authorizeFromEnv();
try {
Customer::retrieve('invalid');
} catch (InvalidRequestError $e) {
$this->assertEqual(404, $e->getHttpStatus());
}
}
示例12: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($customerID)
{
Stripe::setApiKey($this->stripeConfig['testSecretKey']);
$customerRetrieve = StripeCustomer::retrieve($customerID);
/*echo '<pre>';
print_r($customerRetrieve);
echo '</pre>';*/
return view('customer.show', compact('customerRetrieve'));
}
示例13: deleteCreditCard
public function deleteCreditCard($email, $index)
{
$cstmrAssocId = $this->getAssocCustomerId($email);
$customer = \Stripe\Customer::retrieve($cstmrAssocId);
$list = $this->getCreditCards($email);
$card_id = $list[$index]["id"];
$customer->sources->retrieve($card_id)->delete();
return $this->getCreditCards($email);
}
示例14: cancel_suscription
function cancel_suscription($customer_id, $suscription_id)
{
try {
$customer = \Stripe\Customer::retrieve($customer_id);
$subscription = $customer->subscriptions->retrieve($suscription_id);
$subscription->cancel();
} catch (Exception $e) {
http_response_code(404);
return $e->getJsonBody();
}
}
示例15: __construct
function __construct()
{
gateKeeper();
$user = getLoggedInUser();
$subscription = pageArray(2);
if ($subscription && $user->stripe_cust) {
\Stripe\Stripe::setApiKey(EcommercePlugin::secretKey());
$cu = \Stripe\Customer::retrieve($user->stripe_cust);
$cu->subscriptions->retrieve($subscription)->cancel();
new SystemMessage("Your subscription has been canceled.");
}
forward();
}