|
1 | | -import time |
2 | 1 | import os |
| 2 | +import time |
| 3 | + |
3 | 4 | from dotenv import load_dotenv |
4 | | -from multisafepay.value_object.weight import Weight |
5 | | -from multisafepay.api.shared.cart.cart_item import CartItem |
6 | | -from multisafepay.api.paths.orders.request.components.checkout_options import CheckoutOptions |
7 | | -from multisafepay.api.paths.orders.request.components.payment_options import PaymentOptions |
8 | | -from multisafepay.api.paths.orders.request.components.plugin import Plugin |
9 | | -from multisafepay.api.paths.orders.request.order_request import OrderRequest |
10 | | -from multisafepay.api.shared.cart.shopping_cart import ShoppingCart |
11 | | -from multisafepay.api.shared.customer import Customer |
12 | | -from multisafepay.sdk import Sdk |
13 | | -from multisafepay.value_object.amount import Amount |
14 | | -from multisafepay.value_object.country import Country |
15 | | -from multisafepay.value_object.currency import Currency |
16 | | -from multisafepay.api.shared.description import Description |
17 | | -from multisafepay.value_object.email_address import EmailAddress |
18 | | -from multisafepay.value_object.ip_address import IpAddress |
19 | | -from multisafepay.value_object.phone_number import PhoneNumber |
20 | | -from multisafepay.api.paths.orders.response.order_response import Order |
| 5 | + |
| 6 | +from multisafepay import Sdk |
| 7 | +from multisafepay.api.paths.orders.request import OrderRequest |
| 8 | +from multisafepay.api.paths.orders.request.components import ( |
| 9 | + CheckoutOptions, |
| 10 | + PaymentOptions, |
| 11 | + Plugin, |
| 12 | +) |
| 13 | +from multisafepay.api.paths.orders.response import Order |
| 14 | +from multisafepay.api.shared import Customer, Description |
| 15 | +from multisafepay.api.shared.cart import CartItem, ShoppingCart |
| 16 | +from multisafepay.value_object import ( |
| 17 | + Amount, |
| 18 | + Country, |
| 19 | + Currency, |
| 20 | + EmailAddress, |
| 21 | + IpAddress, |
| 22 | + PhoneNumber, |
| 23 | + Weight, |
| 24 | +) |
21 | 25 |
|
22 | 26 | # Load environment variables from a .env file |
23 | 27 | load_dotenv() |
|
83 | 87 |
|
84 | 88 | # Create cart items |
85 | 89 | cart_items = [ |
86 | | - CartItem() |
87 | | - .add_name('Geometric Candle Holders') |
88 | | - .add_description('Geometric Candle Holders description') |
89 | | - .add_unit_price(90) |
90 | | - .add_quantity(3) |
91 | | - .add_merchant_item_id('1111') |
92 | | - .add_tax_rate_percentage(21) |
93 | | - .add_weight(Weight(value=1.0, unit='kg')), |
94 | | - |
95 | | - CartItem() |
96 | | - .add_name('Nice apple') |
97 | | - .add_description('Nice apple description') |
98 | | - .add_unit_price(35) |
99 | | - .add_quantity(1) |
100 | | - .add_merchant_item_id('666666') |
101 | | - .add_tax_rate_percentage(9) |
102 | | - .add_weight(Weight(value=20, unit='kg')), |
103 | | - |
104 | | - CartItem() |
105 | | - .add_name('Flat Rate - Fixed') |
106 | | - .add_description('Shipping') |
107 | | - .add_unit_price(10) |
108 | | - .add_quantity(1) |
109 | | - .add_merchant_item_id('msp-shipping') |
110 | | - .add_tax_rate_percentage(0) |
111 | | - .add_weight(Weight(value=0, unit='kg')) |
| 90 | + ( |
| 91 | + CartItem() |
| 92 | + .add_name('Geometric Candle Holders') |
| 93 | + .add_description('Geometric Candle Holders description') |
| 94 | + .add_unit_price(90) |
| 95 | + .add_quantity(3) |
| 96 | + .add_merchant_item_id('1111') |
| 97 | + .add_tax_rate_percentage(21) |
| 98 | + .add_weight(Weight(value=1.0, unit='kg')) |
| 99 | + ), |
| 100 | + ( |
| 101 | + CartItem() |
| 102 | + .add_name('Nice apple') |
| 103 | + .add_description('Nice apple description') |
| 104 | + .add_unit_price(35) |
| 105 | + .add_quantity(1) |
| 106 | + .add_merchant_item_id('666666') |
| 107 | + .add_tax_rate_percentage(9) |
| 108 | + .add_weight(Weight(value=20, unit='kg')) |
| 109 | + ), |
| 110 | + ( |
| 111 | + CartItem() |
| 112 | + .add_name('Flat Rate - Fixed') |
| 113 | + .add_description('Shipping') |
| 114 | + .add_unit_price(10) |
| 115 | + .add_quantity(1) |
| 116 | + .add_merchant_item_id('msp-shipping') |
| 117 | + .add_tax_rate_percentage(0) |
| 118 | + .add_weight(Weight(value=0, unit='kg')) |
| 119 | + ), |
112 | 120 | ] |
113 | 121 |
|
114 | 122 | # Create shopping_cart |
115 | 123 | shopping_cart = ShoppingCart().add_items(cart_items) |
116 | 124 |
|
117 | 125 | # Create an OrderRequest object and add the order details |
118 | | - order_request = (OrderRequest() |
119 | | - .add_type('direct') |
120 | | - .add_order_id(order_id) |
121 | | - .add_description(description) |
122 | | - .add_amount(amount) |
123 | | - .add_currency(currency) |
124 | | - .add_gateway('IDEAL') |
125 | | - .add_customer(customer) |
126 | | - .add_delivery(customer) |
127 | | - .add_plugin(plugin) |
128 | | - .add_payment_options(payment_options) |
129 | | - .add_shopping_cart(shopping_cart) |
130 | | - .add_checkout_options(CheckoutOptions.generate_from_shopping_cart(shopping_cart)) |
131 | | - ) |
| 126 | + order_request = ( |
| 127 | + OrderRequest() |
| 128 | + .add_type('direct') |
| 129 | + .add_order_id(order_id) |
| 130 | + .add_description(description) |
| 131 | + .add_amount(amount) |
| 132 | + .add_currency(currency) |
| 133 | + .add_gateway('IDEAL') |
| 134 | + .add_customer(customer) |
| 135 | + .add_delivery(customer) |
| 136 | + .add_plugin(plugin) |
| 137 | + .add_payment_options(payment_options) |
| 138 | + .add_shopping_cart(shopping_cart) |
| 139 | + .add_checkout_options( |
| 140 | + CheckoutOptions.generate_from_shopping_cart(shopping_cart) |
| 141 | + ) |
| 142 | + ) |
132 | 143 |
|
133 | 144 | # Get the order manager from the SDK |
134 | 145 | order_manager = multisafepay_sdk.get_order_manager() |
|
0 commit comments