|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "beyond_api/utils" |
| 4 | + |
| 5 | +module BeyondApi |
| 6 | + class PaymentMethodDefinitions < Base |
| 7 | + include BeyondApi::Utils |
| 8 | + |
| 9 | + # |
| 10 | + # A +POST+ request is used to create a payment method definition on system level. |
| 11 | + # |
| 12 | + # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions' -i -X POST \ |
| 13 | + # -H 'Content-Type: application/json' \ |
| 14 | + # -H 'Accept: application/hal+json' \ |
| 15 | + # -H 'Authorization: Bearer <Access token>' \ |
| 16 | + # -d '{ |
| 17 | + # "name": "credit-card", |
| 18 | + # "referralUriTemplate": "https://example.com/merchants", |
| 19 | + # "statusUriTemplate": "https://example.com/merchants/{shopId}/status", |
| 20 | + # "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect", |
| 21 | + # "createPaymentUriTemplate": "https://example.com/payments", |
| 22 | + # "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture", |
| 23 | + # "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund", |
| 24 | + # "sandbox": "true", |
| 25 | + # "workflow": "PAYMENT_ON_BUY", |
| 26 | + # "captureWorkflow": "CAPTURE_ON_ORDER", |
| 27 | + # "refund": "NO_REFUND", |
| 28 | + # "logos": [{ |
| 29 | + # "setName" : "official", |
| 30 | + # "variant" : "STOREFRONT", |
| 31 | + # "uri" : "https://example.com/static/storefront.png" |
| 32 | + # }], |
| 33 | + # "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.", |
| 34 | + # "en-US" : "Allow your customers to pay by credit card." |
| 35 | + # }, |
| 36 | + # "officialDescription": { |
| 37 | + # "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.", |
| 38 | + # "en-US" : "Allow your customers to pay by credit card." |
| 39 | + # }, |
| 40 | + # "defaultName": { |
| 41 | + # "de-DE" : "Kreditkarte", |
| 42 | + # "en-US" : "Credit card" |
| 43 | + # }, |
| 44 | + # "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}' |
| 45 | + # |
| 46 | + # @beyond_api.scopes +paym:m+ |
| 47 | + # |
| 48 | + # @param body [Hash] the request body |
| 49 | + # |
| 50 | + # @return [OpenStruct] |
| 51 | + # |
| 52 | + # @example |
| 53 | + # @payment_method_definitions = session.payment_method_definitions.create(body) |
| 54 | + # |
| 55 | + def create(body) |
| 56 | + response, status = BeyondApi::Request.post(@session, "/payment-method-definitions", body) |
| 57 | + |
| 58 | + handle_response(response, status) |
| 59 | + end |
| 60 | + |
| 61 | + # |
| 62 | + # A +GET+ request is used to list all payment method definitions on system level. |
| 63 | + # |
| 64 | + # $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions' -i -X GET \ |
| 65 | + # -H 'Accept: application/hal+json' \ |
| 66 | + # -H 'Authorization: Bearer <Access token>' |
| 67 | + # |
| 68 | + # @beyond_api.scopes +paym:m+ |
| 69 | + # |
| 70 | + # @option params [Boolean] :paginated |
| 71 | + # @option params [Integer] :size the page size |
| 72 | + # @option params [Integer] :page the page number |
| 73 | + # |
| 74 | + # @return [OpenStruct] |
| 75 | + # |
| 76 | + # @example |
| 77 | + # @payment_method_definitions = session.payment_method_definitions.all(size: 100, page: 0) |
| 78 | + # |
| 79 | + def all(params = {}) |
| 80 | + handle_all_request("/payment-method-definitions", :payment_method_definitions, params) |
| 81 | + end |
| 82 | + |
| 83 | + # |
| 84 | + # A +GET+ request is used to deactivate a payment method. |
| 85 | + # |
| 86 | + # $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X GET \ |
| 87 | + # -H 'Accept: application/hal+json' \ |
| 88 | + # -H 'Authorization: Bearer <Access token>' |
| 89 | + # |
| 90 | + # @beyond_api.scopes +pymt:u+ |
| 91 | + # |
| 92 | + # @param payment_method_definition_id [String] the payment method definition UUID |
| 93 | + # |
| 94 | + # @return [OpenStruct] |
| 95 | + # |
| 96 | + # @example |
| 97 | + # @payment_method_definition = session.payment_methods.find("credit-card") |
| 98 | + # |
| 99 | + def find(payment_method_definition_id) |
| 100 | + response, status = BeyondApi::Request.get(@session, "/payment-method-definitions/#{payment_method_definition_id}") |
| 101 | + |
| 102 | + handle_response(response, status) |
| 103 | + end |
| 104 | + |
| 105 | + # |
| 106 | + # A +PUT+ request is used to update a payment method definition on system level. |
| 107 | + # |
| 108 | + # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X PUT \ |
| 109 | + # -H 'Content-Type: application/json' \ |
| 110 | + # -H 'Accept: application/hal+json' \ |
| 111 | + # -H 'Authorization: Bearer <Access token>' \ |
| 112 | + # -d '{ |
| 113 | + # "name": "credit-card-updated", |
| 114 | + # "referralUriTemplate": "https://example.com/merchants", |
| 115 | + # "statusUriTemplate": "https://example.com/merchants/{shopId}/status", |
| 116 | + # "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect", |
| 117 | + # "createPaymentUriTemplate": "https://example.com/payments", |
| 118 | + # "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture", |
| 119 | + # "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund", |
| 120 | + # "workflow": "PAYMENT_ON_SELECTION", |
| 121 | + # "captureWorkflow": "CAPTURE_ON_DEMAND", |
| 122 | + # "refund": "NO_REFUND", |
| 123 | + # "logos": [{ |
| 124 | + # "setName" : "official", |
| 125 | + # "variant" : "STOREFRONT", |
| 126 | + # "uri" : "https://example.com/static/storefront.png" |
| 127 | + # }], |
| 128 | + # "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.", |
| 129 | + # "en-US" : "Allow your customers to pay by credit card." |
| 130 | + # }, |
| 131 | + # "officialDescription": { |
| 132 | + # "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.", |
| 133 | + # "en-US" : "Allow your customers to pay by credit card." |
| 134 | + # }, |
| 135 | + # "defaultName": { |
| 136 | + # "de-DE" : "Kreditkarte", |
| 137 | + # "en-US" : "Credit card" |
| 138 | + # }, |
| 139 | + # "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}' |
| 140 | + # |
| 141 | + # @beyond_api.scopes +paym:m+ |
| 142 | + # |
| 143 | + # @param payment_method_definition_id [String] the payment method definition UUID |
| 144 | + # @param body [Hash] the request body |
| 145 | + # |
| 146 | + # @return [OpenStruct] |
| 147 | + # |
| 148 | + # @example |
| 149 | + # @payment_method_definition = session.payment_method_definitions.update("credit_card", body) |
| 150 | + # |
| 151 | + def update(payment_method_definition_id, body) |
| 152 | + response, status = BeyondApi::Request.put(@session, "/payment-method-definitions/#{payment_method_definition_id}") |
| 153 | + |
| 154 | + handle_response(response, status) |
| 155 | + end |
| 156 | + |
| 157 | + # |
| 158 | + # A +DELETE+ request is used to delete a payment method definition on system level. |
| 159 | + # |
| 160 | + # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X DELETE \ |
| 161 | + # -H 'Accept: application/hal+json' \ |
| 162 | + # -H 'Authorization: Bearer <Access token>' |
| 163 | + # |
| 164 | + # @return true |
| 165 | + # |
| 166 | + # @example |
| 167 | + # session.payment_method_definitions.delete("credit-card") |
| 168 | + # |
| 169 | + def delete(payment_method_definition_id) |
| 170 | + response, status = BeyondApi::Request.delete(@session, "/payment-method-definitions/#{payment_method_definition_id}", body) |
| 171 | + |
| 172 | + handle_response(response, status, respond_with_true: true) |
| 173 | + end |
| 174 | + end |
| 175 | +end |
0 commit comments