|
117 | 117 | expect(subscriptions.data.first.metadata.example).to eq( "yes" )
|
118 | 118 | end
|
119 | 119 |
|
| 120 | + it "adds a new subscription with payment method provided as default" do |
| 121 | + plan |
| 122 | + customer = Stripe::Customer.create(source: gen_card_tk) |
| 123 | + payment_method = Stripe::PaymentMethod.create( |
| 124 | + type: 'card', |
| 125 | + card: { |
| 126 | + number: 4242_4242_4242_4242, |
| 127 | + exp_month: 9, |
| 128 | + exp_year: (Time.now.year + 5), |
| 129 | + cvc: 999 |
| 130 | + } |
| 131 | + ) |
| 132 | + sub = Stripe::Subscription.create( |
| 133 | + plan: 'silver', |
| 134 | + customer: customer, |
| 135 | + metadata: { foo: "bar", example: "yes" }, |
| 136 | + collection_method: 'send_invoice', |
| 137 | + default_payment_method: payment_method.id, |
| 138 | + ) |
| 139 | + |
| 140 | + subscriptions = Stripe::Subscription.list(customer: customer.id) |
| 141 | + expect(subscriptions.count).to eq(1) |
| 142 | + expect(subscriptions.data.first.id).to eq(sub.id) |
| 143 | + expect(subscriptions.data.first.collection_method).to eq('send_invoice') |
| 144 | + expect(subscriptions.data.first.default_payment_method).to eq(payment_method.id) |
| 145 | + end |
| 146 | + |
120 | 147 | it "adds a new subscription to customer (string/symbol agnostic)" do
|
121 | 148 | customer = Stripe::Customer.create(source: gen_card_tk)
|
122 | 149 | subscriptions = Stripe::Subscription.list(customer: customer.id)
|
|
754 | 781 | expect(subscription.pending_invoice_item_interval.interval_count).to eq 3
|
755 | 782 | end
|
756 | 783 |
|
| 784 | + it "updates a subscription's default payment method" do |
| 785 | + plan |
| 786 | + customer = Stripe::Customer.create(source: gen_card_tk) |
| 787 | + payment_method_card = Stripe::PaymentMethod.create( |
| 788 | + type: 'card', |
| 789 | + card: { |
| 790 | + number: 4242_4242_4242_4242, |
| 791 | + exp_month: 9, |
| 792 | + exp_year: (Time.now.year + 5), |
| 793 | + cvc: 999 |
| 794 | + } |
| 795 | + ) |
| 796 | + payment_method_sepa = Stripe::PaymentMethod.create( |
| 797 | + type: 'sepa_debit', |
| 798 | + sepa_debit: {iban: 'DE89370400440532013000'}, |
| 799 | + ) |
| 800 | + subscription = Stripe::Subscription.create( |
| 801 | + plan: 'silver', |
| 802 | + customer: customer, |
| 803 | + metadata: { foo: "bar", example: "yes" }, |
| 804 | + default_payment_method: payment_method_card.id, |
| 805 | + ) |
| 806 | + |
| 807 | + subscriptions = Stripe::Subscription.list(customer: customer) |
| 808 | + expect(subscriptions.data.first.default_payment_method).to eq(payment_method_card.id) |
| 809 | + |
| 810 | + Stripe::Subscription.update( |
| 811 | + subscription.id, |
| 812 | + default_payment_method: payment_method_sepa.id, |
| 813 | + collection_method: 'send_invoice', |
| 814 | + ) |
| 815 | + |
| 816 | + subscriptions = Stripe::Subscription.list(customer: customer) |
| 817 | + expect(subscriptions.data.first.collection_method).to eq('send_invoice') |
| 818 | + expect(subscriptions.data.first.default_payment_method).to eq(payment_method_sepa.id) |
| 819 | + end |
| 820 | + |
757 | 821 | it 'when adds coupon', live: true do
|
758 | 822 | coupon = stripe_helper.create_coupon
|
759 | 823 | customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
|
|
0 commit comments