Skip to content

Commit

Permalink
Merge pull request #1163 from amadolid/minor/stripe-bugfixes
Browse files Browse the repository at this point in the history
[STRIPE]: Align actions to stripe api specs
  • Loading branch information
ypkang authored Jun 29, 2023
2 parents b152d07 + 91ba5b7 commit 0bbfabc
Show file tree
Hide file tree
Showing 8 changed files with 525 additions and 525 deletions.
597 changes: 286 additions & 311 deletions docs/docs/docs/development/std_actions/9_stripe.md

Large diffs are not rendered by default.

293 changes: 151 additions & 142 deletions jaseci_core/jaseci/extens/act_lib/stripe.py

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions jaseci_core/jaseci/extens/api/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def user_create(
global_init: str = "",
global_init_ctx: dict = {},
other_fields: dict = {},
send_email: bool = False,
):
"""
Create a new user (master object)
Expand Down Expand Up @@ -60,7 +61,7 @@ def user_create(
and is_superuser.
"""
ret = {}
mast = self.user_creator(name, password, other_fields)
mast = self.user_creator(name, password, other_fields, send_email)
if type(mast) is dict: # in case of upstream error
return mast
ret["user"] = mast.serialize()
Expand Down Expand Up @@ -102,7 +103,9 @@ def user_deleteself(self):
ret["status_code"] = 400
return ret

def user_creator(self, name, password: str = "", other_fields: dict = {}):
def user_creator(
self, name, password: str = "", other_fields: dict = {}, send_email=True
):
"""
Abstraction for user creation for elegant overriding
"""
Expand Down
18 changes: 13 additions & 5 deletions jaseci_core/jaseci/extens/api/webhook_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,33 @@ def webhook(self, provider: str, _req_ctx: dict = {}, _raw_req_ctx: str = None):
else:
metadata = payload_obj.get("metadata")

master_id = metadata.get("master_id")
master_id = metadata.get("master")
master = self._h.get_obj(master_id, master_id)

node_id = metadata.get("node")
if not node_id:
node_id = master.active_gph_id

node = self._h.get_obj(master_id, node_id)

global_snt_id = self._h.get_glob("GLOB_SENTINEL")
global_snt = self._h.get_obj(master_id, global_snt_id)
sentinel_id = (
metadata.get("sentinel")
or master.active_snt_id
or self._h.get_glob("GLOB_SENTINEL")
)
sentinel = self._h.get_obj(
master_id,
self._h.get_glob("GLOB_SENTINEL")
if sentinel_id == "global"
else sentinel_id,
)

payload = {"event": req_body}
self.seek_committer(master)

wlk = stripe_service.get_walker(req_body["type"])

return master.walker_run(
name=wlk, nd=node, ctx=payload, _req_ctx=_req_ctx, snt=global_snt
name=wlk, nd=node, ctx=payload, _req_ctx=_req_ctx, snt=sentinel
)
else:
raise HTTPException(
Expand Down
78 changes: 43 additions & 35 deletions jaseci_core/jaseci/tests/fixtures/stripe.jac
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
walker create_product {
has name = "product1", description = "new product";
can stripe.create_product;
can stripe.product_create;

stripe.create_product(name, description);
stripe.product_create(name = name, description = description);
}

walker create_product_price {
has productId = "product1", amount = 12, currency = "usd", recurring = {};
can stripe.create_product_price;
can stripe.price_create;

stripe.create_product_price(productId, amount, currency, recurring);
stripe.price_create(productId, amount, currency, recurring = recurring);
}

walker product_list {
has detailed = true;
can stripe.product_list;

stripe.product_list(detailed);
stripe.product_list(active = true);
}

walker create_customer {
has email = "test12@gmail.com", name = "stripe customer", address = {"billing_address": "123 metro manila"};
can stripe.create_customer;
can stripe.customer_create;

stripe.create_customer(email, name, address);
stripe.customer_create(email=email, name=name, address=address);
}

walker get_customer {
has customer_id = "cus_NBsqL1C1GrrHYM";
can stripe.get_customer;
can stripe.customer_retrieve;

stripe.get_customer(customer_id);
stripe.customer_retrieve(customer_id);
}

walker attach_payment_method {
Expand All @@ -42,9 +41,9 @@ walker attach_payment_method {

walker detach_payment_method {
has payment_method_id = "pm_1MN1iN2xToAoV8chTjvX94hm";
can stripe.detach_payment_method;
can stripe.payment_method_detach;

stripe.detach_payment_method(payment_method_id);
stripe.payment_method_detach(payment_method_id);
}

walker get_payment_methods {
Expand All @@ -63,37 +62,37 @@ walker update_default_payment_method {

walker create_invoice {
has customer_id = "cus_NBsqL1C1GrrHYM";
can stripe.create_invoice;
can stripe.invoice_create;

stripe.create_invoice(customer_id);
stripe.invoice_create(customer_id);
}

walker get_invoice_list {
has customer_id = "cus_NBsqL1C1GrrHYM", subscription_id = "sub_1MTgMQCZO78n7fsZqu1dk6nD";
can stripe.get_invoice_list;
can stripe.invoice_list;

stripe.get_invoice_list(customer_id, subscription_id);
stripe.invoice_list(customer = customer_id, subscription = subscription_id);
}

walker get_payment_intents {
has customer_id = "cus_NBsqL1C1GrrHYM";
can stripe.get_payment_intents;
can stripe.payment_intent_list;

stripe.get_payment_intents(customer_id);
stripe.payment_intent_list(customer = customer_id);
}

walker create_payment_intents {
has customer_id = "cus_NBsqL1C1GrrHYM", amount = 12, currency = "usd", payment_method_types = ["card"];
can stripe.create_payment_intents;
can stripe.payment_intent_create;

report stripe.create_payment_intents(customer_id, amount, currency, payment_method_types);
report stripe.payment_intent_create(amount, currency, customer = customer_id, payment_method_types = payment_method_types);
}

walker get_customer_subscription {
has subscription_id = "sub_1MTgMQCZO78n7fsZqu1dk6nD";
can stripe.get_customer_subscription;
has customer_id = "customer_id";
can stripe.subscription_list;

stripe.get_customer_subscription(subscription_id);
stripe.subscription_list(customer = customer_id);
}

walker create_payment_method {
Expand All @@ -105,9 +104,9 @@ walker create_payment_method {
"exp_year": 2024,
"cvc": "314"
};
can stripe.create_payment_method;
can stripe.payment_method_create;

stripe.create_payment_method(card_type, card, billing_details);
stripe.payment_method_create(card_type, card = card, billing_details = billing_details);
}

walker create_trial_subscription {
Expand All @@ -126,16 +125,16 @@ walker create_subscription {

walker cancel_subscription {
has subscription_id = "sub_1MTgMQCZO78n7fsZqu1dk6nD";
can stripe.cancel_subscription;
can stripe.subscription_delete;

stripe.cancel_subscription(subscription_id);
stripe.subscription_delete(subscription_id);
}

walker get_subscription {
has subscription_id = "sub_1MTgMQCZO78n7fsZqu1dk6nD";
can stripe.get_subscription;
can stripe.subscription_retrieve;

stripe.get_subscription(subscription_id);
stripe.subscription_retrieve(subscription_id);
}

walker update_subscription_item {
Expand All @@ -147,21 +146,30 @@ walker update_subscription_item {

walker get_invoice {
has invoice_id = "inv_1MTgMQCZO78n7fsZqu1dk6nD";
can stripe.get_invoice;
can stripe.invoice_retrieve;

stripe.get_invoice(invoice_id);
stripe.invoice_retrieve(invoice_id);
}

walker create_usage_report {
has subscription_id = "sub_1MTgMQCZO78n7fsZqu1dk6nD", quantity = 12;
can stripe.create_usage_report;
can stripe.subscription_item_create_usage_record;

stripe.create_usage_report(subscription_id, quantity);
stripe.subscription_item_create_usage_record(subscription_id, quantity);
}

walker create_checkout_session {
has success_url = "https://example.com/success", cancel_url = "https://example.com/cancel", line_items = [{"price": "price_H5ggYwtDq4fbrJ","quantity": 12}], mode = "payment";
can stripe.create_checkout_session;
can stripe.checkout_session_create;

stripe.checkout_session_create(success_url, mode, line_items = line_items, cancel_url = cancel_url);
}

walker create_billing_portal_session {
can stripe.billing_portal_session_create;

stripe.create_checkout_session(success_url, cancel_url, line_items, mode);
stripe.billing_portal_session_create(
customer="cus_O7ECcoZCZFwinb",
return_url="https://example.com/account"
);
}
52 changes: 24 additions & 28 deletions jaseci_core/jaseci/tests/test_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def setUpClass(cls):
stripe.Invoice.retrieve = Mock()
stripe.SubscriptionItem.create_usage_record = Mock()
stripe.checkout.Session.create = Mock()
stripe.billing_portal.Session.create = Mock()

@classmethod
def tearDownClass(cls):
Expand All @@ -57,7 +58,7 @@ def test_stripe_create_product(self, ret):
@jac_testcase("stripe.jac", "create_product_price")
def test_stripe_create_product_price(self, ret):
stripe.Price.create.assert_called_once_with(
product="product1", unit_amount=12, currency="usd"
product="product1", unit_amount=12, currency="usd", recurring={}
)

@jac_testcase("stripe.jac", "product_list")
Expand All @@ -74,72 +75,63 @@ def test_stripe_create_customer(self, ret):

@jac_testcase("stripe.jac", "get_customer")
def test_stripe_get_customer(self, ret):
stripe.Customer.retrieve.assert_called_once_with(id="cus_NBsqL1C1GrrHYM")
stripe.Customer.retrieve.assert_called_once_with("cus_NBsqL1C1GrrHYM")

@jac_testcase("stripe.jac", "attach_payment_method")
def test_stripe_attach_payment_method(self, ret):
stripe.PaymentMethod.list.assert_called_once_with(
customer="cus_NBsqL1C1GrrHYM", type="card"
)
stripe.PaymentMethod.list.assert_called_once_with(customer="cus_NBsqL1C1GrrHYM")

stripe.PaymentMethod.attach.assert_called_once_with(
payment_method="pm_1MN1iN2xToAoV8chTjvX94hm", customer="cus_NBsqL1C1GrrHYM"
"pm_1MN1iN2xToAoV8chTjvX94hm", customer="cus_NBsqL1C1GrrHYM"
)

@jac_testcase("stripe.jac", "detach_payment_method")
def test_stripe_detach_payment_method(self, ret):
stripe.PaymentMethod.detach.assert_called_once_with(
payment_method="pm_1MN1iN2xToAoV8chTjvX94hm"
"pm_1MN1iN2xToAoV8chTjvX94hm"
)

@jac_testcase("stripe.jac", "get_payment_methods")
def test_stripe_get_payment_methods(self, ret):
stripe.PaymentMethod.list.assert_called_with(
customer="cus_NBsqL1C1GrrHYM", type="card"
)
stripe.PaymentMethod.list.assert_called_with(customer="cus_NBsqL1C1GrrHYM")

@jac_testcase("stripe.jac", "update_default_payment_method")
def test_stripe_update_default_payment_method(self, ret):
stripe.Customer.modify.assert_called_with(
sid="cus_NBsqL1C1GrrHYM",
"cus_NBsqL1C1GrrHYM",
invoice_settings={"default_payment_method": "pm_1MN1iN2xToAoV8chTjvX94hm"},
)

@jac_testcase("stripe.jac", "create_invoice")
def test_stripe_create_invoice(self, ret):
stripe.Customer.modify.assert_called_once_with(
sid="cus_NBsqL1C1GrrHYM",
"cus_NBsqL1C1GrrHYM",
invoice_settings={"default_payment_method": "pm_1MN1iN2xToAoV8chTjvX94hm"},
)

@jac_testcase("stripe.jac", "get_invoice_list")
def test_stripe_get_invoice_list(self, ret):
stripe.Invoice.list.assert_called_once_with(
customer="cus_NBsqL1C1GrrHYM",
limit=10,
subscription="sub_1MTgMQCZO78n7fsZqu1dk6nD",
)

@jac_testcase("stripe.jac", "get_payment_intents")
def test_stripe_get_payment_intents(self, ret):
stripe.PaymentIntent.list.assert_called_once_with(
customer="cus_NBsqL1C1GrrHYM", limit=10
)
stripe.PaymentIntent.list.assert_called_once_with(customer="cus_NBsqL1C1GrrHYM")

@jac_testcase("stripe.jac", "create_payment_intents")
def test_stripe_create_payment_intents(self, ret):
stripe.PaymentIntent.create.assert_called_once_with(
customer="cus_NBsqL1C1GrrHYM",
amount=12,
currency="usd",
customer="cus_NBsqL1C1GrrHYM",
payment_method_types=["card"],
)

@jac_testcase("stripe.jac", "get_customer_subscription")
def test_stripe_get_customer_subscription(self, ret):
stripe.Subscription.list.assert_called_once_with(
customer="sub_1MTgMQCZO78n7fsZqu1dk6nD"
)
stripe.Subscription.list.assert_called_once_with(customer="customer_id")

@jac_testcase("stripe.jac", "create_payment_method")
def test_stripe_create_payment_method(self, ret):
Expand Down Expand Up @@ -172,19 +164,19 @@ def test_stripe_create_subscription(self, ret):
@jac_testcase("stripe.jac", "cancel_subscription")
def test_stripe_cancel_subscription(self, ret):
stripe.Subscription.delete.assert_called_once_with(
sid="sub_1MTgMQCZO78n7fsZqu1dk6nD"
"sub_1MTgMQCZO78n7fsZqu1dk6nD"
)

@jac_testcase("stripe.jac", "get_subscription")
def test_stripe_get_subscription(self, ret):
stripe.Subscription.retrieve.assert_called_once_with(
id="sub_1MTgMQCZO78n7fsZqu1dk6nD"
"sub_1MTgMQCZO78n7fsZqu1dk6nD"
)

@jac_testcase("stripe.jac", "update_subscription_item")
def test_stripe_update_subscription_item(self, ret):
stripe.Subscription.modify.assert_called_once_with(
sid="sub_1MTgMQCZO78n7fsZqu1dk6nD",
"sub_1MTgMQCZO78n7fsZqu1dk6nD",
cancel_at_period_end=False,
items=[
{
Expand All @@ -196,9 +188,7 @@ def test_stripe_update_subscription_item(self, ret):

@jac_testcase("stripe.jac", "get_invoice")
def test_stripe_get_invoice(self, ret):
stripe.Invoice.retrieve.assert_called_once_with(
id="inv_1MTgMQCZO78n7fsZqu1dk6nD"
)
stripe.Invoice.retrieve.assert_called_once_with("inv_1MTgMQCZO78n7fsZqu1dk6nD")

@jac_testcase("stripe.jac", "create_usage_report")
def test_stripe_create_usage_report(self, ret):
Expand All @@ -208,7 +198,13 @@ def test_stripe_create_usage_report(self, ret):
def test_stripe_create_checkout_session(self, ret):
stripe.checkout.Session.create.assert_called_once_with(
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
line_items=[{"price": "price_H5ggYwtDq4fbrJ", "quantity": 12}],
mode="payment",
line_items=[{"price": "price_H5ggYwtDq4fbrJ", "quantity": 12}],
cancel_url="https://example.com/cancel",
)

@jac_testcase("stripe.jac", "create_billing_portal_session")
def test_stripe_create_billing_portal_session(self, ret):
stripe.billing_portal.Session.create.assert_called_once_with(
customer="cus_O7ECcoZCZFwinb", return_url="https://example.com/account"
)
Loading

0 comments on commit 0bbfabc

Please sign in to comment.